Re: Large file into an array
To fix your error:
VB Code:
Dim List As [b]New[/b] ArrayList
But I don't see why you are using an arraylist, you already have your strings in the listing array. I could be missing the point however ;)
Re: Large file into an array
If you're using an arraylist then you might as well read the file a line at a time:
VB Code:
Dim List As New ArrayList
Dim sr As New StreamReader(Application.StartupPath & "/Largefile.txt")
While sr.Peek > -1
List.Add(sr.ReadLine())
End While
sr.Close()
Otherwise just do as grilkip says and keep the strings in a string array.
Re: Large file into an array
Quote:
Originally Posted by Parallax
If you're using an arraylist then you might as well read the file a line at a time:
VB Code:
Dim List As New ArrayList
Dim sr As New StreamReader(Application.StartupPath & "/Largefile.txt")
While sr.Peek > -1
List.Add(sr.ReadLine())
End While
sr.Close()
Otherwise just do as grilkip says and keep the strings in a string array.
Thx, thats exactly what i needed. :thumb:
Re: Large file into an array
Well thats done, but now i have another problem.
Now i need have several values, and i need to check if any of them are present in the array. As i understand this code is supposed to work, but it doesnt:
VB Code:
While False
If List.Contains("value1") Then
MsgBox("present")
End If
End While
What can be the problem here?
Re: Large file into an array
VB Code:
'While False 'While False means it will never execute
If List.Contains("value1") Then
MsgBox("present")
End If
'End While
Re: Large file into an array
Quote:
Originally Posted by grilkip
VB Code:
'While False 'While False means it will never execute
If List.Contains("value1") Then
MsgBox("present")
End If
'End While
Oops... well that was stupid. :blush:
But still, i need to put it into a loop, so i only need to do this: "While True"?
Re: Large file into an array
depends on what you want to do, While true will start a never ending loop.
??
Re: Large file into an array
Quote:
Originally Posted by grilkip
depends on what you want to do, While true will start a never ending loop.
??
Yep, that's it, it must loop throu the array all the time, to see if the values are there
Re: Large file into an array
VB Code:
Dim vals() as string = {"list1","list2"}
For each val as string in vals
if list.contains(val) then
'whatever
end if
Next
Re: Large file into an array
Is your question how can you run this code all the time checking to see if the value in the list is present? You do not want to do a neverending loop, it will take all of your process time. You would simply call the sub containing the check code each time an item changes or an item is added to the list.
Are you just wanting to open the file and search for a particular line? If so, put the check in the readline method as you read in each line. If the string = the string you are searching for, you can exit the loop and close the file.
Re: Large file into an array
Quote:
Originally Posted by wild_bill
VB Code:
Dim vals() as string = {"list1","list2"}
For each val as string in vals
if list.contains(val) then
'whatever
end if
Next
Thx, that's exactly what i needed :thumb:
To gigemboy:
Well my app is still far from finished, so i dont know if its better to make a never ending loop or a sub, but that shouldn't be a problem now that i know how to check the array for specific values