|
-
Jan 30th, 2004, 01:37 AM
#1
Thread Starter
Banned
Can this code be reduced?
VB Code:
Private Sub SetSingle(bEnabled As Boolean)
Dim iCtr As Integer
grdSingle.Enabled = bEnabled
If bEnabled = False Then
For iCtr = 0 To btnSingle.Count - 1
btnSingle(iCtr).Enabled = False
Next iCtr
Else
If iMode = enumEDIT_FILTER Or iMode = enumVIEW_FILTER Then
If FilterList.Filters(FilterList.Selected).GetSCCount = 0 Then
btnSingle(2).Enabled = True
btnSingle(1).Enabled = False
btnSingle(0).Enabled = False
ElseIf FilterList.Filters(FilterList.Selected).GetSCCount = 1 Then
btnSingle(0).Enabled = False
btnSingle(1).Enabled = True
btnSingle(2).Enabled = True
Else
btnSingle(2).Enabled = True
btnSingle(1).Enabled = True
btnSingle(0).Enabled = True
End If
Else
If grdSingle.Rows = 1 Then
btnSingle(2).Enabled = True
btnSingle(1).Enabled = False
btnSingle(0).Enabled = False
ElseIf grdSingle.Rows = 2 Then
btnSingle(0).Enabled = False
btnSingle(1).Enabled = True
btnSingle(2).Enabled = True
Else
btnSingle(2).Enabled = True
btnSingle(1).Enabled = True
btnSingle(0).Enabled = True
End If
End If
End If
End Sub
Last edited by debbie_82; Jan 30th, 2004 at 01:50 AM.
-
Jan 30th, 2004, 09:59 AM
#2
You could build lookup tables for matching the value against the minimum enabled control index, then use a single loop to enable them all.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Jan 30th, 2004, 12:25 PM
#3
based on part of what CornedBee said, you could do this:
VB Code:
Private Sub SetSingle(bEnabled As Boolean)
Dim iCtr As Integer
Dim iMinBtn As Integer
grdSingle.Enabled = bEnabled
If bEnabled = False Then
iMinBtn = btnSingle.Count
Else
If iMode = enumEDIT_FILTER Or iMode = enumVIEW_FILTER Then
If FilterList.Filters(FilterList.Selected).GetSCCount = 0 Then
iMinBtn = 2
ElseIf FilterList.Filters(FilterList.Selected).GetSCCount = 1 Then
iMinBtn = 1
Else
iMinBtn = 0
End If
Else
If grdSingle.Rows = 1 Then
iMinBtn = 2
ElseIf grdSingle.Rows = 2 Then
iMinBtn = 1
Else
iMinBtn = 0
End If
End If
End If
For iCtr = 0 To iMinBtn - 1
btnSingle(iCtr).Enabled = False
Next iCtr
For iCtr = iMinBtn To btnSingle.Count - 1
btnSingle(iCtr).Enabled = True
Next iCtr
End Sub
-
Feb 1st, 2004, 08:25 PM
#4
Thread Starter
Banned
Wow, just shows why I like programming.
I better practice more...
Thank you for some cool insights.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|