Retain value in Variable after Application closes

so next time i open i can get that value

Page 1 of 1

8 Replies - 7008 Views - Last Post: 21 May 2009 - 10:24 AM Rate Topic: -----

#1 just_a_beginner  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 16-April 09

Retain value in Variable after Application closes

Posted 22 April 2009 - 01:37 AM

Hi,

I want to retain a value in a variable even after the application closes, so the next time i open the application i can get that value.

It's actually an integer value, i want to count the no. of times the application has been opened. I tried using static [b] but it doesnt work. Please help. :blink:

Is This A Good Question/Topic? 0
  • +

Replies To: Retain value in Variable after Application closes

#2 Goethals  Icon User is offline

  • D.I.C Head

Reputation: 25
  • View blog
  • Posts: 145
  • Joined: 14-April 09

Re: Retain value in Variable after Application closes

Posted 22 April 2009 - 01:40 AM

You'll have to store it in a file, or on a database.
Variables live in your RAM memory, and are cleared when
your application closes.
Was This Post Helpful? 0
  • +
  • -

#3 just_a_beginner  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 16-April 09

Re: Retain value in Variable after Application closes

Posted 22 April 2009 - 02:10 AM

View PostGoethals, on 22 Apr, 2009 - 12:40 AM, said:

You'll have to store it in a file, or on a database.
Variables live in your RAM memory, and are cleared when
your application closes.

Are u sure there's no keyword or anything to save that value other than a textfile?? Thanks anyway. :)

Do u know how to enter a large number of values into a combobox???

This post has been edited by just_a_beginner: 22 April 2009 - 02:11 AM

Was This Post Helpful? 0
  • +
  • -

#4 Goethals  Icon User is offline

  • D.I.C Head

Reputation: 25
  • View blog
  • Posts: 145
  • Joined: 14-April 09

Re: Retain value in Variable after Application closes

Posted 22 April 2009 - 02:27 AM

You could store it in the registry...
Forgot about that sorry.
Be carefull doing so though,
you really dont want to mess up your registry.
I would advise saving it to a file or a database though.
Was This Post Helpful? 0
  • +
  • -

#5 Lesco  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 55
  • Joined: 05-December 08

Re: Retain value in Variable after Application closes

Posted 22 April 2009 - 05:47 AM

Have your program write to a text doc saved in the bin folder of your program.
 My.Computer.FileSystem.WriteAllText("textboxname.txt", "contents, could be variables" & "more text or" Controlchars.newline, True) 


you could keep adding more text and such before the True if you wanted to. Its been a while since i used this code but im pretty certain the option for append is set to true so that it does not erase the contents of the text document everytime you write to it, if it does erase all the contents every time you write to it simply change it to false.

as for putting the text in a list box or text box, you should be able to use the readalltext method.
 textbox1.text = My.Computer.FileSystem.ReadAllText("textdoc.txt")

Was This Post Helpful? 0
  • +
  • -

#6 just_a_beginner  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 16-April 09

Re: Retain value in Variable after Application closes

Posted 23 April 2009 - 12:59 AM

View PostLesco, on 22 Apr, 2009 - 04:47 AM, said:

Have your program write to a text doc saved in the bin folder of your program.
 My.Computer.FileSystem.WriteAllText("textboxname.txt", "contents, could be variables" & "more text or" Controlchars.newline, True) 


you could keep adding more text and such before the True if you wanted to. Its been a while since i used this code but im pretty certain the option for append is set to true so that it does not erase the contents of the text document everytime you write to it, if it does erase all the contents every time you write to it simply change it to false.

as for putting the text in a list box or text box, you should be able to use the readalltext method.
 textbox1.text = My.Computer.FileSystem.ReadAllText("textdoc.txt")



Thanks.

View PostGoethals, on 22 Apr, 2009 - 01:27 AM, said:

You could store it in the registry...
Forgot about that sorry.
Be carefull doing so though,
you really dont want to mess up your registry.
I would advise saving it to a file or a database though.



Thanks. I will use the text file.
Was This Post Helpful? 0
  • +
  • -

#7 ra_preethi  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 21-May 09

Re: Retain value in Variable after Application closes

Posted 21 May 2009 - 03:59 AM

Is it possible to store value in app.config file and use?
Was This Post Helpful? 0
  • +
  • -

#8 bigtonyk  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 61
  • Joined: 17-May 09

Re: Retain value in Variable after Application closes

Posted 21 May 2009 - 07:29 AM

View Postjust_a_beginner, on 22 Apr, 2009 - 12:37 AM, said:

Hi,

I want to retain a value in a variable even after the application closes, so the next time i open the application i can get that value.

It's actually an integer value, i want to count the no. of times the application has been opened. I tried using static [b] but it doesnt work. Please help. :blink:


You can use Application Settings in VB.

http://msdn2.microso...y/a65txexh.aspx
Was This Post Helpful? 0
  • +
  • -

#9 specialfreckles  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 06-March 09

Re: Retain value in Variable after Application closes

Posted 21 May 2009 - 10:24 AM

Just use the built in GetSetting, SaveSetting routines


	Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
	   
		dim Uses as Integer = cint( GetSetting( My.Application.Info.ProductName, "General", "Used", "0"))
		SaveSetting( My.Application.Info.ProductName, "General", "Used", (Uses + 1).ToString)

	End Sub





This post has been edited by specialfreckles: 21 May 2009 - 11:44 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1