Solved

Initializing An Array Easily

Posted on 2006-10-20
3
272 Views
Last Modified: 2010-04-23
Say I have something like this:

Public MyArray(100) As Single

Suppose I want to initialize all of them to 5.55. Is there an easy way?

Also consider the same for two-dimensional array:

Public MyArray(10,10) As Single

Edit: a way INSTEAD of using a For loop (or two For loops)
0
Comment
Question by:GivenRandy
3 Comments
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 17775518
You simply have to iterate over the entire array and set each element...no way around it.
0
 
LVL 9

Expert Comment

by:Naveen Swamy
ID: 17775932
iteration would help you in this
0
 
LVL 8

Expert Comment

by:fatalXception
ID: 17776548
whilst you can write this:

public myarray() as single = new single() {10,14,12,34} which will create a 4 element array with the values 10,14,12,34, you cannot initialise a fixed sized array like this.  Its just not allowed.

But I suppose if you really want to avoid a loop you could write it as
public myarray() as single = new single() {5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5,5.5} ...don't bother counting them, I have no idea how many there are there :)

Is there some particular reason why you don't want to do a loop?
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Word Template Mail merge with vb.net 4 56
More on Time zones in vb 2010 12 37
Advice on Xojo as a development tool over VB. 4 31
Variable Event ? 3 19
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

948 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now