?
Solved

loading an array

Posted on 2006-06-16
15
Medium Priority
?
210 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 800 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 86

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 86

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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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 Month14 days, 9 hours left to enroll

840 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