agmorgan
Jan 21st, 2004, 12:57 PM
Remember this is using VBA in Excel!
I have a form with 5 RefEdit controls on it and 5 associated labels.
There is also a textbox with a spinbutton (UpDown control?)
which regulates how many of the RefEdit controls are enabled.
A control array would be better than this select case, but control
arrays aren't available in VBA.
How can I improve? :(
Private Sub spnLines_Change()
' Change the Value of the textbox with
' the UpDown control's Value property.
txtLines.Text = Format(spnLines.Value, "0")
End Sub
Private Sub txtLines_Change()
'Make sure entry is a number, if not, beep and put in last value.
If Not IsNumeric(txtLines.Text) Then
Beep
txtLines.Text = Format(spnLines.Value, "0")
Cancel = True
Exit Sub
End If
'Check values are within accepted range, exit if not.
If Val(txtLines.Text) > spnLines.Max Or Val(txtLines.Text) < spnLines.Min Then
MsgBox "Number Of Lines Must Be Between 1 and 5"
Exit Sub
End If
spnLines.Value = Val(txtLines.Text)
Select Case CInt(txtLines.Text)
Case 1
RefEdit2.Enabled = False
RefEdit3.Enabled = False
RefEdit4.Enabled = False
RefEdit5.Enabled = False
lblLine2.Enabled = False
lblLine3.Enabled = False
lblLine4.Enabled = False
lblLine5.Enabled = False
Case 2
RefEdit2.Enabled = True
RefEdit3.Enabled = False
RefEdit4.Enabled = False
RefEdit5.Enabled = False
lblLine2.Enabled = True
lblLine3.Enabled = False
lblLine4.Enabled = False
lblLine5.Enabled = False
Case 3
RefEdit2.Enabled = True
RefEdit3.Enabled = True
RefEdit4.Enabled = False
RefEdit5.Enabled = False
lblLine2.Enabled = True
lblLine3.Enabled = True
lblLine4.Enabled = False
lblLine5.Enabled = False
Case 4
RefEdit2.Enabled = True
RefEdit3.Enabled = True
RefEdit4.Enabled = True
RefEdit5.Enabled = False
lblLine2.Enabled = True
lblLine3.Enabled = True
lblLine4.Enabled = True
lblLine5.Enabled = False
Case 5
RefEdit2.Enabled = True
RefEdit3.Enabled = True
RefEdit4.Enabled = True
RefEdit5.Enabled = True
lblLine2.Enabled = True
lblLine3.Enabled = True
lblLine4.Enabled = True
lblLine5.Enabled = True
End Select
End Sub
Private Sub txtLines_Enter()
' Start highlight before first character.
txtLines.SelStart = 0
' Highlight to end of text.
txtLines.SelLength = Len(txtLines.Text)
End Sub
I have a form with 5 RefEdit controls on it and 5 associated labels.
There is also a textbox with a spinbutton (UpDown control?)
which regulates how many of the RefEdit controls are enabled.
A control array would be better than this select case, but control
arrays aren't available in VBA.
How can I improve? :(
Private Sub spnLines_Change()
' Change the Value of the textbox with
' the UpDown control's Value property.
txtLines.Text = Format(spnLines.Value, "0")
End Sub
Private Sub txtLines_Change()
'Make sure entry is a number, if not, beep and put in last value.
If Not IsNumeric(txtLines.Text) Then
Beep
txtLines.Text = Format(spnLines.Value, "0")
Cancel = True
Exit Sub
End If
'Check values are within accepted range, exit if not.
If Val(txtLines.Text) > spnLines.Max Or Val(txtLines.Text) < spnLines.Min Then
MsgBox "Number Of Lines Must Be Between 1 and 5"
Exit Sub
End If
spnLines.Value = Val(txtLines.Text)
Select Case CInt(txtLines.Text)
Case 1
RefEdit2.Enabled = False
RefEdit3.Enabled = False
RefEdit4.Enabled = False
RefEdit5.Enabled = False
lblLine2.Enabled = False
lblLine3.Enabled = False
lblLine4.Enabled = False
lblLine5.Enabled = False
Case 2
RefEdit2.Enabled = True
RefEdit3.Enabled = False
RefEdit4.Enabled = False
RefEdit5.Enabled = False
lblLine2.Enabled = True
lblLine3.Enabled = False
lblLine4.Enabled = False
lblLine5.Enabled = False
Case 3
RefEdit2.Enabled = True
RefEdit3.Enabled = True
RefEdit4.Enabled = False
RefEdit5.Enabled = False
lblLine2.Enabled = True
lblLine3.Enabled = True
lblLine4.Enabled = False
lblLine5.Enabled = False
Case 4
RefEdit2.Enabled = True
RefEdit3.Enabled = True
RefEdit4.Enabled = True
RefEdit5.Enabled = False
lblLine2.Enabled = True
lblLine3.Enabled = True
lblLine4.Enabled = True
lblLine5.Enabled = False
Case 5
RefEdit2.Enabled = True
RefEdit3.Enabled = True
RefEdit4.Enabled = True
RefEdit5.Enabled = True
lblLine2.Enabled = True
lblLine3.Enabled = True
lblLine4.Enabled = True
lblLine5.Enabled = True
End Select
End Sub
Private Sub txtLines_Enter()
' Start highlight before first character.
txtLines.SelStart = 0
' Highlight to end of text.
txtLines.SelLength = Len(txtLines.Text)
End Sub