Results 1 to 6 of 6

Thread: [2005] better codeing

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Apr 2006
    Posts
    147

    [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:
    1. 'im just gonna write sql statement to much to write connection and everything
    2.  
    3.  
    4. sql = "insert into table (jason) values (" & var1 & ")"
    5. sql.execute
    6.  
    7. sql = "insert into table (jason) values (" & var2 & ")"
    8. sql.execute
    9.  
    10. sql = "insert into table (jason) values (" & var3 & ")"
    11. sql.execute
    12.  
    13. sql = "insert into table (jason) values (" & var4 & ")"
    14. sql.execute
    15.  
    16. sql = "insert into table (jason) values (" & var5 & ")"
    17. sql.execute
    18.  
    19. .......
    20. .........
    21. ..........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

  2. #2
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,547

    Re: [2005] better codeing

    Quote 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:
    1. 'im just gonna write sql statement to much to write connection and everything
    2.  
    3.  
    4. sql = "insert into table (jason) values (" & var1 & ")"
    5. sql.execute
    6.  
    7. sql = "insert into table (jason) values (" & var2 & ")"
    8. sql.execute
    9.  
    10. sql = "insert into table (jason) values (" & var3 & ")"
    11. sql.execute
    12.  
    13. sql = "insert into table (jason) values (" & var4 & ")"
    14. sql.execute
    15.  
    16. sql = "insert into table (jason) values (" & var5 & ")"
    17. sql.execute
    18.  
    19. .......
    20. .........
    21. ..........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.

  3. #3
    Addicted Member
    Join Date
    Jun 2006
    Posts
    128

    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

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Apr 2006
    Posts
    147

    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.

  5. #5
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    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

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Apr 2006
    Posts
    147

    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
  •  



Click Here to Expand Forum to Full Width