Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Computer Forums > Programmers Lounge > Programming Discussions » VB.NET Variables over multiple forms
Closed Thread
Old 10-17-2008, 03:48 PM   #1 (permalink)
murdocsvan's Avatar
 
Ultra Techie

Join Date: Jun 2007

Location: Surrey, UK

Posts: 849

murdocsvan is on a distinguished road

Default VB.NET Variables over multiple forms

Hi, for a college project im designing a simple game. I need to use a set of variables over multiple forms, which can be open and edited. Can anyone help?
__________________

murdocsvan is offline  
Old 10-17-2008, 08:45 PM   #2 (permalink)
Baez's Avatar
 

Join Date: Sep 2005

Location: Toronto, Canada

Posts: 5,466

Baez is a glorious beacon of lightBaez is a glorious beacon of lightBaez is a glorious beacon of lightBaez is a glorious beacon of lightBaez is a glorious beacon of light

Default Re: VB.NET Variables over multiple forms

You need to use what is called a View State or a Session State. Take a look at this for more information: MSDN Session State
__________________

Baez is offline  
Old 10-17-2008, 09:50 PM   #3 (permalink)
murdocsvan's Avatar
 
Ultra Techie

Join Date: Jun 2007

Location: Surrey, UK

Posts: 849

murdocsvan is on a distinguished road

Default Re: VB.NET Variables over multiple forms

Ahh, this doesn't work because its for ASP .NET, not Visual Basic .NET.

Still stuck with this one.
__________________

murdocsvan is offline  
Old 10-17-2008, 09:56 PM   #4 (permalink)
Baez's Avatar
 

Join Date: Sep 2005

Location: Toronto, Canada

Posts: 5,466

Baez is a glorious beacon of lightBaez is a glorious beacon of lightBaez is a glorious beacon of lightBaez is a glorious beacon of lightBaez is a glorious beacon of light

Default Re: VB.NET Variables over multiple forms

View State is available in VB.NET I believe. Session is an ASP function you're right. Didn't realize you were only working with VB.NET sorry.
__________________


Last edited by Baez; 10-17-2008 at 10:12 PM.
Baez is offline  
Old 10-18-2008, 03:01 PM   #5 (permalink)
murdocsvan's Avatar
 
Ultra Techie

Join Date: Jun 2007

Location: Surrey, UK

Posts: 849

murdocsvan is on a distinguished road

Default Re: VB.NET Variables over multiple forms

okay, but that article still doesnt make a lot of sense to me. what im asking is, how do i set global variables?
__________________

murdocsvan is offline  
Old 10-19-2008, 05:37 PM   #6 (permalink)
Baez's Avatar
 

Join Date: Sep 2005

Location: Toronto, Canada

Posts: 5,466

Baez is a glorious beacon of lightBaez is a glorious beacon of lightBaez is a glorious beacon of lightBaez is a glorious beacon of lightBaez is a glorious beacon of light

Default Re: VB.NET Variables over multiple forms

There are no global variables in VB so you need to use static variables.

Code:
Function updateSales(ByVal thisSale As Decimal) As Decimal
    Static totalSales As Decimal = 0
    totalSales += thisSale
    Return totalSales
End Function

' more code...

updateSales.totalSales = 2
Part of this code in on MSDN. I just added the end to show you how to use it after the procedure has terminated.
__________________

Baez is offline  
Old 10-21-2008, 06:20 AM   #7 (permalink)
murdocsvan's Avatar
 
Ultra Techie

Join Date: Jun 2007

Location: Surrey, UK

Posts: 849

murdocsvan is on a distinguished road

Default Re: VB.NET Variables over multiple forms

Actually, thanks for the advice cvb, but it turned out there are a form of global variables in Visual Basic .NET.

My solution was to add a basic module to the project, and then to add the variables to those. Then i access the data by referencing the module from any of the forms.

I don't know the syntax for referencing the data yet, but this is what i was told by my teacher.
__________________

murdocsvan is offline  
Old 10-21-2008, 12:44 PM   #8 (permalink)
Baez's Avatar
 

Join Date: Sep 2005

Location: Toronto, Canada

Posts: 5,466

Baez is a glorious beacon of lightBaez is a glorious beacon of lightBaez is a glorious beacon of lightBaez is a glorious beacon of lightBaez is a glorious beacon of light

Default Re: VB.NET Variables over multiple forms

Haha well the syntax is almost identical to what I just showed you. The difference is that I used a function. Mine is a little more secure. But I imagine you don't have to worry about security at this point.
__________________

Baez is offline  
 
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Vista & Multiple processors Lexluethar Windows Operating Systems and Software 4 08-06-2008 12:27 PM
Hosting multiple websites on a home network server Solutionit Web Site Hosting / ISP Q & A 10 04-13-2008 12:14 AM
I want to PRINT on forms that are in my printer automatic feeder... rocket1406 Windows Operating Systems and Software 3 08-06-2007 07:46 PM