Results 1 to 3 of 3

Thread: Creating VB Variables at RUNTIME

  1. #1
    tgo57
    Guest

    Creating VB Variables at RUNTIME

    Can I create a variable at runtime such as follows?

    dim i as integer
    for i = 1 to loopcount

    dim ListItem & i as listitem

    Set ListItem & i = lstConnections.ListItems.Add()
    ListItem & i.Text = "Item 1"

    next i

    I know this doesnt work but is there a way in VB to make this work?

    Thanks!

  2. #2
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Well you can't really 'create' a variable at runtime, but to do what you are saying there you could do this:

    VB Code:
    1. dim i as integer
    2. for i = 1 to loopcount 'i assume you set loopcount elsewhere
    3.  
    4. dim Itm as listitem 'can not have a variable the same name as a keyword
    5.  
    6. Set Itm = lstConnections.ListItems.Add()
    7. Itm.Text = "Item 1"
    8.  
    9. next i
    10.  
    11. Set Itm=nothing

    PS To make your code show up colorcoded and all put it between [ vbcode ] and [ /vbcode ] without the spaces.

  3. #3
    tgo57
    Guest

    Thumbs up Thank You!

    Yup your solution works great! Thank you very much!


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