开发者

How to develop accumulator codes?

开发者 https://www.devze.com 2022-12-10 14:45 出处:网络
This is for vb.net I\'ve been working to develop a system which involves computation. I would just like to ask for any ideas or source code or a link perhaps that

This is for vb.net I've been working to develop a system which involves computation. I would just like to ask for any ideas or source code or a link perhaps that could help me resolve this issue.

What I've been trying to develop in my program is, I have a textbox where user will enter a numeric value,there is a button and a label below and in the first place the label

should be set to zero. Everytime you enter a numeric value in the textbox and click the button it should add the value in the label and should save the valu开发者_JS百科e in the label so even if you exit the program whatever the last value displayed in the label should remain the same when run the program again,I believe it requires a database to save the value. Basically its like with payment system which saves the total amount of all payments made.

This is how should it works,say for example,if you will enter 1,2,3 it should save the sum value which is 6 in the label even if you close the program and when you run it again and enter another value it should add to the current value which is 6.

I would greatly appreciate for any informative response.


why dont u use files to save the result ?


You could simply save the current sum as a User Setting.


There are several ways to save a number (or a million numbers) between program executions. Using a database to save a single number is like using a freight train to transport a can of Diet Coke. It will do the job, but it takes a lot more effort to use.

Instead, try saving the number to a file when the program exits, and read that file when the program begins running.

One way to save a number to a file is:

FileOpen(1, My.Application.Info.DirectoryPath & "\" & "app.dat", OpenMode.Output)
Print(1, numvariable)
FileClose(1)

' My.Application.Info.DirectoryPath & "\" & "app.dat" ' is the file name -- it can be any valid path\name. "numvariable" is the number you want to save.

Similarly, you can read the number like this:

If file.exists(My.Application.Info.DirectoryPath & "\" & "app.dat") Then
  FileOpen(1, My.Application.Info.DirectoryPath & "\" & "app.dat", OpenMode.Input)
  Input(1, numvariable)
  FileClose(1)
End If

You probably will want to use a string variable for the file name. You'll need to put "imports system.io" at the top of the program. If you try to open a file that does not exist for input, it causes an error. That's why you have to check for it first with File.Exists.

0

精彩评论

暂无评论...
验证码 换一张
取 消