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!

Cancel button not working

Status
Not open for further replies.

DemBones79

Programmer
Jun 12, 2008
7
US
I have inherited several macros from my predecessors. One in particular is giving me a hard time. It never had a cancel button before, only an OK. I've tried coding one in and it appears just fine, but it doesn't actually do anything. I'm afraid I don't understand the rest of the code well enough to figure it out. If anyone can help, I'd sure appreciate it.

Code:
Function dlgFNRFunc(identifier$, action, suppvalue)
  dlgFNRFunc = True
  Select Case action
  Case 2
    Select Case identifier$
    Case "BtnOK"
      If dlgValue("cbxHome") = 1 Then dlgFNRFunc = False
      If dlgValue("cbxAlt1") = 1 Then dlgFNRFunc = False
      If dlgValue("cbxAlt2") = 1 Then dlgFNRFunc = False
    End Select
  End Select
End Function

   
    Begin Dialog dlgFNR 140, 120, "FNR Attempt Dialog Box", .dlgFNRFunc
        ButtonGroup .ButtonPressed
        OkButton  7, 89, 53, 14, .BtnOK
        CancelButton  67, 88, 50, 14
        GroupBox 10, 10, 100, 70, "Attempted To Call"
        CheckBox 15, 20, 91, 12, "Home Phone", .cbxHome
        CheckBox 15, 35, 91, 12, "Alt1 Phone", .cbxAlt1
        CheckBox 15, 50, 91, 12, "Alt2 Phone", .cbxAlt2
    End Dialog
    
    
    Dim dlgVar As dlgFNR
    On Error Resume Next
    nRet = Dialog(dlgVar)
    
    attempt_home = dlgVar.cbxHome
    attempt_alt1 = dlgVar.cbxAlt1
    attempt_alt2 = dlgVar.cbxAlt2
 
Code:
Function dlgFNRFunc(identifier$, action, suppvalue)
  dlgFNRFunc = True
  Select Case action
  Case 2
    Select Case identifier$
    Case "BtnOK"
      If dlgValue("cbxHome") = 1 Then dlgFNRFunc = False
      If dlgValue("cbxAlt1") = 1 Then dlgFNRFunc = False
      If dlgValue("cbxAlt2") = 1 Then dlgFNRFunc = False
    [COLOR=red]Case "BtnCNCL"
      'Do cancel stuff here[/color]
    End Select
  End Select
End Function

    Begin Dialog dlgFNR 140, 120, "FNR Attempt Dialog Box", .dlgFNRFunc
        ButtonGroup .ButtonPressed
        OkButton  7, 89, 53, 14, .BtnOK
        CancelButton  67, 88, 50, 14 [COLOR=red].BtnCNCL[/color]
        GroupBox 10, 10, 100, 70, "Attempted To Call"
        CheckBox 15, 20, 91, 12, "Home Phone", .cbxHome
        CheckBox 15, 35, 91, 12, "Alt1 Phone", .cbxAlt1
        CheckBox 15, 50, 91, 12, "Alt2 Phone", .cbxAlt2
    End Dialog
    
    
    Dim dlgVar As dlgFNR
    On Error Resume Next
    nRet = Dialog(dlgVar)
    
    attempt_home = dlgVar.cbxHome
    attempt_alt1 = dlgVar.cbxAlt1
    attempt_alt2 = dlgVar.cbxAlt2

[small]Sometimes you gotta leave your zone of safety. You have to manufacture Inspirado. You gotta get out of the apartment. You've got to run with the wolves. You've got to dive into the ocean and fight with the sharks. Or just treat yourself to a delicious hot fudge sundae........ with nuts. - Jack Black[/small]
 
Thanks for the reply, but I had tried something similar before and just tried your code as well, but I get a compile error "Syntax Error" on the
Code:
CancelButton  67, 88, 50, 14 .BtnCNCL
line.

Is there something else I need to do? Syntax Error is awfully unhelpful, but since the only thing that changed on that line was the .BtnCNCL, that is the only thing to which I think it can be referring.
 
Sorry the cancel button has a default identifier. Try

Code:
Function dlgFNRFunc(identifier$, action, suppvalue)
  dlgFNRFunc = True
  Select Case action
  Case 2
    Select Case identifier$
    Case "BtnOK"
      If dlgValue("cbxHome") = 1 Then dlgFNRFunc = False
      If dlgValue("cbxAlt1") = 1 Then dlgFNRFunc = False
      If dlgValue("cbxAlt2") = 1 Then dlgFNRFunc = False
    Case "Cancel"
      msgbox "cancel pressed"
    End Select
  End Select
End Function

   Begin Dialog dlgFNR 140, 120, "FNR Attempt Dialog Box", .dlgFNRFunc
        ButtonGroup .ButtonPressed
        OkButton  7, 89, 53, 14, .BtnOK
        CancelButton  67, 88, 50, 14 
        GroupBox 10, 10, 100, 70, "Attempted To Call"
        CheckBox 15, 20, 91, 12, "Home Phone", .cbxHome
        CheckBox 15, 35, 91, 12, "Alt1 Phone", .cbxAlt1
        CheckBox 15, 50, 91, 12, "Alt2 Phone", .cbxAlt2
    End Dialog
    
    
    Dim dlgVar As dlgFNR
    On Error Resume Next
    nRet = Dialog(dlgVar)
    
    attempt_home = dlgVar.cbxHome
    attempt_alt1 = dlgVar.cbxAlt1
    attempt_alt2 = dlgVar.cbxAlt2

end sub

[small]Sometimes you gotta leave your zone of safety. You have to manufacture Inspirado. You gotta get out of the apartment. You've got to run with the wolves. You've got to dive into the ocean and fight with the sharks. Or just treat yourself to a delicious hot fudge sundae........ with nuts. - Jack Black[/small]
 
Odd that the OK button allows a user defined identifier as well as works with an identifier of "OK". I guess it has to do with the cancel button also handling the 'X' pressed.

[small]Sometimes you gotta leave your zone of safety. You have to manufacture Inspirado. You gotta get out of the apartment. You've got to run with the wolves. You've got to dive into the ocean and fight with the sharks. Or just treat yourself to a delicious hot fudge sundae........ with nuts. - Jack Black[/small]
 
Thanks again for your help, but unfortunately it didn't work. I was no longer getting a syntax error, but the dialog still wouldn't close. I played around with a few things and what I finally came up with was this:
Code:
Function dlgFNRFunc(identifier$, action, suppvalue)
  dlgFNRFunc = True
  Select Case action
  Case 2
    Select Case identifier$
    Case "BtnOK"
      If dlgValue("cbxHome") = 1 Then dlgFNRFunc = False
      If dlgValue("cbxAlt1") = 1 Then dlgFNRFunc = False
      If dlgValue("cbxAlt2") = 1 Then dlgFNRFunc = False
    Case "Cancel"
      [COLOR=red]dlgFNRFunc = False[/color red]
    End Select
  End Select
End Function

The important part was that "dlgFNRFunc = False". Without that, the dialog would stay up indefinitely. Once that was inserted, it now exits properly. Thanks again for all your help. Your advice regarding the Case "Cancel" was spot on.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top