[RESOLVED] Help control array change borderstyle
There are 5 images. When I click on one I want to change it's borderstyle. Only one image can have a borderstyle = 1 at any time. So how I change the previous image borderstyle back to zero.
Code:
If imgCar(Index).BorderStyle = 0 Then
imgCar(Index).BorderStyle = 1
Else
imgCar(Index).BorderStyle = 0
End If
Re: Help control array change borderstyle
Loop throu control aray and reset border first, then set it to currently selected (clicked) control. Try something like this:
Code:
Option Explicit
Private Sub Image1_Click(Index As Integer)
Dim i As Integer
For i = Image1.LBound To Image1.UBound
Image1(i).BorderStyle = 0
Next i
Image1(Index).BorderStyle = 1
End Sub
Edit: add error handler to avoid errors for missing control array member (say, you have 0, 1, 3 but not 2).
Re: [RESOLVED] Help control array change borderstyle
Another approach would be is to keep track of the last Image control clicked via a Static (or module-level) variable:
Code:
Private Sub imgCar_Click(Index As Integer)
Static OldIndex As Integer '<-- Assumes there's an Image control with an Index of 0
If Index <> OldIndex Then imgCar(OldIndex).BorderStyle = 0
imgCar(Index).BorderStyle = 1
OldIndex = Index
End Sub