Results 1 to 5 of 5

Thread: Created a dialog box... how do I tell which button is pressed?

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2001
    Posts
    9

    Created a dialog box... how do I tell which button is pressed?

    I created a dialog box with an Ok and Cancel button. How do I tell which button is pressed?
    Also, I noticed that VB allows:

    If Form1.Command1 Then

    or

    If Not(Form1.Command1) Then

    What does it mean when Form1.Command1 is true or false?

  2. #2
    PowerPoster
    Join Date
    Feb 2001
    Location
    Crossroads
    Posts
    3,046
    commondialog1.cancelerror=True creates a trappable error when cancel is pressed

  3. #3
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Do you mean Msgbox?

    VB Code:
    1. dim resp
    2. resp=Msgbox("I created this Dialog!",vbOKCancel,"Mine")
    3. If resp=vbOk then
    4.    Msgbox "You clicked Ok"
    5. else
    6.    Msgbox "you clicked Cancel"
    7. end if

  4. #4

    Thread Starter
    New Member
    Join Date
    Mar 2001
    Posts
    9
    Sorry about the confusion. I meant that I created my own dialog box by creating a new form and adding buttons. I'm not sure if these are referred to as "dialog boxes" in VB. In VC++ (MFC), I can create a new form and it essentially becomes a dialog box. The functions and button presses are accessed in pretty much the same way as an msgbox or inputbox in VB (after the dialog box is closed).

    I created a new form (frmAdd) and added two text boxes and two buttons: OK and Cancel. How would I know if the user presses Cancel or OK? I'd like to retrieve the information from the textboxes only if the user presses OK. I basically want to access frmAdd as if it was a dialog box. Thanks.

    EDIT: I just realized that I could use the OK and Cancel buttons to retrieve or to not retrieve that data. This technique, however, doesn't seem very good. I'd still like to know how to access my frmAdd like it was a dialog box.
    Last edited by igowerf; Aug 17th, 2001 at 12:34 AM.

  5. #5
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    VB kind of has a different concept all the controls raise events when actions are performed so when a user types in the textbox in frmAdd it fires the GotFocus event (TextBox_GotFocus) when its selected and the Change, KeyPress events are fired as the user types. Likewise when the button is clicked it fires the Clicked event. You can write code in these events to respond. So you could put your code like:
    VB Code:
    1. Public Sub CommandOk_Click()
    2. If text1.text="" then
    3.   msgbox "Please enter something"
    4. else
    5. 'put code to do something with the data then exit
    6. unload me
    7. end if

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width