array question
array question
(OP)
hi
i have a line of data with fields of various lengths that i need to extract. each field varies in length and are separated by spaces (could be one or more spaces):
eg: XXXXXXXX XXXXXX XXXXXXXXX XXXXXXXXX XX
i'm looking for a code that will give me something like
field1 = " ", field2 = " "...etc. i need to place these fields on another screen.
i tried to test each character until i reach a space. this is what i have so far
i can get the first field but am stuck getting the rest of the fields.
any thoughts? i'm not good with arrays.
thanks
zach
i have a line of data with fields of various lengths that i need to extract. each field varies in length and are separated by spaces (could be one or more spaces):
eg: XXXXXXXX XXXXXX XXXXXXXXX XXXXXXXXX XX
i'm looking for a code that will give me something like
field1 = " ", field2 = " "...etc. i need to place these fields on another screen.
i tried to test each character until i reach a space. this is what i have so far
CODE
linedat = sess.getstring (16, 11, 69)
for i = len(linedat)
field = mid(linedat,i,1)
if field = " " then field1 = sess.getstring (16,11, i -1)
next i
for i = len(linedat)
field = mid(linedat,i,1)
if field = " " then field1 = sess.getstring (16,11, i -1)
next i
any thoughts? i'm not good with arrays.
thanks
zach
RE: array question
zach,
VBA has a Split function. Extra does not. So here's a clone of that function and an example, written and tested in VBA...
CODE
Dim i As Integer, a() As String, p1 As Integer, idx
p1 = 1
For i = 1 To Len(s)
If Mid(s, i, 1) = delim Then
ReDim Preserve a(idx)
a(idx) = Mid(s, p1, i - p1)
p1 = i + 1
idx = idx + 1
End If
Next
SplitIt = a
End Function
Sub testit()
Dim a, i As Integer
a = SplitIt("XXXXXXXX XXXXXX XXXXXXXXX XXXXXXXXX XX", " ")
For i = 0 To UBound(a)
Debug.Print a(i)
Next
End Sub
Skip,
Just traded in my old subtlety...
for a NUANCE!
RE: array question
Sorry zach, I failed to add the final parse...
CODE
Dim i As Integer, a() As String, p1 As Integer, idx
p1 = 1
For i = 1 To Len(s)
If Mid(s, i, 1) = delim Then
ReDim Preserve a(idx)
a(idx) = Mid(s, p1, i - p1)
p1 = i + 1
idx = idx + 1
End If
Next
ReDim Preserve a(idx)
a(idx) = Mid(s, p1, i - p1)
SplitIt = a
End Function
Skip,
Just traded in my old subtlety...
for a NUANCE!
RE: array question
Here it is cleaned up a bit
CODE
Dim i As Integer, a() As String, p1 As Integer, idx
p1 = 1
For i = 1 To Len(s)
If Mid(s, i, 1) = delim Then
GoSub ParseIt
p1 = i + 1
idx = idx + 1
End If
Next
GoSub ParseIt
SplitIt = a
Exit Function
ParseIt:
ReDim Preserve a(idx)
a(idx) = Mid(s, p1, i - p1)
Return
End Function
Skip,
Just traded in my old subtlety...
for a NUANCE!
RE: array question
thanks for the feedback. i will give it a try.
zachi