Solved

loading an array

Posted on 2006-06-16
15
205 Views
Last Modified: 2011-09-20
Hi Guys,
            Is it possible to load an array in VB the way itcam be done in C#,

int[] myArray = {1,4,6,7,8,9,0,7};

Thanks
Serge
0
Comment
Question by:Autofreak
  • 8
  • 4
  • 2
  • +1
15 Comments
 
LVL 37

Expert Comment

by:Harisha M G
ID: 16923989
Hi,

myArray = Array(1,4,6,7,8,9,0,7)

However, myArray must be of Variant type.



---
Harish
0
 

Author Comment

by:Autofreak
ID: 16924024
What if it's two_dimensional?
Serge
0
 
LVL 37

Accepted Solution

by:
Harisha M G earned 200 total points
ID: 16924025
Autofreak, somewhat better if you want to take care of the type also...

    Dim iArray() As Integer
    myarray = Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
    For i = LBound(myarray) To UBound(myarray)
        ReDim Preserve iArray(LBound(myarray) To i)
        iArray(i) = myarray(i)
    Next

0
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 37

Expert Comment

by:Harisha M G
ID: 16924032
   myarray = Array(Array(1, 2, 3, 4),Array(5, 6, 7, 8),Array(9, 10, 11, 12), _
                    Array(13, 14, 15, 16))
0
 

Author Comment

by:Autofreak
ID: 16924209
Cool
        How do I retrieve myArray(0,1) in one line?? It does't onderstand this syntax.
Thanks
Serge

0
 
LVL 37

Expert Comment

by:Harisha M G
ID: 16924218
You told the answer yourself !!

myArray(0,1)

!!
0
 
LVL 37

Expert Comment

by:Harisha M G
ID: 16924228
Oh.. sorry.. you should use

myArray(0)(1)

to get 2 (1st row, 2nd column)

Usually 0,1 is used. However, in this case, we are using a variant to act as an array. So, we should use this syntax.
0
 

Author Comment

by:Autofreak
ID: 16924311
Damn it,
          the functions that recieve the values from the array compalin on argument type mismatch ,
is there a function to convert a variant into a string?

Serge
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 16924404
Are you using VB6 or Vb.Net?
0
 
LVL 37

Expert Comment

by:Harisha M G
ID: 16924409
what exactly are you storing ?
0
 
LVL 37

Expert Comment

by:Harisha M G
ID: 16924426
Idle_Mind, if it were VB.NET, then he could have assigned it directly, as in C#
I think it is VB 6.


0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 16924428
Right...with slight differences in syntax.

I just wanted to be sure.  =)
0
 
LVL 37

Expert Comment

by:Harisha M G
ID: 16924446
:)
0
 
LVL 9

Expert Comment

by:justchat_1
ID: 16924651
if you needed it:
string = CStr(varient)
0
 

Author Comment

by:Autofreak
ID: 16995465
Sorry Guys, So distracted I was, eXcellent tips,

Cheers
Serge
                 
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

829 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