gungadout
14-10-2010, 05:45
Hi Folks,
It looks as though ParseSet$ only places a new value into a string if the index being referenced already exists.
In other languages I have used in the past, the ParseSet$ equivalent automatically extends an existing string if required, appending as many delimiters as are needed to place the delimited field in the required position.
Often, the number of possible delimited fields is not known in advance, and the fields are not necessarily populated in sequential order. E.g. Index position 3 may be the first delimited field to be placed, followed by index position 10, then index position 6. Not all delimited field positions may necessarily be filled.
This was my testing to identify why my large program was failing:
' Empty GUI script created on 10-14-2010 13:45:36 by (ThinAIR)
Dim TestArray(10) As String = ""
Dim Comma As String = ","
Dim TestString As String
Dim Subscript As Long
Dim FieldNo As Long
Subscript = 1
FieldNo = 2
' TestArray(Subscript) = ParseSet$(TestArray(Subscript), Comma, FieldNo, Format$(FieldNo))
TestArray(Subscript) = ParseSet$(TestArray(Subscript), Comma, FieldNo, "2")
FieldNo = 4
' TestArray(Subscript) = ParseSet$(TestArray(Subscript), Comma, FieldNo, Format$(FieldNo))
TestArray(Subscript) = ParseSet$(TestArray(Subscript), Comma, FieldNo, "4")
FieldNo = 6
' TestArray(Subscript) = ParseSet$(TestArray(Subscript), Comma, FieldNo, Format$(FieldNo))
TestArray(Subscript) = ParseSet$(TestArray(Subscript), Comma, FieldNo, "6")
MsgBox(0,"Final Testarray Pass 1 = " + TestArray(1))
FieldNo = 2
TestString = TestArray(Subscript)
' TestString = ParseSet$(TestString, Comma, FieldNo, Format$(FieldNo))
TestString = ParseSet$(TestString, Comma, FieldNo, "2")
MsgBox(0, "TestString - FieldNo = 2 = " + TestString)
TestArray(Subscript) = TestString
FieldNo = 4
TestString = TestArray(Subscript)
MsgBox(0, "TestString - FieldNo = 4 = " + TestString)
' TestString = ParseSet$(TestString, Comma, FieldNo, Format$(FieldNo))
TestString = ParseSet$(TestString, Comma, FieldNo, "4")
TestArray(Subscript) = TestString
FieldNo = 6
TestString = TestArray(Subscript)
If TestString = "" Then
TestString = ",,,,,,,,,,"
End If
MsgBox(0, "TestString - FieldNo = 6 = " + TestString)
' TestString = ParseSet$(TestString, Comma, FieldNo, Format$(FieldNo))
TestString = ParseSet$(TestString, Comma, FieldNo, "6")
TestArray(Subscript) = TestString
MsgBox(0,"Final Testarray Pass 2 = " + TestArray(1))
The automatic extension of delimited strings is a very handy facility to have.
Is it possible to have ParseSet$'s functionality extended to include that, or should I just make a function of my own?
(If I make a function of my own, I foresee some degradation in performance compared to a native thinBasic implementation. I will be using this technique a lot to handle multiple levels of screen, with different numbers and types of controls in each.)
Regards,
Peter H. (gungadout)
It looks as though ParseSet$ only places a new value into a string if the index being referenced already exists.
In other languages I have used in the past, the ParseSet$ equivalent automatically extends an existing string if required, appending as many delimiters as are needed to place the delimited field in the required position.
Often, the number of possible delimited fields is not known in advance, and the fields are not necessarily populated in sequential order. E.g. Index position 3 may be the first delimited field to be placed, followed by index position 10, then index position 6. Not all delimited field positions may necessarily be filled.
This was my testing to identify why my large program was failing:
' Empty GUI script created on 10-14-2010 13:45:36 by (ThinAIR)
Dim TestArray(10) As String = ""
Dim Comma As String = ","
Dim TestString As String
Dim Subscript As Long
Dim FieldNo As Long
Subscript = 1
FieldNo = 2
' TestArray(Subscript) = ParseSet$(TestArray(Subscript), Comma, FieldNo, Format$(FieldNo))
TestArray(Subscript) = ParseSet$(TestArray(Subscript), Comma, FieldNo, "2")
FieldNo = 4
' TestArray(Subscript) = ParseSet$(TestArray(Subscript), Comma, FieldNo, Format$(FieldNo))
TestArray(Subscript) = ParseSet$(TestArray(Subscript), Comma, FieldNo, "4")
FieldNo = 6
' TestArray(Subscript) = ParseSet$(TestArray(Subscript), Comma, FieldNo, Format$(FieldNo))
TestArray(Subscript) = ParseSet$(TestArray(Subscript), Comma, FieldNo, "6")
MsgBox(0,"Final Testarray Pass 1 = " + TestArray(1))
FieldNo = 2
TestString = TestArray(Subscript)
' TestString = ParseSet$(TestString, Comma, FieldNo, Format$(FieldNo))
TestString = ParseSet$(TestString, Comma, FieldNo, "2")
MsgBox(0, "TestString - FieldNo = 2 = " + TestString)
TestArray(Subscript) = TestString
FieldNo = 4
TestString = TestArray(Subscript)
MsgBox(0, "TestString - FieldNo = 4 = " + TestString)
' TestString = ParseSet$(TestString, Comma, FieldNo, Format$(FieldNo))
TestString = ParseSet$(TestString, Comma, FieldNo, "4")
TestArray(Subscript) = TestString
FieldNo = 6
TestString = TestArray(Subscript)
If TestString = "" Then
TestString = ",,,,,,,,,,"
End If
MsgBox(0, "TestString - FieldNo = 6 = " + TestString)
' TestString = ParseSet$(TestString, Comma, FieldNo, Format$(FieldNo))
TestString = ParseSet$(TestString, Comma, FieldNo, "6")
TestArray(Subscript) = TestString
MsgBox(0,"Final Testarray Pass 2 = " + TestArray(1))
The automatic extension of delimited strings is a very handy facility to have.
Is it possible to have ParseSet$'s functionality extended to include that, or should I just make a function of my own?
(If I make a function of my own, I foresee some degradation in performance compared to a native thinBasic implementation. I will be using this technique a lot to handle multiple levels of screen, with different numbers and types of controls in each.)
Regards,
Peter H. (gungadout)