|
-
Aug 16th, 2006, 06:55 PM
#1
Thread Starter
Addicted Member
[2005] better codeing
not sure what to call this so sorry for the title
ok say i have 10 variables
var1
var2
var3
var4
var5
var6
var7
var8
var9
var10
ok each of them needs to be processed into sql
so
VB Code:
'im just gonna write sql statement to much to write connection and everything
sql = "insert into table (jason) values (" & var1 & ")"
sql.execute
sql = "insert into table (jason) values (" & var2 & ")"
sql.execute
sql = "insert into table (jason) values (" & var3 & ")"
sql.execute
sql = "insert into table (jason) values (" & var4 & ")"
sql.execute
sql = "insert into table (jason) values (" & var5 & ")"
sql.execute
.......
.........
..........so on and so on
in my actual project it is much more complicated but thats the jist of it
now is there an easier way of doing this?
like doing a for loop 10 times or something. if i did a loop i dont know how to change the var name to be based off the loop tho.
anyways thanks for your help in advance.
-JLR
-
Aug 16th, 2006, 06:56 PM
#2
Frenzied Member
Re: [2005] better codeing
 Originally Posted by ikaris69
not sure what to call this so sorry for the title
ok say i have 10 variables
var1
var2
var3
var4
var5
var6
var7
var8
var9
var10
ok each of them needs to be processed into sql
so
VB Code:
'im just gonna write sql statement to much to write connection and everything
sql = "insert into table (jason) values (" & var1 & ")"
sql.execute
sql = "insert into table (jason) values (" & var2 & ")"
sql.execute
sql = "insert into table (jason) values (" & var3 & ")"
sql.execute
sql = "insert into table (jason) values (" & var4 & ")"
sql.execute
sql = "insert into table (jason) values (" & var5 & ")"
sql.execute
.......
.........
..........so on and so on
in my actual project it is much more complicated but thats the jist of it
now is there an easier way of doing this?
like doing a for loop 10 times or something. if i did a look i dont know how to change the var name to be based of the loop tho.
anyways thanks for your help in advance.
-JLR
dim var(9) as integer
just create an array.
-
Aug 16th, 2006, 07:02 PM
#3
Addicted Member
Re: [2005] better codeing
Well if you are asking about the looping ...
You could try storing the information in an array and uses a loop for the Array.
e.g
Code:
dim array as new arraylist
array[0]=var1
array[1]=var2
.
.
.
for temp as integer =0 to 10
sql = "insert into table (jason) values (" & array[temp] & ")"
sql.execute
next
-
Aug 16th, 2006, 09:32 PM
#4
Thread Starter
Addicted Member
Re: [2005] better codeing
thanks for the replies
well i already do that with most of the information, but some reason i had coded(about 3 months ago) a certain few like the example and i could have sworn i saw a way to coding a loop around variables that were like that.
-
Aug 17th, 2006, 09:41 AM
#5
Re: [2005] better codeing
There was one in VB6, but I never used it. I remember people in that forum were often asking how could I call by a string name of a variable, and I believe there was a way. I don't remember what the technique was, just that it was fairly obscure, and I never had a use for it. You might try searching in that forum, but don't get your hopes up, it might well be something that didin't move over to .NET.
My usual boring signature: Nothing
 
-
Aug 17th, 2006, 10:52 AM
#6
Thread Starter
Addicted Member
Re: [2005] better codeing
yeah thats what i remember thanks ill search for it
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|