Originally Posted by
TOWERSIGNALS
Right now I have to re-structure that table into 2 columns in a text file format to get the Access program to work.
You could have file picker code to select the input text file and select the folder to put the target file.
I made a test text file from the data in Post #1 and created this code to change from 6 columns to 2 columns with the call sign at the beginning of each group of readings.
Obviously, I named the button "cmdParse"
Code:
Private Sub cmdParse_Click()
Dim strIN As String
Dim strOut As String
Dim ArrDeg(359) As String
Dim sPart1 As String
Dim sPart2 As String
Dim sPart3 As String
Dim sStation As String
Dim RF As Integer
Dim WF As Integer
Dim i As Integer
Dim Arr1 As Integer
Dim Arr2 As Integer
Dim Arr3 As Integer
Dim Pos1 As Integer
Dim Pos2 As Integer
Dim Pos3 As Integer
Dim OK2Print As Boolean
'MUST have a source file AND a Target file.
If Len(Trim(Me.txtSource & "")) = 0 Or Len(Trim(Me.txtTarget & "")) = 0 Then
MsgBox "Missing Source or Target text files!!" & vbCrLf & "Please fix"
Exit Sub
End If
'------------------------------------------------------------------------------------------'
' Should also check to ensure they are also TEXT files (.txt)
'------------------------------------------------------------------------------------------'
' Open source file
RF = FreeFile
Open Me.txtSource For Input As #RF
' Open target file
WF = FreeFile
Open Me.txtTarget For Output As #WF
'While not end of Source file
Do While Not EOF(RF)
'read line
Line Input #RF, strIN
' Parse line
If Left(strIN, 7) = "Station" Then
'only print if read lines after a call sign
If OK2Print Then
Print #WF, sStation
'print the parsed values
For i = 0 To UBound(ArrDeg)
Print #WF, ArrDeg(i)
Next
ArrayFilled = False ' set print flag
Erase ArrDeg 'clear affay
End If
sStation = strIN
Else
OK2Print = True
'get the position of the "m"s
Pos1 = InStr(strIN, "m") + 1
Pos2 = InStr(Pos1, strIN, "m") + 1
Pos3 = InStr(Pos2, strIN, "m")
'get the string to print to file
sPart1 = Trim(Left(strIN, Pos1))
sPart2 = Trim(Mid(strIN, Pos1 + 1, Pos2 - Pos1))
sPart3 = Trim(Mid(strIN, Pos2 + 1, Pos3 - Pos2))
'get the degree order the reading should be at in the array
Arr1 = Val(Left(sPart1, InStr(sPart1, Chr(176))))
Arr2 = Val(Left(sPart2, InStr(sPart2, Chr(176))))
Arr3 = Val(Left(sPart3, InStr(sPart3, Chr(176))))
'replact the degree symbol and add to array
ArrDeg(Arr1) = Trim(Replace(sPart1, Chr(176), ""))
ArrDeg(Arr2) = Trim(Replace(sPart2, Chr(176), ""))
ArrDeg(Arr3) = Trim(Replace(sPart3, Chr(176), ""))
End If
Loop
' at end of input file so print the last station and readings.
If EOF(RF) Then
If OK2Print Then
Print #WF, sStation
For i = 0 To UBound(ArrDeg)
If Len(ArrDeg(i)) > 0 Then
Print #WF, ArrDeg(i)
End If
Next
End If
End If
'closr the output and input files
Close #2
Close #1
MsgBox ("Done")
End Sub
Originally Posted by
TOWERSIGNALS
At this stage I can do one station at a time but my goal is to have Access process a group of 40 or 50 stations at once. More later on and thanks again. Towersignals
Not sure what you mean by this. Do you have multiple text files or multiple stations in one (each) text file?