?
Solved

loading an array

Posted on 2006-06-16
15
Medium Priority
?
208 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
[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
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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 …
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…
Suggested Courses

765 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