Solved

loading an array

Posted on 2006-06-16
15
202 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
 
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…

707 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

19 Experts available now in Live!

Get 1:1 Help Now