vb.net newbee needs help with data transfer from multiple forms

d0uga1

Member
Joined
Apr 13, 2005
Messages
5
Programming Experience
Beginner
i have seen a few messages regarding accessing multiple forms floating around but i cannot get it to work with my project i need it putting into laimans terms
(general background)

i am trying to write a small casino app, i have 5 user forms at the mo with others being added when i can think of new things. i have alot of code in my forms and dont want to stop and start over but i have come to a problem.

on my main form (titled StartPage) i have a form with no buttons just pictures and labels i have set it so that when each picture is clicked it opens the corresponding userform and hides the main form (startpage). one of the labels shows the players 'credit limit' on form 2 the 'BlackJack' form i have another label which i want to show the players current 'credit limit' and when the player goes back to the Lobby ( startpage) i need it to update the credit limit on that page aswell. i have been trying for several hours trying to get this working but to no avail.

Can you help?


i have deleted my previous attempts so basically i need to know from scratch.

my user forms are named
(form1) - StartPage
my labels are named - CurrentCredit
(form2) - Blackjack
my labels are named - credittext
a button named - Golobby <-- this returns player back to the startpage.

i need these labels to update on the formload event.

i hope i have not missed anything you need or boared you with my typehappy hands.

many thanks in advance and for your time.
 

Paszt

Staff member
Joined
Jun 3, 2004
Messages
1,500
Location
Raleigh, NC - USA
Programming Experience
Beginner
There are several ways to do this, all deal with getting a reference to the different forms; use a module with global variables, send references to the different forms, ...
This is a good article that explains these methods: Multiple Forms in VB.NET. Part 4 - Accessing Controls and Data ...

Also note that the formLoad event only occurs when the form loads. If you hide a form and then make it visible again via the Show method, the formLoad event doesn't get fired.
 

d0uga1

Member
Joined
Apr 13, 2005
Messages
5
Programming Experience
Beginner
thanks for the info but the link you posted i have not been able to get my head around thanks anyway
 

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,319
Location
Sydney, Australia
Programming Experience
10+
I would suggest using a module, as Paszt posted, with public variables or, preferably, private variables and public properties. Each form will be able to access the module's public properties to update the global values. They should update their labels in the Activated event handler rather than when loaded to avoid the problem Paszt mentioned.
 

d0uga1

Member
Joined
Apr 13, 2005
Messages
5
Programming Experience
Beginner
..

After several headaces and keyboard banging i finnally got my head around it and of course it was so easy (but as the saying goes its only easy if you know it)

all i did was create a module and changed it to say friend module as below..

Friend
Module Module1 ' This Is A Reference Module For All Objects Throughout The Whole Project.
Friend F1 As StartPage ' This shares The Start Page Throught Out The Whole Project.
Friend F2 As BlackJack ' This shares The Blackjack Page Throught Out The Whole Project.
Friend F3 As Roullette ' This shares The Roullette Page Throught Out The Whole Project.
Friend F4 As Slots ' This shares The Slots Page Throught Out The Whole Project.
End Module

well as easy as that

thanks for the help give guys
 

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,319
Location
Sydney, Australia
Programming Experience
10+
This approach will certainly work, but good programming practice dictates that you only expose as much of an object as is absolutely necessary. In my opinion, it would be better to declare in the module only the variables you need each form to be able to access, rather than the forms themselves.
 
Top Bottom