LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   New Bash Script - guidance requested (https://www.linuxquestions.org/questions/linux-software-2/new-bash-script-guidance-requested-4175582526/)

biosboy4 06-17-2016 12:21 PM

New Bash Script - guidance requested
 
Hello,

I need to write a bash script that can automatically pick up .bas files (Visual Basic Log files) and translate them into a spreadsheet. Then of course, dropping them off where they need to go.

Does anyone have any experience with this? I know it is possible to translate them using M$ office but I don't really want to do this with powershell or wine.

Thanks,

michaelk 06-17-2016 02:54 PM

Members may not know anything about a .bas file or its format including me. Can you provide an example.

The easiest the way to translate them into a something any spreadsheet application can read is to convert the files to a CSV (Comma Separated Variable) or tab delimited file.

ondoho 06-19-2016 04:12 AM

Quote:

Originally Posted by biosboy4 (Post 5562581)
I need to write a bash script that can automatically pick up .bas files (Visual Basic Log files) and translate them into a spreadsheet.

they are log files? what sort? and what sort of spreadsheet?
we would need the format of both.
i don't know what "spreadsheet" as a generic term is supposed to mean; maybe the csv previously mentioned is sufficient.

Habitual 06-19-2016 07:33 AM

http://file.org/extension/bas says
"Files that contain the .bas file extension are most commonly associated with program source code that has been written in the BASIC programming language."
Source code generally being text?
No mention of them being log files...

I also think some clarity is needed.
Leave out the references to proprietary software/OSs and the wine software.

How would you describe the problem?

biosboy4 06-20-2016 09:55 AM

Sorry, I got that a little jumbled up.

The Balancer logs balance data to a file called mv6

I rename that file to mv6.csv and open it with excel, then run a decodemodule.bas in a new visual basic window to make the log files readable.

Is this something that can be scripted to work with Libreoffice or Openoffice?

michaelk 06-20-2016 10:23 AM

Maybe, without knowing anything about the VB script I can't say 100% that it could modified to run in Libreoffice or Openoffice. Since the log file appears to be a CSV file already the VB script probably could be rewritten in another language as another option.

biosboy4 06-20-2016 10:26 AM

Here's the module:

Quote:

'
' RH2LogDecodeModule.bas
' Hunter Engineering Company
'
' Date: July 25, 2012
' Author: Erik Hensens
' Description: Implements a Microsoft Excel Visual Basic script that decodes RH2 Balancer log files.
'


' Get the "Lookup Table" multiplier for a given iIndex
' These values are constant and are also used to encode values in the Balancer code
Public Function dGetLookupTableMultiplier(iIndex As Integer) As Double

If (iIndex = 10) Then
dGetLookupTableMultiplier = 73.3841
ElseIf (iIndex = 11) Then
dGetLookupTableMultiplier = 32.7513
ElseIf (iIndex = 12) Then
dGetLookupTableMultiplier = 83.2346
ElseIf (iIndex = 13) Then
dGetLookupTableMultiplier = 41.1273
ElseIf (iIndex = 14) Then
dGetLookupTableMultiplier = 64.7793
ElseIf (iIndex = 15) Then
dGetLookupTableMultiplier = 37.6312
ElseIf (iIndex = 16) Then
dGetLookupTableMultiplier = 93.0908
ElseIf (iIndex = 17) Then
dGetLookupTableMultiplier = 10.8811
ElseIf (iIndex = 18) Then
dGetLookupTableMultiplier = 44.2431
ElseIf (iIndex = 19) Then
dGetLookupTableMultiplier = 37.1286
ElseIf (iIndex = 20) Then
dGetLookupTableMultiplier = 37.6321
ElseIf (iIndex = 21) Then
dGetLookupTableMultiplier = 24.8933
ElseIf (iIndex = 22) Then
dGetLookupTableMultiplier = 39.793
ElseIf (iIndex = 23) Then
dGetLookupTableMultiplier = 42.7322
ElseIf (iIndex = 24) Then
dGetLookupTableMultiplier = 22.1792
ElseIf (iIndex = 25) Then
dGetLookupTableMultiplier = 67.1183
ElseIf (iIndex = 26) Then
dGetLookupTableMultiplier = 72.5404
ElseIf (iIndex = 27) Then
dGetLookupTableMultiplier = 11.6233
ElseIf (iIndex = 28) Then
dGetLookupTableMultiplier = 45.1371
ElseIf (iIndex = 29) Then
dGetLookupTableMultiplier = 69.5235
ElseIf (iIndex = 30) Then
dGetLookupTableMultiplier = 18.4632
ElseIf (iIndex = 31) Then
dGetLookupTableMultiplier = 42.5232
ElseIf (iIndex = 32) Then
dGetLookupTableMultiplier = 93.3048
ElseIf (iIndex = 33) Then
dGetLookupTableMultiplier = 70.0908
ElseIf (iIndex = 34) Then
dGetLookupTableMultiplier = 35.1504
ElseIf (iIndex = 35) Then
dGetLookupTableMultiplier = 81.4528
ElseIf (iIndex = 36) Then
dGetLookupTableMultiplier = 79.3581
ElseIf (iIndex = 37) Then
dGetLookupTableMultiplier = 50.4509
ElseIf (iIndex = 38) Then
dGetLookupTableMultiplier = 70.089
ElseIf (iIndex = 39) Then
dGetLookupTableMultiplier = 88.6324
ElseIf (iIndex = 40) Then
dGetLookupTableMultiplier = 82.8465
ElseIf (iIndex = 41) Then
dGetLookupTableMultiplier = 25.3234
ElseIf (iIndex = 42) Then
dGetLookupTableMultiplier = 19.4906
ElseIf (iIndex = 43) Then
dGetLookupTableMultiplier = 14.9922
ElseIf (iIndex = 44) Then
dGetLookupTableMultiplier = 22.5104
ElseIf (iIndex = 45) Then
dGetLookupTableMultiplier = 87.2123
ElseIf (iIndex = 46) Then
dGetLookupTableMultiplier = 89.0909
ElseIf (iIndex = 47) Then
dGetLookupTableMultiplier = 58.3422
ElseIf (iIndex = 48) Then
dGetLookupTableMultiplier = 76.343
ElseIf (iIndex = 49) Then
dGetLookupTableMultiplier = 78.1058
ElseIf (iIndex = 50) Then
dGetLookupTableMultiplier = 64.3242
ElseIf (iIndex = 51) Then
dGetLookupTableMultiplier = 53.1935
ElseIf (iIndex = 52) Then
dGetLookupTableMultiplier = 91.1288
ElseIf (iIndex = 53) Then
dGetLookupTableMultiplier = 53.2123
ElseIf (iIndex = 54) Then
dGetLookupTableMultiplier = 79.2525
ElseIf (iIndex = 55) Then
dGetLookupTableMultiplier = 52.3583
ElseIf (iIndex = 56) Then
dGetLookupTableMultiplier = 61.973
ElseIf (iIndex = 57) Then
dGetLookupTableMultiplier = 38.1104
ElseIf (iIndex = 58) Then
dGetLookupTableMultiplier = 75.2178
ElseIf (iIndex = 59) Then
dGetLookupTableMultiplier = 68.1285
ElseIf (iIndex = 60) Then
dGetLookupTableMultiplier = 69.4567
ElseIf (iIndex = 61) Then
dGetLookupTableMultiplier = 26.7385
ElseIf (iIndex = 62) Then
dGetLookupTableMultiplier = 11.9872
ElseIf (iIndex = 63) Then
dGetLookupTableMultiplier = 54.0824
ElseIf (iIndex = 64) Then
dGetLookupTableMultiplier = 31.3534
ElseIf (iIndex = 65) Then
dGetLookupTableMultiplier = 51.7813
ElseIf (iIndex = 66) Then
dGetLookupTableMultiplier = 17.8821
ElseIf (iIndex = 67) Then
dGetLookupTableMultiplier = 89.3412
ElseIf (iIndex = 68) Then
dGetLookupTableMultiplier = 91.1731
ElseIf (iIndex = 69) Then
dGetLookupTableMultiplier = 13.197
ElseIf (iIndex = 70) Then
dGetLookupTableMultiplier = 83.6453
ElseIf (iIndex = 71) Then
dGetLookupTableMultiplier = 62.919
ElseIf (iIndex = 72) Then
dGetLookupTableMultiplier = 21.9327
ElseIf (iIndex = 73) Then
dGetLookupTableMultiplier = 44.1937
ElseIf (iIndex = 74) Then
dGetLookupTableMultiplier = 82.783
ElseIf (iIndex = 75) Then
dGetLookupTableMultiplier = 99.1105
ElseIf (iIndex = 76) Then
dGetLookupTableMultiplier = 65.3451
ElseIf (iIndex = 77) Then
dGetLookupTableMultiplier = 99.873
ElseIf (iIndex = 78) Then
dGetLookupTableMultiplier = 81.8615
ElseIf (iIndex = 79) Then
dGetLookupTableMultiplier = 19.9912
ElseIf (iIndex = 80) Then
dGetLookupTableMultiplier = 11.7319
ElseIf (iIndex = 81) Then
dGetLookupTableMultiplier = 27.7633
ElseIf (iIndex = 82) Then
dGetLookupTableMultiplier = 40.243
ElseIf (iIndex = 83) Then
dGetLookupTableMultiplier = 70.1986
ElseIf (iIndex = 84) Then
dGetLookupTableMultiplier = 63.9983
ElseIf (iIndex = 85) Then
dGetLookupTableMultiplier = 92.9831
ElseIf (iIndex = 86) Then
dGetLookupTableMultiplier = 50.6372
ElseIf (iIndex = 87) Then
dGetLookupTableMultiplier = 62.809
ElseIf (iIndex = 88) Then
dGetLookupTableMultiplier = 31.515
ElseIf (iIndex = 89) Then
dGetLookupTableMultiplier = 28.8171
ElseIf (iIndex = 90) Then
dGetLookupTableMultiplier = 22.6627
ElseIf (iIndex = 91) Then
dGetLookupTableMultiplier = 72.0876
ElseIf (iIndex = 92) Then
dGetLookupTableMultiplier = 84.9943
ElseIf (iIndex = 93) Then
dGetLookupTableMultiplier = 43.2086
ElseIf (iIndex = 94) Then
dGetLookupTableMultiplier = 69.8423
ElseIf (iIndex = 95) Then
dGetLookupTableMultiplier = 98.7742
ElseIf (iIndex = 96) Then
dGetLookupTableMultiplier = 80.8234
ElseIf (iIndex = 97) Then
dGetLookupTableMultiplier = 92.6302
ElseIf (iIndex = 98) Then
dGetLookupTableMultiplier = 62.538
ElseIf (iIndex = 99) Then
dGetLookupTableMultiplier = 14.3301
Else
dGetLookupTableMultiplier = 0
End If

End Function


' The routine that goes through the worksheet and decodes the numeric cells
Sub RH2LogDecodeRoutine()

' Text variables
Dim szThisCellString As String
Dim sziLookupTableIndexString As String
Dim szValueString As String
Dim szFileName As String

' Boolean variables
Dim bThisCellPositive As Boolean

' Numeric variables
Dim iLookupTableIndex As Integer
Dim dEncodedValue As Double
Dim dLookupMultiplier As Double
Dim dDecodedValue As Double
Dim iFirstColumnToDecode As Integer

' Set the file name
szFileName = ActiveWorkbook.Name

' If this is the measurements file
If Mid(szFileName, 1, 1) = "m" Then

' Start at the third column
iFirstColumnToDecode = 3

' Or, if this is the calibration file
ElseIf Mid(szFileName, 1, 1) = "c" Then

' Start at the third column
iFirstColumnToDecode = 3

' Or, if this is the eCal autospin file
ElseIf Mid(szFileName, 1, 1) = "e" Then

' Start at the third column
iFirstColumnToDecode = 3

' Or, if we don't recognize the file
Else

' Start at the first column
iFirstColumnToDecode = 1

End If


' For every used cell in the active worksheet
For Each Cell In ActiveSheet.UsedRange.Cells

' If this is a column we want to decode
If Cell.Column > (iFirstColumnToDecode - 1) Then

' Get the text in this cell
szThisCellString = Cell.Text

' If the first character is a dash
If Mid(szThisCellString, 1, 1) = "-" Then

' This cell is negative
bThisCellPositive = False

' Or, if the first character is not a dash
Else

' This cell is positive
bThisCellPositive = True

End If

' If the value in this cell is negative
If bThisCellPositive = False Then

' The iIndex into the lookup table is the second two characters in the cell
sziLookupTableIndexString = Mid(szThisCellString, 2, 2)

' The value is everything else in the cell besides the iIndex into the lookup table
szValueString = Mid(szThisCellString, 4, Len(szThisCellString) - 3)

' Or, if the value in this cell is positive
Else

' The iIndex into the lookup table is the first two characters
sziLookupTableIndexString = Mid(szThisCellString, 1, 2)

' The value is everything else in the cell besides the iIndex into the lookup table
szValueString = Mid(szThisCellString, 3, Len(szThisCellString) - 2)

End If

' Get the lookup table iIndex as an integer
iLookupTableIndex = CInt(sziLookupTableIndexString)

' Get the lookup multiplier for this lookup table iIndex
dLookupMultiplier = dGetLookupTableMultiplier(iLookupTableIndex)

' Get the value to decode as a double
dEncodedValue = Val(szValueString)

' If the lookup multiplier is zero
If dLookupMultiplier = 0 Then

' This is an error, set the decoded value to zero
dDecodedValue = 0

' Or, if the lookup multiplier is non-zero
Else

' Get the decoded value
dDecodedValue = dEncodedValue / dLookupMultiplier

End If

' If this cell is negative
If bThisCellPositive = False Then

' Make the decoded value negative
dDecodedValue = dDecodedValue * -1

End If

' At this point, we have the decoded value, dDecodedValue
' Next, just replace the cell with this decoded value
Cell.Value = dDecodedValue

End If

Next

End Sub

michaelk 06-20-2016 11:12 AM

Not a Libreoffice basic expert by any means but a first glance I don't see anything that can not be converted.


All times are GMT -5. The time now is 08:56 AM.