Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Variables that never lost their values 2

Status
Not open for further replies.

assimang

Programmer
Mar 11, 2008
96
Hello everyone,
I am very new in vb.net 2005 and I want ask if it's possible to declare some variables that will keep it's values even if the program will end without lost their values the next time I run it? And how? Any help much appreciated.

Thanks in advanced.
 
Yes, it's common for applications to read and write values to persistent storage. You can use a text file, database, xml file (app.config or custom), binary file, the registry or another method to store your values. You will need to come up with routines to read in the values to variables when the application is launched as well as saving the values when the application is closing.

 
Thank you riverguy, I first thought sql but my problem is that my variables are boolean and microsoft sql server 2005 doesn't provide boolean type. Secondly, I am thinking about text file, how can do this with text file and how can I access it, its variables, and its values via code?
 
[red]>> microsoft sql server 2005 doesn't provide boolean type[/red]

Yes. SQL Server does provide a 'boolean' type, but they call it BIT, instead.

A BIT column/variable can be 1, 0, or NULL.



-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Thank you so much gmnastro!
I didn't know it so i am going to do it though sql.
If you set allow nulls unchecked is it possible to accept null value? What does exactly represent null? Boolean type can be true or false. Why bit provides null to?

Thank again, both of you!
 
I should clarify a little.

I don't recommend using a full blown relation database just to store a boolean or two. The purpose of my post is to clear up any confusion regarding SQL Server and how it handles booleans.

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
You can think of NULL as 'I don't know'.

For example, suppose you are tracking people, and you want to store a boolean for 'High School Diploma'. Obviously everyone has a high school diploma, or they don't. However, from a data perspective, it's possible that you won't know, which is where NULL comes in handy.

Make sense?

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Thank you again gmnastro.
Well, i am using a database created through sql for my application and I thought to created this table with variables there, but you are right that it's not a relational table, and I don't think I could relate it with another table. I have 3 bit variables and one int.
 
If you are already using a database, then it makes sense to use it for this too. Not all tables need to relate to other tables.

My point was... I wouldn't use a SQL Database to store 3 bits and an int UNLESS I was already using it for other purposes.

Most of the DB's I create have a 'config' table. In this config table, I have 2 columns, ConfigName and ConfigValue. I use this table for little odds and ends that don't really merit having their own table. Each column is a varchar. If I want to store a boolean, I would actually store 'True' or 'False' in the table. By definition, this table will never get large, and it will only be used infrequently, so doing data conversion is not a problem.

Make sense?

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Thank you so much george once more. It works nice.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top