![]() |
I need help with VB
I want to fill an array with data but there must be an easier way than this.
Dim MyArray$(7) MyArray$(1) = "Monday" MyArray$(2) = "Tuesday" MyArray$(3) = "Wednesday" What I really want is something like this. Dim MyArray$(7) Data "Monday","Tuesday","Wednesday" ..... then use a loop to add the data to the array. I could store the data in a text file and read it in like this Open "data.txt" For Input As #1 Do x = x + 1 Input #1, a$ MyArray$(x) = a$ Loop Until EOF(1) Close but I want my data string to be stored within the program. :helpme |
You could store them as comma delimited or whatever then use a function to loop through them and put them in an array I guess.
|
There aren't too many different ways.
<% Dim mArray(11) mArray=Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December") %> |
2 ways come to mind and there are probably better ones:
1)define a string variable with comma delimeters and then use a string tokenizer or 2)similar to above but use the SPLIT() function which automatically tokenizes a string and returns an array with all the tokens as the array elements. have fun! |
Quote:
In old basics you could just use the "Data" and "Read" but VB don't appear to have such a function. If you gad a string like .... MyData$="Monday,Tuesday,Wednesday,Thursday" how would you put them into an array? :helpme |
|
Dim Days() as String = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" }
remember VB starts its arrays at 0... so sunday is day(0) not day(1). |
here is a little code i threw up, shows you start with a string then add's data to it. hope this is what you were looking for :thumbsup
Function Dates() Dim strDay As String, iCount As Integer strDay = "Monday,Tuesday,Wednesday,Thursday,Friday,Saturday ,Sunday" strDates = Split(strDay, ",") For iCount = LBound(strDates) To UBound(strDates) strDates(iCount) = strDates(iCount) & " Index (" & iCount & ")" & vbNewLine MsgBox strDates(iCount) Next iCount End Function |
Quote:
|
Quote:
|
Quote:
Unfortunately its not supported in my old version of VB, I guess its time to upgrade. |
Quote:
I feel so old and out of date :1orglaugh |
| All times are GMT -7. The time now is 08:28 AM. |
Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123