variable declaration

I have a large group of variables like:

var1, var2,var3...
dim I as integer

and I want to do this
in a (For Next) block

set var(i) to WHATEVER
is this possible???
MBHEY131Asked:
Who is Participating?
 
Martin LissOlder than dirtCommented:
I don't know anything about queries but the only way to refer to a bunch of array entries is something like

MsgBox MyArray(1) & MyArray(5) & MyArray(7)

which if MyArray(1) was "Just" and MyArray(5) was "for" and MyArray(7) was "fun" then the msgbox would display "justforfun".
0
 
Martin LissOlder than dirtCommented:
No, but you could create an array to store the various values in and loop through the entries.
0
 
MBHEY131Author Commented:
Ok, I see (My first exposure to the arrays), although they may be the answer here:
I have a few follow up ?'s

I make an array as follows:

Dim myarray1(10) as string (or whatever)
Dim myarray2(15) as string (or whatever)

I then will be passing (all the values) to an INSERT QUERY (or UPDATE) for updating a database


My ?'s

This is (A EXAMPLE) of my INSERT QUERY (Not the actual ONE)
Me.RO_InvTableAdapter1.FillByVerifyRO_Exists(DbseRO_InvDataSet.RO_Inv, RoNum_Ln1)


This QUERY has only 1 VARIABLE (RoNum_Ln1) but the one in ? will have many more can I pass the DATA to the QUERY like this:
Me.RO_InvTableAdapter1.FillByVerifyRO_Exists(DbseRO_InvDataSet.RO_Inv, myarray1(10),myarray2(15))
Will that bring ALL 25 values to the insert for updating? (And also):

what if my INSERT QUERY is now set to accept the values like an in order of:  myarray1(0),myarray2(0),myarray1(1),myarray2(1) and so on ?

I can reorder if I have to because right now I don't have any (array variables) in the INSERT (OR IS THERE A WAY OF SETTING UP THE "INSERT QUERY" to accept the array???)

thanx a bunch for your help on this!
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
Martin LissOlder than dirtCommented:
I'm not sure I understand your question, but by default arrays start at index 0 so Dim MyArray(10) will create an array with 11 entries and the 1st entry would be referred to via MyArray(0). You could however do this:

Dim MyArray(1 to 10) As String

and then there would be room for only 10 entries and the first one would be MyArray(1).
0
 
MBHEY131Author Commented:
ok that's fine (my understanding "although limited" was that the number 10 would give you 10 variables (0-9 for the index), but OK I can figure that out later)
 What about passing to the QUERY, CAN YOU PASS THEM IN BUNCHS LIKE THAT, AND THE ORDERING??
0
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
You'll have to create a Sql for each single value (array element), there is no bulk operation.
0
 
MBHEY131Author Commented:
It say's I must start my Array with a 0 on the line

Dim MyArray(1 to 10) As String
which is OK with me but my ? would be if I don't put anything at all in the (0) index variable,
Will this mess up my other Array fields.?
0
 
Martin LissOlder than dirtCommented:
It say's I must start my Array with a 0 on the line
Where does it say that?

Sub test()
Dim myArray(10) As String
Dim myArrayTwo(1 To 10) As String

myArray(0) = "This "
myArray(1) = " is "
myArray(2) = " a "
myArray(3) = " test "

' This produces "This  is  a  test"
Debug.Print myArray(0) & myArray(1) & myArray(2) & myArray(3)

myArrayTwo(1) = "My "
myArrayTwo(2) = " name "
myArrayTwo(3) = " is "
myArrayTwo(4) = " Marty "

' This produces "My  name  is  Marty "
Debug.Print myArrayTwo(1) & myArrayTwo(2) & myArrayTwo(3) & myArrayTwo(4)

End Sub
0
 
MBHEY131Author Commented:
It say's I must start my Array with a 0 on the line

 Where does it say that?
++++++++++++++++++++++++++++++++++++++++++
visual studio 2012 in vb.net gives me that error when I try to declare the array.
===============================================================

but that's OK, the code seems to function with nothing in the (0) index variable.
0
 
Martin LissOlder than dirtCommented:
Oh, I see. You never mentioned that this was .Net. And yes, it's OK (at least in VBA and VB6) to have nothing in (0).
0
 
MBHEY131Author Commented:
1 more quick ? - Below is the start of the "ACTUAL UPDATE QUERY" that I am going to call (after changes for ARRAY values obviously) this QUERY was built by the WIZARD in vs2012 and vb.net

UPDATE       RO_Inv
SET                RO_PrtsNum_P1_Ln1 = @RO_PrtsNum_P1_Ln1, RO_PrtsDesc_P1_Ln1 = @RO_PrtsDesc_P1_Ln1, RO_PrtsSoldQty_P1_Ln1 = @RO_PrtsSoldQty_P1_Ln1,

I'm not quite sure I understand the variable issues:

My Understanding is:

The Variables in the above query  are:
var1 =  @RO_PrtsNum_P1_Ln1,
var2 =  @RO_PrtsDesc_P1_Ln1,
var3 =  @RO_PrtsSoldQty_P1_Ln1,
and so on as this is a vary large query (for me anyway)

my code to pass the query and variables would be something like:

Me.RO_Inv_PARTS_Ln1_TableAdapter1.Upd_Qry_PARTS_Ln1(Me.DtabseRO_Ln1_DataSet1.RO_Inv, myarray1(1),myarray2(1),myarray3(1),etc...)

Now do I have to pass the actual query variable names in the code or does the system (vs2012,vb.net) know to interpret them in the order their passed.

making this short as possible

do the variable names in the query have to match what I pass to the query in code?? I guess that is the ?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.