Link to home
Create AccountLog in
Avatar of keith1001
keith1001Flag for United States of America

asked on

Visual Basic - Passing Variables between forms

I have the following code but it wont pass the variables:

First form:
Public Class vin_input
    Public myVIN As String
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        vehicle_info.Show()
        myVIN = txtVIN.Text 'get value of this text box
        Me.Hide()

    End Sub

    Private Sub vin_input_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub
End Class

Open in new window



Form2
Private Sub vehicle_info_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim getVin As String
        getVin = vin_input.myVIN

Open in new window


getVin is always nothing.
Avatar of Hawkvalley1
Hawkvalley1
Flag of United States of America image

Make a Public variable on the vehicle form and when you create it you set this field.

' from first form
Dim vi As New vehicle_info
vi.GetVin = myVin
vi.Show

Open in new window

Avatar of keith1001

ASKER

Ok form1 above is:  vin-input
and form2  is: vehicle-info

I'm confused on where do I put the code you did?

What code goes on vin-input form (form #1)?

Then what code goes on vehicle-info (form #2) to get variable myVin and assign to getVin?
SOLUTION
Avatar of Shahan Ayyub
Shahan Ayyub
Flag of Pakistan image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
ASKER CERTIFIED SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account