Results 1 to 2 of 2

Thread: Getting Values from String/Array

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2000
    Location
    UK
    Posts
    78

    Post

    Let says I had a string given back from a certain fuction or 'DLL' that contained numerous values about the system that was seperated by a certain charactor (!%) example:

    FAT32!%63555432!%FALSE!%24082000!%C:!%14

    I now want to know how to put each individual value into varibles, so it would end up like this:

    sys1 = FAT32
    sys2 = 63555432
    sys3 = FALSE

    e.t.c

    Can someone please help me out ?
    TIA




  2. #2
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845
    use the split() function
    Code:
    Option Explicit
    
    Private Sub Command1_Click()
    Dim strTemp() As String
    Dim i As Integer
    strTemp = Split("FAT32!%63555432!%FALSE!%24082000!%C:!%14", "!%")
    
    For i = 0 To UBound(strTemp())
    
    Debug.Print strTemp(i)
    Next i
    
    End Sub
    split is vb6 only so for vb 5 you'll need this:
    Code:
    Public Function Split(ByVal sIn As String, Optional sDelim As _
                String, Optional nLimit As Long = -1, Optional bCompare As _
                 VbCompareMethod = vbBinaryCompare) As Variant
              Dim sRead As String, sOut() As String, nC As Integer
              If sDelim = "" Then
                  Split = sIn
              End If
              sRead = ReadUntil(sIn, sDelim, bCompare)
              Do
                  ReDim Preserve sOut(nC)
                  sOut(nC) = sRead
                  nC = nC + 1
                  If nLimit <> -1 And nC >= nLimit Then Exit Do
                  sRead = ReadUntil(sIn, sDelim)
              Loop While sRead <> ""
              ReDim Preserve sOut(nC)
              sOut(nC) = sIn
              Split = sOut
          End Function
    Mark
    -------------------

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width