By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,979 Members | 943 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,979 IT Pros & Developers. It's quick & easy.

Passing variables to dialog boxes

P: n/a
Hi,
What is the best way to transfer variables to and from a dialog box? My
project consists of a form with a number of controls, lets say three Labels,
when a label is clicked it opens a dialog box with a text box in it and the
text box data will be returned to the label that was clicked. Don't laugh
but this is the code I use, it's OK for three controls but gets complicated
when using alot of controls and although it works I think its not the best
way. Any advice greatly appreciated.

Many thanks
Richard.

General Declarations:
---------------------------------------------------------------------
Public myLabel1 As String
Public myLabel2 As String
Public myLabel3 As String
Public myLabelNumber As Integer
---------------------------------------------------------------------

Form1 Events:
---------------------------------------------------------------------
Private Sub Label1_Click()
myLabelNumber = 1
Dialog.Show
End Sub
---------------------------------------------------------------------
Private Sub Label2_Click()
myLabelNumber = 2
Dialog.Show
End Sub
---------------------------------------------------------------------
Private Sub Label3_Click()
myLabelNumber = 3
Dialog.Show
End Sub
---------------------------------------------------------------------

Dialog Events:
---------------------------------------------------------------------
Private Sub Form_Unload(Cancel As Integer)

Select Case myLabelNumber

Case 1
Form1.Label1.Caption = Text1
Case 2
Form1.Label2.Caption = Text1
Case 3
Form1.Label3.Caption = Text1
End Select

End Sub
---------------------------------------------------------------------
Private Sub OKButton_Click()

Unload Dialog

End Sub
---------------------------------------------------------------------


Jul 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Best thing to do is to create a property on the form that sets/retrieves
the text from the textbox. You can feed the property the value before you
call the dialog and then read it back after calling it.

-------------------------------------------------------------
[Dialog]
Public Property Get Value() As String

Value = Text1.Text

End Property

Public Property Let Value(Data As String)

Text1.Text = Data

End Property

[Form1]
Private Sub Label1_Click

Dialog.Value = Label1.Text
Dialog.Show vbModal
Label1.Caption=Dialog.Value

End Sub

(etc.)

--
Said the option button to the window: "I've been framed!"

Dan Rushe
vi***************@comcast.net

"Prosonman" <pr*******@hotmail.com> wrote in message
news:c8**********@sparta.btinternet.com...
Hi,
What is the best way to transfer variables to and from a dialog box? My
project consists of a form with a number of controls, lets say three Labels, when a label is clicked it opens a dialog box with a text box in it and the text box data will be returned to the label that was clicked. Don't laugh
but this is the code I use, it's OK for three controls but gets complicated when using alot of controls and although it works I think its not the best
way. Any advice greatly appreciated.

Many thanks
Richard.

General Declarations:
---------------------------------------------------------------------
Public myLabel1 As String
Public myLabel2 As String
Public myLabel3 As String
Public myLabelNumber As Integer
---------------------------------------------------------------------

Form1 Events:
---------------------------------------------------------------------
Private Sub Label1_Click()
myLabelNumber = 1
Dialog.Show
End Sub
---------------------------------------------------------------------
Private Sub Label2_Click()
myLabelNumber = 2
Dialog.Show
End Sub
---------------------------------------------------------------------
Private Sub Label3_Click()
myLabelNumber = 3
Dialog.Show
End Sub
---------------------------------------------------------------------

Dialog Events:
---------------------------------------------------------------------
Private Sub Form_Unload(Cancel As Integer)

Select Case myLabelNumber

Case 1
Form1.Label1.Caption = Text1
Case 2
Form1.Label2.Caption = Text1
Case 3
Form1.Label3.Caption = Text1
End Select

End Sub
---------------------------------------------------------------------
Private Sub OKButton_Click()

Unload Dialog

End Sub
---------------------------------------------------------------------

Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.