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!

Question about a dialog box with true/false buttons?

Status
Not open for further replies.

bigdubbe

Programmer
May 26, 2006
11
US
I was wondering what the code would be if you wanted a true radio button to act like an ok button, and the false button to stop the macro.
 
Dialog boxes require at least one button. In order to have a cancel and an OK, I made two buttons. When the dialogbox loads (action = 1), these buttons are hidden with DlgVisible .id,0. This prevents the user for seeing or selecting those buttons.

Another issue, is an OptionGroup must have at least one radio selected. In order to correct this, I added a radio button that's 1x1. This will show as a little patch of darker gray on the dialogbox. When I tried making it invisible the OptionGroup stopped working correctly, so instead I just hid the little patch of gray behind the "Start" radio.

Now you just have to make the radios push a button once they're selected. By selecting a radio a value in the dialog changes (action = 2). Based on the value of the dialog box, I place focus on the corresponding button, and initiate a SendKey of a space (pushing the button).

Code:
Function FileDlgFunc(identifier$, action, suppvalue)
    Select Case action
    Case 1
        DlgVisible "Cancel",0
        DlgVisible "OK",0
    Case 2
        If DlgValue("OG1") = 1 Then
            DlgFocus "OK"
            SendKeys " "
        End If
        If DlgValue("OG1") = 2 Then
            DlgFocus "Cancel"
            SendKeys " "
        End If
    End Select
End Function

Sub Main
    Begin Dialog Dialog1 1,1, 100, 20, "DialogBox", .FileDlgFunc
    OptionGroup .OG1
         OptionButton 5, 5, 1, 1, "", .OB1
         OptionButton 5, 5, 40, 10, "Start", .OB2
         OptionButton 45, 5, 40, 10, "End", .OB3
         CancelButton 1,1,1,1,.Cancel
         PushButton 1,1,1,1,"",.OK
    End Dialog
    Dim MyDialog as Dialog1
    On Error Resume Next
    Dialog MyDialog
    If Err Then MsgBox "Cancel" Else MsgBox "OK"
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top