Results 1 to 15 of 15

Thread: Array Question

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Seattle
    Posts
    954

    Array Question

    Hi I am trying to take a string that would look like this:

    filename.exe|filename.fil<br>filename.pdf|filename.doc

    I then want to use split to split on the <br> tag. From there I would like to have all the filenames placed into an array like this:

    array(o) = filename.exe
    array(1) = filename.fil
    array(2) = filename.pdf
    array(3) = filename.doc

    Problem is that I will never know how large the array should be. It is going to be completely dynamic. Here is what I have so far:

    Dim tmp$
    Dim tmpArray() As String
    Dim intDynArray() As String

    tmp = MinusHeader
    tmpArray = Split(tmp, "<br>")
    'ReDim Preserve intDynArray(UBound(tmpArray) + 1)
    Dim i%
    For i = 0 To tmpArray(UBound(tmpArray))
    Debug.Print tmpArray(i)
    Next i

  2. #2
    Frenzied Member moinkhan's Avatar
    Join Date
    Jun 2000
    Location
    Karachi, Pakistan
    Posts
    2,011
    First you want to Split the String with <BR> then the resulting Strings with | ???
    VB Code:
    1. Dim tmp$
    2. Dim tmpArray() As String
    3. Dim intDynArray() As String
    4.  
    5. tmp = MinusHeader
    6. tmpArray = Split(tmp, "<br>")
    7.  
    8. Dim i%
    9. For i = 0 To tmpArray(UBound(tmpArray))
    10.    intDynArray = Split (tmpArray(i),"|")
    11.  
    12. Next i
    Well I suspect this is not what you want..

  3. #3
    Frenzied Member moinkhan's Avatar
    Join Date
    Jun 2000
    Location
    Karachi, Pakistan
    Posts
    2,011
    I think... I got you now..
    VB Code:
    1. Dim tmp$
    2. Dim tmpArray() As String
    3. Dim intDynArray() As String
    4. Dim FinalArray() As String
    5. tmp = MinusHeader
    6. tmpArray = Split(tmp, "<br>")
    7.  
    8. Dim PrevIndex As Integer
    9. Dim i%
    10. For i = 0 To tmpArray(UBound(tmpArray))
    11.    intDynArray = Split (tmpArray(i),"|")
    12.    ReDim Preserve FinalArray(UBound(intDynArray)-LBound(intDynArray)+1)
    13.    For X = PrevIndex  To UBound(FinalArray)
    14.         FinalArray(X) = intDynArray(X-PrevIndex)
    15.    Next X
    16. PrevIndex = UBound(FinalArray) + 1
    17. Next i

    I've not tested the code.. so please tell me whether it does

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Seattle
    Posts
    954
    Breaks here:

    For i = 0 To tmpArray(UBound(tmpArray))

    Type mismatch. I don't think that it can get the uBOund of a string? What do you think?

  5. #5
    Fanatic Member RealisticGraphics's Avatar
    Join Date
    Jul 1999
    Location
    Arkansas
    Posts
    655
    Try just For i = 0 To UBound(tmpArray)
    www.RealisticGraphics.net

    Running VS.Net Enterprise & VB 6

    Other Languages: JavaScript, VBScript, VBA, HTML, CSS, ASP, SQL, XML

    MSN Messenger: kmsheff

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Seattle
    Posts
    954
    OK, I am getting there. THis is what I have so far:


    VB Code:
    1. Public Function LoadFileIntoArray(MinusHeader As String) As String
    2. Dim tmp$
    3. Dim tmpArray() As String
    4. Dim intDynArray() As String
    5. Dim FinalArray() As String
    6. tmp = MinusHeader
    7. tmpArray = Split(tmp, "<br>")
    8.  
    9. Dim PrevIndex As Integer
    10. Dim i%, x%
    11. For i = 0 To UBound(tmpArray)
    12.    intDynArray = Split(tmpArray(i), "|")
    13.    ReDim Preserve FinalArray(UBound(intDynArray) - LBound(intDynArray)) ' + 1)
    14.    For x = PrevIndex To UBound(FinalArray)
    15.         FinalArray(x) = intDynArray(x - PrevIndex)
    16.         Debug.Print FinalArray(x)
    17.    Next x
    18. PrevIndex = PrevIndex + 1 'UBound(FinalArray)
    19. Next i
    20. End Function

    This only gets to the first filename in the second x. Am I making sense?

  7. #7
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    what is the use of the UBOUND?

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Seattle
    Posts
    954
    Which one?

  9. #9
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    i cant find in vb the defenition of Ubound know can tell me exactly what it does?

  10. #10

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Seattle
    Posts
    954
    Ubound is the Upper Bund of that array. So if my array goes form 0 to 5 the ubound woulb be 5.

  11. #11
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    tKS that seems very very usefull!

  12. #12
    PowerPoster MidgetsBro's Avatar
    Join Date
    Oct 2000
    Location
    Apparently, Internet.com
    Posts
    3,125
    Originally posted by PT Exorcist
    i cant find in vb the defenition of Ubound know can tell me exactly what it does?
    UBound = Upper Bound... the highest item in the array.
    LBound = Lower Bound... the lowest item in the array (usually 0)

    [edit]Jesus ****ing christ!!! It took 11 minutes for my post to actually show up on the forum... either my school's T1 is really ****ed or the vbforums are choking again...[/edit]
    Last edited by MidgetsBro; May 29th, 2002 at 01:28 PM.
    <removed by admin>

  13. #13
    PowerPoster MidgetsBro's Avatar
    Join Date
    Oct 2000
    Location
    Apparently, Internet.com
    Posts
    3,125
    What you are trying to is so much easier with a listbox... no worrying about UBounds of arrays and such. Here is some code I wrote using a listbox, but you probably still want to do it with an array.
    VB Code:
    1. Dim TempAry() As String
    2. Dim TempAry2() As String
    3. Open "C:\test.txt" For Input As #1
    4.     buff = Input$(LOF(1), 1)
    5.     TempAry = Split(buff, "<br>")
    6.     For i = 0 To UBound(TempAry)
    7.         TempAry2 = Split(TempAry(i), "|")
    8.         For j = 0 To UBound(TempAry2)
    9.             List1.AddItem TempAry2(j)
    10.         Next
    11.     Next
    12. Close #1
    <removed by admin>

  14. #14

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Seattle
    Posts
    954
    OK right now I have the code as follows:

    VB Code:
    1. Public Function LoadFileIntoArray(MinusHeader As String) As String
    2. Dim tmp$
    3. Dim tmpArray() As String
    4. Dim intDynArray() As String
    5. Dim FinalArray() As String
    6. Dim strCommand$
    7. Dim strWebPage$
    8.  
    9. tmp = MinusHeader
    10. tmpArray = Split(tmp, "<br>")
    11.  
    12. Dim PrevIndex As Integer
    13. Dim i%, x%
    14. For i = 0 To UBound(tmpArray)
    15.    intDynArray = Split(tmpArray(i), "|")
    16.    ReDim Preserve FinalArray(UBound(intDynArray) - LBound(intDynArray)) ' + 1)
    17.    For x = 0 To UBound(FinalArray)
    18.         FinalArray(x) = intDynArray(x - PrevIndex)
    19.         Debug.Print FinalArray(x)
    20.         strWebPage = "http://localhost/FileList/" & FinalArray(x)
    21.         strCommand = "GET " + strWebPage + " HTTP/1.0" + vbCrLf
    22.         strCommand = strCommand + "Accept: */*" + vbCrLf
    23.         strCommand = strCommand + vbCrLf
    24.         Debug.Print strCommand
    25.         'send the command to the server
    26.         winsock1.SendData strCommand
    27.    Next x
    28. 'PrevIndex = PrevIndex + 1 'UBound(FinalArray)
    29. Next i
    30. End Function

    IT does get the FinalArray(x) name correctly. So it loops through the array and prints the correct name. What I want to do with it next but am unsure how is to take that first name (remember they are split like filename.exe | filename.dll), download it but save it as the second filename.

    So I would download filename.exe and save it as filename.dll.

  15. #15
    Hyperactive Member
    Join Date
    May 2002
    Location
    Chicago
    Posts
    271
    This will create an array called aFileArray filled with the file names:

    Private Sub Command2_Click()
    Dim aFileArray()
    Dim sYourString As String
    Dim aBRSplit, aNextSplit
    Dim i, j, k As Integer

    sYourString = "filename.exe|filename.fil<br>filename.pdf|filename.doc"
    aBRSplit = Split(sYourString, "<BR>", , vbTextCompare)

    k = -1

    For i = 0 To UBound(aBRSplit)
    'if "|" is not in string the next line will still work
    aNextSplit = Split(aBRSplit(i), "|")

    For j = 0 To UBound(aNextSplit)
    ReDim Preserve aFileArray(k + 1)
    aFileArray(k + 1) = aNextSplit(j)
    k = k + 1
    Next j

    Next i

    For i = 0 To UBound(aFileArray)
    List1.AddItem aFileArray(i)
    Next i

    End Sub

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