|
-
Nov 28th, 1999, 03:37 AM
#1
Thread Starter
Junior Member
Hi,
Once again I your need advice. I'm doing my first project and I want the numbers that the user puts in a text box to be stored and afterwards I can use these data to make some additions or substractions. The idea is that once the user writes the number in a text box and presses "Enter" this number will be stored and avalaible to do some simple mathematical operations.
I wrote this simple thing but it doesn't work. What is my mistake? Please help.
Option Explicit
Dim strTotal
Dim Stored
Dim Total
Private Sub Text1_KeyPrees(KeyAscii As Integer)
If KeyAscii = 13 Then
strTotal = Text1.Text
Stored = strTotal
Total = Total + Stored
End If
End Sub
Thanks in advance for your help,
Xenia Jones
------------------
-
Nov 28th, 1999, 04:10 AM
#2
Hyperactive Member
The easiest way would be to store the numbers in a text file. Then you can retrieve the data even if the user shuts down the program and the restarts it. If you like, I could show you how to do that (if you don't already know).
-
Nov 28th, 1999, 05:17 AM
#3
Junior Member
I think you code doesn't work because you're trying to add strings. Try this
Option Explicit
Dim strTotal As Integer
Dim Total As Integer
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
strTotal = CInt(Text1.Text)
Total = Total + strTotal
End If
End Sub
This should work. 
------------------
Quadrex
[email protected]
Quadrex Programming
-
Nov 29th, 1999, 02:32 AM
#4
Thread Starter
Junior Member
Hi,
Thanks to you both for your time. I don't know why but it didn't work.
It seems so simply but I can't do it.
Any other advice?
Thanks and best wishes,
Xenia Jones
-
Nov 29th, 1999, 03:24 AM
#5
If you dimension your global variables as follows
Code:
Dim strTotal As Integer
Dim Stored As Integer
Dim Total As Integer
it will work. That is, if you type 6 in your textbox, press Enter, then replace the 6 with a 4 and press Enter again, Total will contain 10. If that's not what you want to have happen, please give an example of what you want.
------------------
Marty
-
Nov 29th, 1999, 03:26 AM
#6
Hyperactive Member
Hi again,
Looking back at my advice, I have some code that you could try. However, I would place the code in a Command button. I'm assuming that you've done that instead of using the ENTER button.
So, when you want to save the numbers, use this code (I'm assuming that you want to save only one number from Text1):
Code:
open "C:\My Documents\Numbers.txt" for output as #1
write #1, text1.text
close #1
Then, when you want to retrieve the number, use this code:
Code:
dim number
open "C:\My Documents\Number.txt" for input as #1
do while not eof(1)
input #1, number
loop
close #1
Now, when you want to perform the equation, use this:
Code:
dim total
total = total + number
I hope that this helped. If not, just tell me.
------------------
Regards,
Alexander McAndrew
VB Zone
http://gsenterprise.server101.com
-
Nov 29th, 1999, 11:02 PM
#7
Thread Starter
Junior Member
Thanks a lots for your help. I really appreciate what you have done and of course your time. I hope do some day the same thing for you!
Best wishes,
Xenia Jones
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|