moving data between forms using module

mcfly

Well-known member
Joined
Jun 15, 2009
Messages
54
Programming Experience
Beginner
this will probably be simple to answer for the right person, I have a form and I need to pass data to another form, I have decided to use a module to store the data I want to pass, here's what code resides on the first form:

VB.NET:
Private Sub CreateNewEventOrAppointmentToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CreateNewEventOrAppointmentToolStripMenuItem.Click
        Dim person_id As String
        Dim calendar_id As String

        person_id = TextBox6.Text

        calendar_id = TextBox3.Text

        get_person_id() = person_id

        get_calendar_id() = calendar_id

        frmEvent.Show()
        Me.Hide()
    End Sub

All I want to do is call a procedure and the data be sent to themodule, and the data to be stored for when I next need it on the second form, here's what i have but doesn't seem to work:


VB.NET:
Module Module1

    Private Sub get_person_id(ByVal person_id As String)

    End Sub

    Private Sub get_calendar_id(ByVal calendar_id As String)

    End Sub

End Module

As you can tell I am very new to vb.net, but I am hopefully on the right lines and somebody will understand what I mean and can help further.

Also as a side note is this a good way to move data between forms????
 
hiya i have now done that, but it still has a error on this line:


VB.NET:
        [COLOR="Red"]get_person_id() [/COLOR]= person_id

        [COLOR="red"]get_calendar_id() [/COLOR]= calendar_id

Says 'Argument not specified for parameter 'person_id of 'Public Sub get_perso(person_id As String)

What ever that means....:confused:
 
No equals sign. get_person_id is the name of the sub and person_id is the parameter you are passing it. person_id doesn't equal anything
VB.NET:
get_person_id(person_id)
 
i done it at last - so simple when u know how:

VB.NET:

Private Sub CreateNewEventOrAppointmentToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CreateNewEventOrAppointmentToolStripMenuItem.Click
Dim person_id As String
Dim calendar_id As String

person_id = TextBox6.Text

calendar_id = TextBox3.Text

get_person_id(person_id)

get_calendar_id(calendar_id)

frmEvent.Show()
Me.Hide()
End Sub

VB.NET:
Module Module1

    Public Sub get_person_id(ByVal person_id As String)
        MsgBox("Your variable" & person_id)
    End Sub

    Public Sub get_calendar_id(ByVal calendar_id As String)
        MsgBox("Your variable" & calendar_id)
    End Sub

End Module
 
The data isn't really stored. Each time you call it, you pass it what you want person_id to be.

It can be the same thing each time...it could be something different on each form every time you run it.
 
ok, i understand a bit more...

so i have manage to get the data from my form1 to my module, now i need to read this data from another form...suppose it acts as a tempory place holder i think:

heres the code i have on form2:

VB.NET:
    Public Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        Dim person_id As String
        Dim calendar_id As String

        Call set_person_id(person_id)
        Call set_calendar_id(calendar_id)

        MsgBox("Your variable " & person_id)
        MsgBox("Your variable " & calendar_id)
    End Sub

heres the module


VB.NET:
Module Module1

    Public Sub get_person_id(ByVal person_id As String)

    End Sub

    Public Sub get_calendar_id(ByVal calendar_id As String)

    End Sub

    Public Sub set_person_id(ByVal person_id)
        Return
    End Sub

    Public Sub set_calendar_id(ByVal calendar_id)
        Return
    End Sub

End Module

I am going slightly wrong within my code for calling the data?? But am not sure where...???:(
 
I think we can simplify things by getting rid of the sub routines, and simply using public variables
VB.NET:
Module Module1

Public person_id As String
Public calendar_id As String

End Module

'from somewhere on some form
person_id = "mcfly"

'from somewhere else on any other form in your entire project
Messagebox.Show(person_id)
Same same with calendar_id
 
Back
Top