|
-
May 28th, 2002, 05:16 PM
#1
Thread Starter
Fanatic Member
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
-
May 28th, 2002, 05:22 PM
#2
Frenzied Member
First you want to Split the String with <BR> then the resulting Strings with | ???
VB Code:
Dim tmp$
Dim tmpArray() As String
Dim intDynArray() As String
tmp = MinusHeader
tmpArray = Split(tmp, "<br>")
Dim i%
For i = 0 To tmpArray(UBound(tmpArray))
intDynArray = Split (tmpArray(i),"|")
Next i
Well I suspect this is not what you want..
-
May 28th, 2002, 05:30 PM
#3
Frenzied Member
I think... I got you now..
VB Code:
Dim tmp$
Dim tmpArray() As String
Dim intDynArray() As String
Dim FinalArray() As String
tmp = MinusHeader
tmpArray = Split(tmp, "<br>")
Dim PrevIndex As Integer
Dim i%
For i = 0 To tmpArray(UBound(tmpArray))
intDynArray = Split (tmpArray(i),"|")
ReDim Preserve FinalArray(UBound(intDynArray)-LBound(intDynArray)+1)
For X = PrevIndex To UBound(FinalArray)
FinalArray(X) = intDynArray(X-PrevIndex)
Next X
PrevIndex = UBound(FinalArray) + 1
Next i
I've not tested the code.. so please tell me whether it does
-
May 28th, 2002, 05:57 PM
#4
Thread Starter
Fanatic Member
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?
-
May 28th, 2002, 06:08 PM
#5
Fanatic Member
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
-
May 29th, 2002, 12:55 PM
#6
Thread Starter
Fanatic Member
OK, I am getting there. THis is what I have so far:
VB Code:
Public Function LoadFileIntoArray(MinusHeader As String) As String
Dim tmp$
Dim tmpArray() As String
Dim intDynArray() As String
Dim FinalArray() As String
tmp = MinusHeader
tmpArray = Split(tmp, "<br>")
Dim PrevIndex As Integer
Dim i%, x%
For i = 0 To UBound(tmpArray)
intDynArray = Split(tmpArray(i), "|")
ReDim Preserve FinalArray(UBound(intDynArray) - LBound(intDynArray)) ' + 1)
For x = PrevIndex To UBound(FinalArray)
FinalArray(x) = intDynArray(x - PrevIndex)
Debug.Print FinalArray(x)
Next x
PrevIndex = PrevIndex + 1 'UBound(FinalArray)
Next i
End Function
This only gets to the first filename in the second x. Am I making sense?
-
May 29th, 2002, 01:02 PM
#7
yay gay
what is the use of the UBOUND?
-
May 29th, 2002, 01:04 PM
#8
Thread Starter
Fanatic Member
-
May 29th, 2002, 01:04 PM
#9
yay gay
i cant find in vb the defenition of Ubound know can tell me exactly what it does?
-
May 29th, 2002, 01:06 PM
#10
Thread Starter
Fanatic Member
Ubound is the Upper Bund of that array. So if my array goes form 0 to 5 the ubound woulb be 5.
-
May 29th, 2002, 01:11 PM
#11
yay gay
tKS that seems very very usefull!
-
May 29th, 2002, 01:22 PM
#12
PowerPoster
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>
-
May 29th, 2002, 01:30 PM
#13
PowerPoster
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:
Dim TempAry() As String
Dim TempAry2() As String
Open "C:\test.txt" For Input As #1
buff = Input$(LOF(1), 1)
TempAry = Split(buff, "<br>")
For i = 0 To UBound(TempAry)
TempAry2 = Split(TempAry(i), "|")
For j = 0 To UBound(TempAry2)
List1.AddItem TempAry2(j)
Next
Next
Close #1
-
May 29th, 2002, 02:21 PM
#14
Thread Starter
Fanatic Member
OK right now I have the code as follows:
VB Code:
Public Function LoadFileIntoArray(MinusHeader As String) As String
Dim tmp$
Dim tmpArray() As String
Dim intDynArray() As String
Dim FinalArray() As String
Dim strCommand$
Dim strWebPage$
tmp = MinusHeader
tmpArray = Split(tmp, "<br>")
Dim PrevIndex As Integer
Dim i%, x%
For i = 0 To UBound(tmpArray)
intDynArray = Split(tmpArray(i), "|")
ReDim Preserve FinalArray(UBound(intDynArray) - LBound(intDynArray)) ' + 1)
For x = 0 To UBound(FinalArray)
FinalArray(x) = intDynArray(x - PrevIndex)
Debug.Print FinalArray(x)
strWebPage = "http://localhost/FileList/" & FinalArray(x)
strCommand = "GET " + strWebPage + " HTTP/1.0" + vbCrLf
strCommand = strCommand + "Accept: */*" + vbCrLf
strCommand = strCommand + vbCrLf
Debug.Print strCommand
'send the command to the server
winsock1.SendData strCommand
Next x
'PrevIndex = PrevIndex + 1 'UBound(FinalArray)
Next i
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.
-
May 29th, 2002, 09:14 PM
#15
Hyperactive Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|