Results 1 to 15 of 15

Thread: Variables

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2000
    Location
    Atlanta, GA, USA
    Posts
    9

    Post

    I have 2 forms: FormA and FormB.
    FormB contains a calendar and an OK button. FormB contains
    a text box. When user choose a day from the calendar, and
    click OK, I need the date from the calendar to be displayed in formB's text box. Do I have to declare a variable in a
    module (to make it global) to handle that? other suggestion??

    Thanks

  2. #2
    Frenzied Member Buzby's Avatar
    Join Date
    Jan 1999
    Location
    UK
    Posts
    1,670

    Post

    To refer to a control on another form just use the form name and a . before the control name;

    eg;

    FormName.TextBox1.Text = "Hello"

    so, in your example, the FormA button click event should be;

    Sub CommandButton1_Click
    FormB.TextBox1.Text = Calendar1.Value
    End Sub

    I've never used the calendar control so I'm not convinced .Value is the right property - if it isn't just change it to the appropriate property to retrieve the date.
    'Buzby'
    Visual Basic Developer
    "I'm moving to Theory. Everything works there."

  3. #3
    Frenzied Member Buzby's Avatar
    Join Date
    Jan 1999
    Location
    UK
    Posts
    1,670

    Post

    To refer to a control on another form just use the form name and a . before the control name;

    eg;

    FormName.TextBox1.Text = "Hello"

    so, in your example, the FormA button click event should be;

    Sub CommandButton1_Click
    FormB.TextBox1.Text = Calendar1.Value
    End Sub

    I've never used the calendar control so I'm not convinced .Value is the right property - if it isn't just change it to the appropriate property to retrieve the date.
    'Buzby'
    Visual Basic Developer
    "I'm moving to Theory. Everything works there."

  4. #4
    Frenzied Member Buzby's Avatar
    Join Date
    Jan 1999
    Location
    UK
    Posts
    1,670

    Post

    To refer to a control on another form just use the form name and a . before the control name;

    eg;

    FormName.TextBox1.Text = "Hello"

    so, in your example, the FormA button click event should be;

    Sub CommandButton1_Click
    FormB.TextBox1.Text = Calendar1.Value
    End Sub

    I've never used the calendar control so I'm not convinced .Value is the right property - if it isn't just change it to the appropriate property to retrieve the date.
    'Buzby'
    Visual Basic Developer
    "I'm moving to Theory. Everything works there."

  5. #5
    Frenzied Member Buzby's Avatar
    Join Date
    Jan 1999
    Location
    UK
    Posts
    1,670

    Post

    To refer to a control on another form just use the form name and a . before the control name;

    eg;

    FormName.TextBox1.Text = "Hello"

    so, in your example, the FormA button click event should be;

    Sub CommandButton1_Click
    FormB.TextBox1.Text = Calendar1.Value
    End Sub

    I've never used the calendar control so I'm not convinced .Value is the right property - if it isn't just change it to the appropriate property to retrieve the date.
    'Buzby'
    Visual Basic Developer
    "I'm moving to Theory. Everything works there."

  6. #6
    New Member
    Join Date
    Mar 2000
    Location
    Hull, PQ, Canada
    Posts
    7

    Post It's easier than you think

    From your question, it seems that all you need to do is to call your FormB as your parent object. Let me give you an example:

    On FormA:


    private sub Command1_Click

    FormB.Text1.text = "Hello World!"

    end sub


    It's as easy as that.

    How this helps

    JFDman

  7. #7
    Hyperactive Member
    Join Date
    Jun 1999
    Location
    Calgary Alberta
    Posts
    359

    Post

    Buzb is right (all 4 times :-)), the .VALUE property is the correct one to reference. But instead of using:

    Code:
    Sub CommandButton1_Click 
    FormB.TextBox1.Text = Calendar1.Value 
    End Sub
    it's better to use:

    Code:
    Sub CommandButton1_Click 
    FormB!TextBox1.Text = Calendar1.Value 
    End Sub
    If I remember correctly, the ! tells it that it is a control. the . can also be used to reference Variables. I can't remember who told me that though :-)

    Buzby - you hit the SUBMIT button too many times didn't you? :-)


    Edited by netSurfer on 03-10-2000 at 08:51 AM

  8. #8

    Thread Starter
    New Member
    Join Date
    Mar 2000
    Location
    Atlanta, GA, USA
    Posts
    9

    Post Variable

    That is what I needed, thanks


    From your question, it seems that all you need to do is to call your FormB as your parent object. Let me give you an example:

    On FormA:


    private sub Command1_Click

    FormB.Text1.text = "Hello World!"

    end sub


    It's as easy as that.

    How this helps

    JFDman

  9. #9

    Thread Starter
    New Member
    Join Date
    Mar 2000
    Location
    Atlanta, GA, USA
    Posts
    9

    Post Variable

    That is what I needed, thanks


    To refer to a control on another form just use the form name and a . before the control name;

    eg;

    FormName.TextBox1.Text = "Hello"

    so, in your example, the FormA button click event should be;

    Sub CommandButton1_Click
    FormB.TextBox1.Text = Calendar1.Value
    End Sub

    I've never used the calendar control so I'm not convinced .Value is the right property - if it isn't just change it to the appropriate property to retrieve the date.


  10. #10
    Frenzied Member Buzby's Avatar
    Join Date
    Jan 1999
    Location
    UK
    Posts
    1,670

    Post

    To refer to a control in another form use the form's name before the control name (seperated with a .)

    eg;

    FormName.TextBox1.Text = "hello"

    in your example - although I have never used the calendar control so .Value may not be the right property;

    Private Sub CommandButton1_Click
    FormB.TextBox1.Text = Calendar1.Value
    End Sub

    'Buzby'
    Visual Basic Developer
    "I'm moving to Theory. Everything works there."

  11. #11
    Frenzied Member Buzby's Avatar
    Join Date
    Jan 1999
    Location
    UK
    Posts
    1,670

    Post

    To refer to a control in another form use the form's name before the control name (seperated with a .)

    eg;

    FormName.TextBox1.Text = "hello"

    in your example - although I have never used the calendar control so .Value may not be the right property;

    Private Sub CommandButton1_Click
    FormB.TextBox1.Text = Calendar1.Value
    End Sub

    'Buzby'
    Visual Basic Developer
    "I'm moving to Theory. Everything works there."

  12. #12
    Frenzied Member Buzby's Avatar
    Join Date
    Jan 1999
    Location
    UK
    Posts
    1,670

    Post

    To refer to a control in another form use the form's name before the control name (seperated with a .)

    eg;

    FormName.TextBox1.Text = "hello"

    in your example - although I have never used the calendar control so .Value may not be the right property;

    Private Sub CommandButton1_Click
    FormB.TextBox1.Text = Calendar1.Value
    End Sub

    'Buzby'
    Visual Basic Developer
    "I'm moving to Theory. Everything works there."

  13. #13
    Frenzied Member Buzby's Avatar
    Join Date
    Jan 1999
    Location
    UK
    Posts
    1,670

    Post

    What the hell is going on.. I did indeed hit the submit button a few times but the message never appeared on the bulletin board so I did that old 'user-favourite' of trying again.. and whaddya know - suddenly they all appeared.
    Sorry...

    'Buzby'
    Visual Basic Developer
    "I'm moving to Theory. Everything works there."

  14. #14
    Hyperactive Member
    Join Date
    Jun 1999
    Location
    Calgary Alberta
    Posts
    359

    Post

    that's ok Mark - we forgive you. After all it's friday! :-)

  15. #15
    Fanatic Member
    Join Date
    Jan 2000
    Location
    Mobile, AL, USA
    Posts
    600

    Post

    Buzby,

    You know that you can delete those extra posts if you want, don't you?

    All the best.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width