473,412 Members | 2,304 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,412 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 2058
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?
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.