Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2004
    Posts
    45

    Unanswered: declaring a variable number of variables

    Hallo,
    I have a multiselect listbox and I would need to store the selected item values in different variables. So I cannot forseen how many variables I will need.
    I was trying this:

    dim listquantity as integer
    dim i as integer
    listquantity = Me.List0.ListCount

    i = 0
    Do While i < listquantity
    If Me.List0.Selected(0) = True Then
    Dim listvalue & i As String
    'and then assign the value of me.list0.select(0) to the listvalue & i variable
    Else: End If
    Loop

    But of course it doesn't work to use operators such as & inside variables declaration. Do you know how I should proceed? thanks for helping

  2. #2
    Join Date
    Jan 2004
    Location
    Aberdeen, Scotland
    Posts
    1,067
    how about declaring an array and rediming to the size that you need

    i.e.
    Code:
    Sub Test()
    
        Dim SelList() As String
        
        For i = 1 To 5
            ReDim Preserve SelList(i)
            SelList(i) = 2 * i
        Next i
        
        For i = 1 To 5
            Debug.Print i, SelList(i)
        Next i
    End Sub
    This little example shows what i mean
    HTH
    Dave

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •