473,231 Members | 1,591 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,231 software developers and data experts.

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 2051
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

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

Similar topics

20
by: Petter Reinholdtsen | last post by:
Is the code fragment 'char a = ("a");' valid ANSI C? The problematic part is '("a")'. I am sure 'char a = "a";' is valid ANSI C, but I am more unsure if it is allowed to place () around the...
18
by: Vasileios Zografos | last post by:
Hello, can anyone please tell me if there is any difference between the two: double Array1; and
23
by: sandy | last post by:
I need (okay, I want) to make a dynamic array of my class 'Directory', within my class Directory (Can you already smell disaster?) Each Directory can have subdirectories so I thought to put these...
2
by: JJA | last post by:
I'm looking at some code I do not understand: var icons = new Array(); icons = new GIcon(); icons.image = "somefilename.png"; I read this as an array of icons is being built. An element of...
57
by: buuuuuum | last post by:
why array can't be assigned, like structs?
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.