Results 1 to 3 of 3

Thread: [RESOLVED] Variable Name in a variable way

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2005
    Posts
    4

    Resolved [RESOLVED] Variable Name in a variable way

    I want to define variables in a loop. Something as below.

    Dim ctr as integer
    for ctr=1 to 10
    dim MyVar<value of ctr>
    ' which will be like MyVar1...MyVar10
    next

    Can this be done ?

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Variable Name in a variable way

    No. When you use Dim to declare a variable, that variable ceases to exist once the current block, in your case the current iteration of the For loop, completes. Try using an array or a collection. That's what they're for:
    VB Code:
    1. Dim ctr As Integer = 10
    2. Dim myVars(ctr - 1) As Object
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    New Member
    Join Date
    Sep 2005
    Posts
    4

    Re: Variable Name in a variable way

    Thanx a lot.

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