|
-
Jan 28th, 2003, 04:25 PM
#1
Thread Starter
Addicted Member
Arrays
I would like to load a lsit and have it in an array but im new and havent done alot with an array so for practice I want to laod a lsit and then when I press I command button it laods everything in the array and puts it in List1...Thx very much guys I aprepciate it
-
Jan 28th, 2003, 04:27 PM
#2
Let me in ..
-
Jan 28th, 2003, 04:52 PM
#3
Thread Starter
Addicted Member
Hmm thx man I appreciate it but im very new and stupid with vb so could u show a clear code of laoding an array with a command button and then dispalying whats in it in list1?Thx bro
-
Jan 28th, 2003, 05:13 PM
#4
PowerPoster
VB Code:
Dim ListArray() As String 'in the genereal declerations section of the form...this is above all other code
'Then in the click event add the items
Private Sub Command1_Click()
ReDim ListArray(0) As String 'Create the array
ReDim Preserve ListArray(UBound(ListArray) + 1)'Add a new element to the array
ListArray(UBound(ListArray)) = "First Item" 'fill that new element with a string
ReDim Preserve ListArray(UBound(ListArray) + 1)
ListArray(UBound(ListArray)) = "Second Item"
ReDim Preserve ListArray(UBound(ListArray) + 1)
ListArray(UBound(ListArray)) = "Third Item"
ReDim Preserve ListArray(UBound(ListArray) + 1)
ListArray(UBound(ListArray)) = "Fourth Item"
ReDim Preserve ListArray(UBound(ListArray) + 1)
ListArray(UBound(ListArray)) = "Fith Item"
ReDim Preserve ListArray(UBound(ListArray) + 1)
ListArray(UBound(ListArray)) = "Sixth Item"
For i = 1 To UBound(ListArray) 'loop thru the arrray and add the items to the listbox.
List1.AddItem (ListArray(i))
Next
End Sub
-We have enough youth. How about a fountain of "Smart"?
-If you can read this, thank a teacher....and since it's in English, thank a soldier.

-
Jan 28th, 2003, 05:24 PM
#5
Thread Starter
Addicted Member
Originally posted by Arc
VB Code:
Dim ListArray() As String 'in the genereal declerations section of the form...this is above all other code
'Then in the click event add the items
Private Sub Command1_Click()
ReDim ListArray(0) As String 'Create the array
ReDim Preserve ListArray(UBound(ListArray) + 1)'Add a new element to the array
ListArray(UBound(ListArray)) = "First Item" 'fill that new element with a string
ReDim Preserve ListArray(UBound(ListArray) + 1)
ListArray(UBound(ListArray)) = "Second Item"
ReDim Preserve ListArray(UBound(ListArray) + 1)
ListArray(UBound(ListArray)) = "Third Item"
ReDim Preserve ListArray(UBound(ListArray) + 1)
ListArray(UBound(ListArray)) = "Fourth Item"
ReDim Preserve ListArray(UBound(ListArray) + 1)
ListArray(UBound(ListArray)) = "Fith Item"
ReDim Preserve ListArray(UBound(ListArray) + 1)
ListArray(UBound(ListArray)) = "Sixth Item"
For i = 1 To UBound(ListArray) 'loop thru the arrray and add the items to the listbox.
List1.AddItem (ListArray(i))
Next
End Sub
Oh wow ok thx very much bro so this:For i = 1 To UBound(ListArray) 'loop thru the arrray and add the items to the listbox.
List1.AddItem (ListArray(i))
Nextthat goes into a command button of where I want to add the items to list1 and then:Private Sub Command1_Click()
ReDim ListArray(0) As String 'Create the array
ReDim Preserve ListArray(UBound(ListArray) + 1)'Add a new element to the array
ListArray(UBound(ListArray)) = "First Item" 'fill that new element with a string
ReDim Preserve ListArray(UBound(ListArray) + 1)
ListArray(UBound(ListArray)) = "Second Item"
ReDim Preserve ListArray(UBound(ListArray) + 1)
ListArray(UBound(ListArray)) = "Third Item"
ReDim Preserve ListArray(UBound(ListArray) + 1)
ListArray(UBound(ListArray)) = "Fourth Item"
ReDim Preserve ListArray(UBound(ListArray) + 1)
ListArray(UBound(ListArray)) = "Fith Item"
ReDim Preserve ListArray(UBound(ListArray) + 1)
ListArray(UBound(ListArray)) = "Sixth Item"
then does that go in a comamnd button to laod an array?Thx for the help bro
-
Jan 28th, 2003, 05:27 PM
#6
Thread Starter
Addicted Member
O damn sorry I got it im very stupid and that worked really good!!!So thx very much but in 1 command button I want to load a txt file and have it in an array...So just like what u did but be able to load a file from your computer and have it in there(array) then click the comamnd button and add them all to your lsit box...So could u help me out ehre plz?Thx man I aprpeciate it
-
Jan 28th, 2003, 05:42 PM
#7
PowerPoster
Well to put a txt file into an array i would use the Split function.
Input the txt file and store its contents in a Variable, then use the Split function to break it into peices and put it in an array. You need to decide how you want to split it up... You want to split it everywhere there is a Space, or a period, or the letter i... it's up to you. THat is what is called Delimiter.
VB Code:
Dim MyArray() as string 'Create the array
MyArray = Split(MyString,"The Delimiter") 'As i said before the Delimter could be anything from a space " ", to a whole sentence "A sentence".
'Now you have an Array called MyArray
'To loop thru this array and add it to a listbox you do the same i showed you before.
For i = 0 to Ubound(MyArray)
List1.additem(MYarray(i))
Next
-We have enough youth. How about a fountain of "Smart"?
-If you can read this, thank a teacher....and since it's in English, thank a soldier.

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
|