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?
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?
commondialog1.cancelerror=True creates a trappable error when cancel is pressed
Do you mean Msgbox?
VB Code:
dim resp resp=Msgbox("I created this Dialog!",vbOKCancel,"Mine") If resp=vbOk then Msgbox "You clicked Ok" else Msgbox "you clicked Cancel" end if
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.
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:
Public Sub CommandOk_Click() If text1.text="" then msgbox "Please enter something" else 'put code to do something with the data then exit unload me end if