473,320 Members | 1,987 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Passing variables to dialog boxes

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
1 5430
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: rettigcd | last post by:
Hello, I need to create a custome form that operates similar to the MsgBox() and InputBox() functions. I can't figure out how to pass data to a MODAL dialog box (form). I've tried 3...
10
by: Steve | last post by:
Can anyone recommend the best way to pass a string back to the calling class (windows form) from a dialog that was shown modally using ShowDialog?
23
by: George | last post by:
Is there a way to customize the open file common dialog? I am trying to modify the button text so I can create a delete file common dialog. I need the same functionality of the open file common...
11
by: Johnny | last post by:
I'm a rookie at C# and OO so please don't laugh! I have a form (fclsTaxCalculator) that contains a text box (tboxZipCode) containing a zip code. The user can enter a zip code in the text box and...
8
by: Johnny | last post by:
I'm a rookie at C# and OO so please don't laugh! I have a form (fclsTaxCalculator) that contains a text box (tboxZipCode) containing a zip code. The user can enter a zip code in the text box and...
1
by: Roy | last post by:
I'm assuming this is amazingly simple and I'm just missing the boat. On the html side of an asp.net page I have a datagrid, a "search" button, and 8 text boxes for search criteria. A user enters...
2
by: one.1more | last post by:
I want to make a text game using javascript dialog boxes. i learned about confirm boxes but its not helpful(http:// www.javascriptmall.com/learn/lesson6.htm) 1. for ex, in the confirm boxes,...
6
by: raylopez99 | last post by:
This thread is about how variables or parameters (including objects) are passed between forms (namely, using parameterized constructors, e.g., to pass an int between forms (e.g., a calling form and...
3
by: Mike Hofer | last post by:
Okay, here's the situation: we want to be able to display ASPX pages in an UpdatePanel. The reasons for this are performance related. The site in development uses *lots* of modal popups from some...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.