|
-
Aug 17th, 2001, 12:07 AM
#1
Thread Starter
New Member
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?
-
Aug 17th, 2001, 12:14 AM
#2
PowerPoster
commondialog1.cancelerror=True creates a trappable error when cancel is pressed
-
Aug 17th, 2001, 12:18 AM
#3
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
-
Aug 17th, 2001, 12:29 AM
#4
Thread Starter
New Member
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.
-
Aug 17th, 2001, 12:52 AM
#5
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|