Re: [188] Using Control Arrays

  • 14 years ago
    Could you tell me how to make the index number accessible in a variable?
  • 14 years ago

    Hi Jason,

    You will have to be more specific, what exactly are you trying to do?
     
    If you want to know the index number of the control that was clicked you can use the Click event handler: 

    Public Sub cmdAction_Click(Index As Integer)
    'The variable Index now contains the subscript of the control that was clicked
    Label1.Caption = "You clicked Number " & Index
    End Sub

    I'm sure that will work for any of an objects allowable event types, mouseover, mousedown etc.

    If you want to refer to individual controls using a variable instead of the controls name:
    Dim a as Integer
    For a = 1 to 10
    objControlName(a).Text = ""
    Next
















  • 14 years ago

    I'm trying to link the record number in a random access file in a form to a control array in a separate form so that the record number is the number of the index. The only way i can think of it is to make a public variable that has the index number of the control clicked. But i have no idea how to seperate out the index from the object "lblSeat(index)".

  • 14 years ago

    If I understand you correctly, just create your control array, I've tested it with Labels and it works.  Double click on any one of them and it will automatically create a blank sub for you:

    Private Sub Label1_Click(Index As Integer)

    End Sub

    The variable called index that is being passed to the sub contains the index of the control.  You can use this in any way you want.  Try putting: MsgBox (Index) inside this sub and running it, you will see your index number!!

    To pass it to a different form you can add a module to your project: Project -> Add Module, and add the following line to it:
    Public globalindex As Integer

    Add the following code to Form1:
    Private Sub Label2_Click(Index As Integer)
    globalindex = Index
    Form1.Hide
    Form2.Show
    End Sub

    You can then use this variable in Form2:
    Private Sub Form_Load()
    FileName = "C:/" & globalindex & ".csv"
    Open FileName For Output As #1
    Print #1, "this Is a test"
    Close #1
    End Sub























  • 14 years ago

    It worked thank you. I don't know why I didn't think of that.

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“The generation of random numbers is too important to be left to chance.” - Robert R. Coveyou