|
-
Aug 4th, 2000, 06:54 PM
#1
Thread Starter
Addicted Member
Hello!
Is it possible to fill an array with one line och code?
For instance, if I want an array of strings with the days of the week, I could do it this way:
Dim week(7) as String
week(1) = "Monday"
week(2) = "Tuesday"
week(3) = "Wednesday"
...
week(7) = "Sunday"
But there must be a better way.
Some sort of
Dim week(7) as String
week = "Monday";"Tuesday";"Wednesday"..."Sunday"
or something.
It's possible in C++, allthough I've forgotten how to do it right now, so it must be a way.
Thanks for your help!
Pentax
Wilhelm Tunemyr,
Swede in London
[email protected]
"Dort, wo man Bücher verbrennt, verbrennt man am Ende auch Menschen"
Heinrich Heine (1797-1856)
Pravda vítezi!
(Truth prevails!)
-
Aug 4th, 2000, 07:31 PM
#2
Frenzied Member
I don't think so, it's not difficult to code though, even if there was it wouldn't be any faster to use the in built function than your own.
-
Aug 4th, 2000, 10:13 PM
#3
You can use the Split() function in VB6:
Code:
Dim vWeek As Variant
vWeek = Split("Monday,Tuesday,Wednesday,Thursday,Friday,Saturday,Sunday", ",")
Or the Format() Function:
Code:
Dim iDay As Integer
For iDay = 1 To 7
Debug.Print Format(CDate("01/" & iDay + 2 & "/2000"), "DDDD")
Next
-
Aug 5th, 2000, 12:39 AM
#4
You can use the Array function (the data type of the array must be variant, and it will start at index 0):
Code:
Dim week as Variant
week = Array("Sunday", "Monday", "Tuesday", .... "Saturday")
week(0) will refer to "Sunday", week(6) will refer to "Saturday".
"It's cold gin time again ..."
Check out my website here.
-
Aug 5th, 2000, 10:31 AM
#5
If you want your Array to start at 1, use the Option Base 1 statement.
Code:
Option Base 1
Private Sub Command1_Click()
MyAray = Array("Monday", "Tuesday")
Print MyArray(1)
End Sub
-
Aug 5th, 2000, 05:45 PM
#6
Thread Starter
Addicted Member
OK, thanks!
It's not so much for the speed as for my lazyness.
It takes less effort to do it this way.
But can it really not be done with an array of strings?
Pentax
Wilhelm Tunemyr,
Swede in London
[email protected]
"Dort, wo man Bücher verbrennt, verbrennt man am Ende auch Menschen"
Heinrich Heine (1797-1856)
Pravda vítezi!
(Truth prevails!)
-
Aug 5th, 2000, 07:04 PM
#7
You must declare it as a variant at first, but once you split it, the datatype will then be converted into a String array.
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
|