get the index of the control array
Code:
Private Sub btnSubmit_Click()
Dim intIndex As Integer
If chk(intIndex) = vbChecked Then
Select Case intIndex
Case 0
Image1.Picture = LoadPicture("C:\Users\myrna\Documents\a VB VB\Pictures vb vb vb\1pc chicken.jpg")
Case 1
Image1.Picture = LoadPicture("C:\Users\myrna\Documents\a VB VB\Pictures vb vb vb\french fries.jpg")
Case 2 ' could also use "Case Else" here
Image1.Picture = LoadPicture("C:\Users\myrna\Documents\a VB VB\Pictures vb vb vb\hamburger.jpg")
Case 3
Image1.Picture = LoadPicture("C:\Users\myrna\Documents\a VB VB\Pictures vb vb vb\beef steak.jpg")
Case 4
Image1.Picture = LoadPicture("C:\Users\myrna\Documents\a VB VB\Pictures vb vb vb\lasagna.jpg")
Case 5
Image1.Picture = LoadPicture("C:\Users\myrna\Documents\a VB VB\Pictures vb vb vb\spaghetti.jpg")
Case 6
Image1.Picture = LoadPicture("C:\Users\myrna\Documents\a VB VB\Pictures vb vb vb\mexican green wave pizza.jpg")
End Select
End If
End Sub
that's my code, I created a control array of chkbox and the index is 0 to 6..
what I want is.. to get the index of the selected checkbox and use it in a select case statement, but my code is not working..
Re: get the index of the control array
More than 1 checkbox can be checked at one time. I think you should move this code into the chk_Click event instead
Re: get the index of the control array
I like that way, but our teacher asking us to do that select case approach.
Re: get the index of the control array
Its nearly the exact same code, but your image will be guaranteed to be loaded with the most recently checked box:
Code:
Private Sub chk_Click(Index As Integer)
If chk(Index).Value = vbChecked Then
Select Case Index
.... your case statements
End Select
End If
End Sub