This might help too:ArrayThe Array keyword is used to initialize arrays and structures with the specified data.It supports arrays of one and two dimensions and array structures of one dimension.Arrays and structures should first be declared in Sub Globals.However the size of the array can be set to 0 as the Array keyword will reinitialize the array.Syntax: Array (Array Elements)
StrSplitSplits a string and returns an array of strings.
Syntax: SrtSplit (RawString, Separators)
RawString - The string that will be split.
Separators - Zero or more characters that act as the separators.
If the Separators string is an empty string then all white characters will be used as the separators.
Example:
Sub Globals
dim words(0) as string
End Sub
Sub App_Start
sentence = "$GPGGA,161229.487,3723.2475,N,12158.3416,W,1,07,1.0,9.0,M,,,,0000*18"
words() = StrSplit(sentence, ",")
for i = 0 to ArrayLen(words())-1
msgbox(words(i))
next
End Sub
Sub Globals
Dim Texto(0) as String
End Sub
Sub App_Start
ReadINI
Main.Show
MsgBox(Texto(3))'should show the 3rd line read from the file(?)
End Sub
Sub ReadNI
FileOpen(c1,AppPath & "\MyFile.txt",cRead")
a = FileRead(c!)
Do Until a = EOF
Texto() = a'Shouldn't this increment the array?
a = FileRead(c1)
Loop
FileClose(c1)
End Sub
Sub Globals
'Declare the global variables here.
Dim txt(0) As string
End Sub
Sub App_Start
readINI
Msgbox(txt(0))
End Sub
Sub READINI
FileOpen(c1,AppPath&"\MyFile.txt",cRead)
a = FileReadToEnd(c1)
txt()=StrSplit(a,crlf)
FileClose(c1)
End Sub
That seems to be a "feature", presumably CR & LF are being read as separate chars in the matching. Doubtless Erel will point something out for us in a minute...LineCutter, your solution does provide all the read lines, but it also adds an empty "line" at every split, so I end up with an array with twice as much items than there really are...
That ought to work, although it offends my sense of economy.Maybe I'll read one line at a time, but concatenate them into a single string and use the srtsplit method....
What do you think?
Sub Globals
'Declare the global variables here.
Dim txt(0) As string
End Sub
Sub App_Start
readINI
For i = 0 To ArrayLen(txt())-1 [B]Step 2[/B]
ListBox1.Add(txt(i))
Next
Form1.Show
End Sub
Sub READINI
FileOpen(c1,AppPath&"\MyFile.txt",cRead)
a = FileReadToEnd(c1)
txt()=StrSplit(a,crlf)
FileClose(c1)
End Sub
I knew I was missing something obvious (I usually do). Thanks Erel.StrSplit uses single characters to split the string.
Sub App_Start
readINI
For i = 0 To ArrayLen(txt())-1
ListBox1.Add(txt(i))
Next
Form1.Show
End Sub
Sub READINI
FileOpen(c1,AppPath&"\MyFile.txt",cRead)
a = FileReadToEnd(c1)
a = StrReplace(a,crlf,Chr(10))
txt() = StrSplit(a,Chr(10))
FileClose(c1)
End Sub
Sub GetValue(ParamName)
Dim arrCount , sLine , sVal , i
sVal = ""
arrCount = ArrayLen(txt())
If arrCount > 0 Then
For i = 0 To arrCount-1
sLine = txt(i)
sline = StrReplace(sline," ", "") 'remove spaces
If sLine <> "" Then
pos = StrIndexOf(sline,ParamName & "=",0)
If pos <> -1 Then
'remove parameter name and the = sign
sline = StrReplace(sline,ParamName & "=", "")
sVal = sline
End If
End If
Next
End If
Return sVal
End Sub