469,072 Members | 1,808 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,072 developers. It's quick & easy.

Array assignment

553 512MB
I have this declaration :


Private List() As Integer

I cant do like this:
List = 5

whats the way of assigning value to array one by one ?

Thanks
Jul 7 '07 #1
4 1879
r035198x
13,262 8TB
Please do not post questions in the articles section.
Moved to the forum
Jul 8 '07 #2
Killer42
8,435 Expert 8TB
I have this declaration :
Private List() As Integer
I cant do like this:
List = 5
whats the way of assigning value to array one by one ?
That depends a bit on what version of VB you're using. In VB.Net I believe you can assign initial values in the statement which defines the array.

In VB6, you can't do that. You have to assign them one by one, or in some sort of looping structure such as a FOR loop.

But whatever version you're using, the whole point of an array is that you refer to the individual elements within it by their index number. For example, to assign the value 5 to occurence 1 you would say
Expand|Select|Wrap|Line Numbers
  1. List(1) = 5
It's worth noting that VB will always start the array at occurrence zero, unless you tell it otherwise. So for instance, if you defined List(5) the entries will actually be numbered from 0 to 5. Pretty stupid, but that's MS for you. I recommend always specifying the exact dimensions of the array. For example Private List(1 To 5).
Jul 8 '07 #3
Do a static declaration like so:

Private m_CustomColors() As Integer = {&H0, &HFFFFFF, &H0, &HFFFFFF, &H0, &HFFFFFF, &H0, &HFFFFFF, &HFFFFFF, &H0, &HFFFFFF, &H0, &HFFFFFF, &H0, &HFFFFFF, &H0}

I used this to initialize a ColorPicker dialog's custom colors to display an alternating black and white pattern.

This provides a 16 element array.

Regards,
Jul 11 '07 #4
Killer42
8,435 Expert 8TB
Do a static declaration like so:...
Thanks for that.

Readers need to keep in mind this is VB.Net code and won't work in VB6.
Jul 11 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

20 posts views Thread by Petter Reinholdtsen | last post: by
18 posts views Thread by Vasileios Zografos | last post: by
2 posts views Thread by JJA | last post: by
57 posts views Thread by buuuuuum | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.