Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Make all checked boxes as default? 1

Status
Not open for further replies.

jackeroo75

Technical User
Aug 26, 2007
34
US
Hi,

How do I make it so all checked boxes in the dialog box are checked as default?


I checked the help to no avail.
 
Jackeroo, Post the code you'd like help with.

[thumbsup2] Wow, I'm having amnesia and deja vu at the same time.
I think I've forgotten this before.


 
Typed not tested, but should point you in the right direction.

Code:
Function dlgMyFunc(identifier$, action, suppvalue)
  Select Case action
  Case 1 'Dialogbox loaded
    dlgValue "chkA", 1
    dlgValue "chkB", 1
    dlgValue "chk1", 1
    dlgValue "chk2", 1
    dlgValue "chk3", 1
  Case 2 'Button clicked
  End Select
End Function

Sub Main
  Begin Dialog dlgJunk 80, 70, "MyDialog", .dlgMyFunc
    ButtonGroup .ButtonPressed
    OkButton 5, 40, 20, 12, .BtnOK
    Checkbox 5, 5, 20, 12, "A", .chkA
    Checkbox 30, 5, 20, 12, "B", .chkB
    Checkbox 5, 20, 20, 12, "1", .chk1
    Checkbox 30, 20, 20, 12, "2", .chk2
    Checkbox 55, 20, 20, 12, "3", .chk3
  End Dialog

  Dim dlgVar as dlgJunk
  On Error Resume Next
  Dialog dlgVar
End Sub
 
Hey Skie-

I'm having a bit of trouble in a new dilemma, I'm trying to create a push button to unselect all. I'm not sure how this is implemented using the dialog box.


Also, I'm a bit confuse in the function where the case resides. Why do you need CASE 2???

Jackeroo75
 
The dlgMyFunc = True is going to keep the dialogbox open even after a button is pushed. This looks a lot better and IMO is easier to code for than looping your dialog box.

When the user presses "OK" it does a dlgMyFunc = False. This will cause your dialog box to close. If you don't code a dlgMyFunc = False for the buttons that need to close the dialog box, you'll end up with a dialog box that you have to end task to close.

The following code is typed, not tested:
Code:
Function dlgMyFunc(identifier$, action, suppvalue)
  dlgMyFunc = True
  Select Case action
  Case 1 'Dialogbox loaded
    dlgValue "chkA", 1
    dlgValue "chkB", 1
    dlgValue "chk1", 1
    dlgValue "chk2", 1
    dlgValue "chk3", 1
  Case 2 'Button clicked
    Select Case indentifer$
    Case "BtnUnSel"
        dlgValue "chkA", 0
        dlgValue "chkB", 0
        dlgValue "chk1", 0
        dlgValue "chk2", 0
        dlgValue "chk3", 0
    Case "BtnOK"
        dlgMyFunc = False
    End Case
  End Select
End Function

Sub Main
  Begin Dialog dlgJunk 80, 70, "MyDialog", .dlgMyFunc
    OkButton 5, 40, 20, 12, .BtnOK
    Button 5, 5, 20, 12, "Unselect",.BtnUnSel
    Checkbox 5, 5, 20, 12, "A", .chkA
    Checkbox 30, 5, 20, 12, "B", .chkB
    Checkbox 5, 20, 20, 12, "1", .chk1
    Checkbox 30, 20, 20, 12, "2", .chk2
    Checkbox 55, 20, 20, 12, "3", .chk3
  End Dialog

  Dim dlgVar as dlgJunk
  On Error Resume Next
  Dialog dlgVar
End Sub
 
Logically, not working when I hit "OK" button because it would check everything when I hit ok. What I want is the user to be able to choose what they want. So if they choose 11 and 10 then hit ok. Only 2 would be check. But what's it is doing is checking everFunction dlgMyFunc(identifier$, action, suppvalue)
dlgMyFunc = True
setflag = 1
Select Case action
Case 1 'Dialogbox loaded
dlgValue "CkFloor11", setflag
dlgValue "CkFloor10", setflag
dlgValue "CkFloor09", setflag
dlgValue "CkFloor8M", setflag
dlgValue "CkFloor8Y", setflag
dlgValue "CkFloorInf", setflag
dlgValue "CkFloor04", setflag
dlgValue "CkFloor03", setflag
dlgValue "CkFloor02", setflag
Case 2

Select Case identifier$
Case "BtnUnSelectAll"
setflag =0
dlgValue "CkFloor11", setflag
dlgValue "CkFloor10", setflag
dlgValue "CkFloor09", setflag
dlgValue "CkFloor8M", setflag
dlgValue "CkFloor8Y", setflag
dlgValue "CkFloorInf", setflag
dlgValue "CkFloor04", setflag
dlgValue "CkFloor03", setflag
dlgValue "CkFloor02", setflag
Case "BtnSelectAll"
setflag =1
dlgValue "CkFloor11", setflag
dlgValue "CkFloor10", setflag
dlgValue "CkFloor09", setflag
dlgValue "CkFloor8M", setflag
dlgValue "CkFloor8Y", setflag
dlgValue "CkFloorInf", setflag
dlgValue "CkFloor04", setflag
dlgValue "CkFloor03", setflag
dlgValue "CkFloor02", setflag
Case "BtnOK"
dlgMyFunc = False

End Select


End Select
End Functionything first.
 
This selects all and unselects all, and the user can also individually check or uncheck them.

dlgValue "checkbox", 1 = Checked
dlgValue "checkbox", 0 = Unchecked
dlgValue "checkbox", -1 = Gray

If you don't want everything to start off checked, you can remove everything that's in Case 1 (these only run when you first load the dialogbox).

When they click OK, it shouldn't change any of the values of the boxes.

Code:
Function dlgMyFunc(identifier$, action, suppvalue)
  dlgMyFunc = True
  Select Case action
  Case 1 'Dialogbox loaded
    dlgValue "chkA", 1
    dlgValue "chkB", 1
    dlgValue "chk1", 1
    dlgValue "chk2", 1
    dlgValue "chk3", 1
  Case 2 'Button clicked or value changed
    Select Case identifier
    Case "btnUnSel","btnSelAll"
        If identifier = "btnUnSel" Then
           iValue = 0
        Else
           iValue = 1
        End If
        dlgValue "chkA", iValue
        dlgValue "chkB", iValue
        dlgValue "chk1", iValue
        dlgValue "chk2", iValue
        dlgValue "chk3", iValue
    Case "btnOK"
        dlgMyFunc = False
    End Select
  End Select
End Function

Sub Main
  Begin Dialog dlgJunk 80, 70, "MyDialog", .dlgMyFunc
    OkButton 5, 40, 20, 12, .btnOK
    Button 30, 40, 20, 12, "UnSel", .btnUnSel
    Button 55, 40, 20, 12, "SelAll", .btnSelAll
    Checkbox 5, 5, 20, 12, "A", .chkA
    Checkbox 30, 5, 20, 12, "B", .chkB
    Checkbox 5, 20, 20, 12, "1", .chk1
    Checkbox 30, 20, 20, 12, "2", .chk2
    Checkbox 55, 20, 20, 12, "3", .chk3
  End Dialog

  Dim dlgVar as dlgJunk
  On Error Resume Next
  Dialog dlgVar
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top