By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,594 Members | 2,016 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,594 IT Pros & Developers. It's quick & easy.

How to make vB remember a value between forms?

P: 1
Hi! I'm using a database to store the values for my project. I'm designing a simple payroll.

I want to calculate the gross salary of an employee, to do this I have to get the hourly rate of that person (I have that stored on a table) and multiply it by the total of hours worked (those values I store on a different table).

I'm having problems taking the hourly rate from the other table to do the math calculation. When I input the values into the database I had to do it on another form, and they're on another table so I really have no idea how I should call it. I've tried it several ways but Visual Basic always records it as 0.

Oh... and I wish I could, but I can't make any changes to my database. Teacher's orders. blah. :(

Thanks so much in advance for your help. I wasn't sure what code to paste here so... if you need me to expand more on the problem with some coding let me know. :]
Dec 12 '07 #1
Share this Question
Share on Google+
3 Replies

P: 41
If your using VB6 then you can add a Module to your project and then at the top declare some global variables, like so...

Global MyGlobalVar As String

If your using VB.NET then add a Module to your project and then at the top declare your global variables like so...

Public myGlobalVar As String

This approach stores your values in a central location for use from any form.

I'm not saying that this is good coding practice. I'm only giving you an answer to your question. If you want a more robust method of doing the work then based on your explanation of the project your working on, I would create all the forms required to handle data input and have all that data stored in the database (like you've already done). Then I would create function to retrieve all the data from the database manipulate it then output it to the user. Others here may have better advise.

Hope this helps,
Dec 13 '07 #2

Expert 5K+
P: 8,127
You need to declare some public variables.
Dec 13 '07 #3

P: 9
Yes, Public variables. I had the same problem several years ago, but after creating a module called Variables (Or whatever), I keep all my variable declarations in that module "Public MyVar1, MyVar2, MyVar3 As Single" etc.

Haven't had the problem with forgotten variable values since.

Hope this helped,
Dec 15 '07 #4

Post your reply

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