|
-
Sep 18th, 2000, 02:00 AM
#1
Thread Starter
Lively Member
Does anybody know how I can assign a lot of values to an array at once?
in C I would do some thing like
int MyData[] = {1,1,2,3,7}
is there any way I can do something similar in VB?
-
Sep 18th, 2000, 02:51 AM
#2
Lively Member
You can't initiate variables in VB...yet - that comes with version 7.
Toot
Some cause happiness wherever they go; others, whenever they go.
-
Sep 18th, 2000, 02:59 AM
#3
Hyperactive Member
you can do something close though ..
dim myString as string
dim myArray
mystring="1,1,2,3,4,5,6,7,8"
myarray=split (mystring,",")
this will populate the array with the string component (devided by the ",").
In the beginning the universe was created. This has made a lot of people very angry and is generally regarded as a bad idea.
- Douglas Adams
The Hitchhiker's Guide to the Galaxy
-
Sep 18th, 2000, 03:50 AM
#4
transcendental analytic
For variant arrays you can do this:
Code:
Dim a as variant
a=array(1,2,3,4,5)
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Sep 18th, 2000, 06:27 PM
#5
Thread Starter
Lively Member
hmmm
I knew about the array function, but I must admit the split function was new to me. The problem is that in both cases I end up with a variant array. This would not be a problem as such if the initial data was all that i wanted in the array, but unfortunately I need to dynamically resize the array.
Can I still do this with variant arrays?
What if I wanted a multi dimensional array, can I still do it this way?
thanks for any help
-
Sep 18th, 2000, 06:38 PM
#6
Hyperactive Member
you can use
redim preserve array (size)
this will resize the array and keep the information
or ...
you can use dictionary objects and than you don't need to define a size, it is also more efficient with memory, where do you take the information from ? (a db ?)
In the beginning the universe was created. This has made a lot of people very angry and is generally regarded as a bad idea.
- Douglas Adams
The Hitchhiker's Guide to the Galaxy
-
Sep 18th, 2000, 06:50 PM
#7
Thread Starter
Lively Member
will redim preserve work with variant arrays as well as with arrays of variants?
The info doesn't come from a db, it depends on waht the user has entered while running the app
I think the Dictionary object is exactly what I want though, thanks
-
Sep 18th, 2000, 07:00 PM
#8
Hyperactive Member
I am not sure about the redim with variants,
But the dictionary objects are great, are you o.k with those ?
In the beginning the universe was created. This has made a lot of people very angry and is generally regarded as a bad idea.
- Douglas Adams
The Hitchhiker's Guide to the Galaxy
-
Sep 19th, 2000, 02:09 AM
#9
transcendental analytic
Àrrays in variant are just the same as regular arrays except that you can use For each to enumerate them, overwrite them with other arrays and anything else, and they are slightly slower. I'm not sure, i don't have vb here to test but i think you can pass a regular array as a variant into a function and then set the array inside the function. You could pass all the items in a paramarray variant.
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Nov 13th, 2000, 09:42 AM
#10
New Member
Just do this:
Code:
Dim MyArray() as long
ReDim MyArray(1) as Long 'do this else will not work
ReDim Preserve MyArray(NewSize)
That will work
theres a dictionary type in VB? goes to look that up
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
|