Results 1 to 7 of 7

Thread: An advice.

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Oct 1999
    Posts
    24

    Post

    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



    ------------------

  2. #2
    Hyperactive Member
    Join Date
    Apr 1999
    Location
    New Jersey
    Posts
    334

    Post

    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).

  3. #3
    Junior Member
    Join Date
    Nov 1999
    Posts
    26

    Post

    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


  4. #4

    Thread Starter
    Junior Member
    Join Date
    Oct 1999
    Posts
    24

    Post

    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

  5. #5
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Post

    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

  6. #6
    Hyperactive Member
    Join Date
    Apr 1999
    Location
    New Jersey
    Posts
    334

    Post

    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


  7. #7

    Thread Starter
    Junior Member
    Join Date
    Oct 1999
    Posts
    24

    Post

    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
  •  



Click Here to Expand Forum to Full Width