×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

array question

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

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
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

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

Function SplitIt(s As String, delim As String)
    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,

glassesJust traded in my old subtlety...
for a NUANCE!tongue

RE: array question



Sorry zach, I failed to add the final parse...

CODE

Function SplitIt(s As String, delim As String)
    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,

glassesJust traded in my old subtlety...
for a NUANCE!tongue

RE: array question



Here it is cleaned up a bit

CODE

Function SplitIt(s As String, delim As String)
    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,

glassesJust traded in my old subtlety...
for a NUANCE!tongue

RE: array question

(OP)
hi skip,
thanks for the feedback. i will give it a try.

zachi

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close