Passing variables to dialog boxes

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Prosonman

    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(Can cel As Integer)

    Select Case myLabelNumber

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

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

    Unload Dialog

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




  • Visual Basic Wizard

    #2
    Re: Passing variables to dialog boxes

    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
    visualbasicwiza rd@comcast.net

    "Prosonman" <prosonman@hotm ail.com> wrote in message
    news:c8ssau$suh $1@sparta.btint ernet.com...[color=blue]
    > 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[/color]
    Labels,[color=blue]
    > when a label is clicked it opens a dialog box with a text box in it and[/color]
    the[color=blue]
    > 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[/color]
    complicated[color=blue]
    > 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(Can cel As Integer)
    >
    > Select Case myLabelNumber
    >
    > Case 1
    > Form1.Label1.Ca ption = Text1
    > Case 2
    > Form1.Label2.Ca ption = Text1
    > Case 3
    > Form1.Label3.Ca ption = Text1
    > End Select
    >
    > End Sub
    > ---------------------------------------------------------------------
    > Private Sub OKButton_Click( )
    >
    > Unload Dialog
    >
    > End Sub
    > ---------------------------------------------------------------------
    >
    >
    >
    >[/color]


    Comment

    Working...