473,326 Members | 2,023 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

VB 6.0 - using variables in multiple forms in a program

Hello, this is my first time posting here. I am teaching an introductory programming course, but I have one student who is very advanced and needs to be challenged. I am using VB 6.0, and what I want to do is:
-Have user input a number in a textbox in Form1
-Have the program assign that number to a variable named Special (eg.Special = val(txtText1.Text)
-Have the value of Special useable in Form2 (eg. in Text2, Extra = Special + 10), where the value of Special was input in Form1.

How/where do I define/declare Special so that I can use its value in both forms?

I hope I am explaining myself clearly! Thanks in advance.

S
Feb 20 '07 #1
2 5724
dorinbogdan
839 Expert 512MB
1. You can define the g_lngSpecial variable in a Module, as public
Expand|Select|Wrap|Line Numbers
  1. Public g_lngSpecial as Long
it will be accessible in all project

2. You can declare in Form1 at General section level:
Expand|Select|Wrap|Line Numbers
  1. Public Special as Long 
- then access it from Form2 as: Form1.Special
- this method is not safe, because any code (from other forms/modules/classes) can modify the variable.

3. You can declare a property in Form1:
Expand|Select|Wrap|Line Numbers
  1. Private m_lngSpecial as Long
  2. Public Property Get Special() as Long
  3.    Special = m_lngSpecial
  4. End Property
- use m_lngSpecial in Form1 when get inputbox value
- then access it from Form2 as: Form1.Special
- the value cannot be modified from other forms/modules/classes, unless you define the Let Property in Form1:
Expand|Select|Wrap|Line Numbers
  1. Public Property Let Special(value as Long) 
  2.    m_lngSpecial = value
  3. End Property
The last method (3) is the best one.
Feb 20 '07 #2
Thank you! I really appreciate your reply.

S
Feb 20 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Mike MacSween | last post by:
It's a form, with (so far) 4 tab pages on it, each of which holds 2/3/4 subforms. (I like tabbed forms by the way - do we all?) Basically the subforms are different ways of looking at the...
25
by: John Hanley | last post by:
I have a program where both my main.c and program.c files use the program.h file. So I #include "program.h" in both the .c files. The program.h file has #ifndef PROGRAM_H #define PROGRAM_H...
1
by: Alasdair | last post by:
Friends, I'm an old C programmer who upgraded to C++ but was never comfortable with it. I've recently moved to C# and love it but I obviously am missing some of the subtleties. I thought the...
2
by: David McCormack | last post by:
I have a small project that I'm writing to help me learn C# and the .Net Framework. This project is a WinForms program with multiple forms that accesses MSDE. I've got most of it done but I've hit...
15
by: Joe Fallon | last post by:
I would like to know how you can figure out how much memory a given instance of a class is using. For example, if I load a collection class with 10 items it might use 1KB, and if I load it with...
2
by: dumbo | last post by:
Hello, who gives one more shining solution to me? My application load form "A". The form "A" by means of a push-button load form "B" that in its turn by means of a push-button load form "C". Form...
27
by: thomasp | last post by:
Variables that I would like to make available to all forms and modules in my program, where should I declare them? At the momment I just created a module and have them all declared public there. ...
2
by: super_dave_42 | last post by:
I am searching for a way to create multiple records in Access 2000 from a worksheet created in Excel. I'm pretty much self-taught with Visual Basic so forgive me if this poorly described. Basically...
2
by: lewisms | last post by:
Hello all, I am quite new to c++/. Net so please don't shoot me down for being a newbie. Any way I am trying to make a simple multithreading program that is just to learn the ideas behind it...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.