?
Solved

How to Initialize arrays at declaration time

Posted on 2003-02-22
5
Medium Priority
?
154 Views
Last Modified: 2010-04-07
Hi. Hopefully this is a simple question. I simply want to declare an array of structures and fill it with constant values.

For example:

Public Type MYTYPE
  myint as integer
  mystr as string
end type

Public MyTypes(10) as MYTYPE

I know I could assign the values in a routine here, but is there some way I can just assign them at declaration time. I know I can do it in C, what about VB?

Any help is appreciated?

Thanks.
0
Comment
Question by:jnhgustin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 18

Expert Comment

by:bobbit31
ID: 7999613
Dim Mytypes() as MYTYPE


you can do this whereever:

ReDim MyTypes(10)
0
 

Author Comment

by:jnhgustin
ID: 7999631
I new I wasn't being clear, that's why I'm having trouble. The answer I'm hoping for is something like:

Public MyTypes(10) as MYTYPE = { 1, "x", 2, "y", ... }

or something like that I would hope. The key is initializing the values or setting them as constants.



 
0
 
LVL 3

Accepted Solution

by:
Gunsen earned 100 total points
ID: 7999659
Not possible with VB 6, but in VB.net
Use for load to initialize array

Dim arr
arr = Split( "a","b","c")
0
 

Author Comment

by:jnhgustin
ID: 7999857
I new I wasn't being clear, that's why I'm having trouble. The answer I'm hoping for is something like:

Public MyTypes(10) as MYTYPE = { 1, "x", 2, "y", ... }

or something like that I would hope. The key is initializing the values or setting them as constants.



 
0
 

Author Comment

by:jnhgustin
ID: 8001151
I new I wasn't being clear, that's why I'm having trouble. The answer I'm hoping for is something like:

Public MyTypes(10) as MYTYPE = { 1, "x", 2, "y", ... }

or something like that I would hope. The key is initializing the values or setting them as constants.



 
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month8 days, 20 hours left to enroll

764 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