Passing label.text value to another form

Hi Experts,

I need to be able to pass a label.text value that is derived as follows to another form.

        Incident_ID.Text = "IN-" & CStr("T588") & "-" & Month(Now) & Year(Now) & "-" & Minute(Now) & Second(Now)

Using this method, I can create a unique string of characters for each record entered.  How can I pass this unique string of characters to another form, so that when additional information is completed on the second form all the data relates properly in the database?  Your time and assistance is appreciated.

I am developing in VB2005 using SQL 2005.
NCSOAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Carl TawnSystems and Integration DeveloperCommented:
Several options:

1) Make the label public and access it directly through the form.
2) Add a property to your form to return the value rather than making the Label public.
3) Have a method on your second form that your first form can call, passing the value of the label.
4) Store the value globally where it can be accessed from both form.
0
NCSOAuthor Commented:
Which of the (4) is most preferred?  
0
Carl TawnSystems and Integration DeveloperCommented:
Personally I would probably go with 3).

Basically because I assume that Form1 opens Form2. If thats the case then Form1 can call the method of Form2 immediatley after creating it. Secondly, the Label remains private to the form it belongs to, so theres no chance of any rogue element altering it. And thirdly, it prevents Form2 having to know anything about the form that created it.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

NCSOAuthor Commented:
Could you give me some code example for doing (3), I tried something similar to it yesterday and I was not successful.  Thanx
0
Carl TawnSystems and Integration DeveloperCommented:
Haven't got time to test this, but it should be something like:

Form 2:

    Public Sub SetLabel(ByVal pString As String)
        '// Do whatever you need to do with the value
    End Sub

Form 1:

    '// Assume this is in an event handler

    Dim f As New Form2()
    f.Show()
    f.SetLabel(Me.Label1.Text)
0
Mike TomlinsonMiddle School Assistant TeacherCommented:
carl_tawn has given a great answer already...

You said:

    "I am developing in VB2005"

This works in VB.Net 2005, but NOT in earlier versions of VB.Net.

If you are using only ONE instance of Form2 at any given time, then you can use the old VB6 style syntax to reference the Form using JUST the Forms name.   You don't need to create an instance of it.  Just declare a Public variable in Form2 and set it from Form1 before showing it:

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Form2.someValue = "IN-" & CStr("T588") & "-" & Month(Now) & Year(Now) & "-" & Minute(Now) & Second(Now)
        Form2.Show()
    End Sub

End Class


Public Class Form2

    Public someValue As String

    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Label1.Text = someValue
    End Sub

End Class
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.