Results 1 to 21 of 21

Thread: [RESOLVED] [VB6] Txtbox shows account balance

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2006
    Posts
    74

    Resolved [RESOLVED] [VB6] Txtbox shows account balance

    hi.. how do i create on form load txtbox check a text document file example balance.txt and displays the balance into the textbox? Please teach me how to make it write into the text document too, i'm have to make a deposit function as well.



    Thank you so much guys, the people in this forum are really friendly.

  2. #2

  3. #3
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Re: [VB6] Txtbox shows account balance

    VB Code:
    1. 'to load
    2. Open "c:\balance.txt" For Input As #1
    3.     Text1.Text = Input(LOF(1),1)
    4. Close #1
    5.  
    6. 'to save
    7. Open "c:\balance.txt" For Output As #1
    8.     Print #1, Text1.Text
    9. Close #1

  4. #4

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Oct 2006
    Posts
    74

    Re: [VB6] Txtbox shows account balance

    Hi there Gavio, i tired your code but it keep saying file not found even when i put the correct location in..

    VB Code:
    1. Private Sub Form_Load()
    2.     Open "C:\Documents and Settings\Virii.EKLIPS\Desktop\Eklips Banking\data\balance.txt" For Input As #1
    3.     txtAccountbalance.Text = Input(LOF(1), 1)
    4. Close #1


    Greetings RhinoBull,

    actually there is nothing in the text file unless i deposit money to the "atm simulator" so this text file will capture and save the amount example $500 and displays it in txtbox on formload. each time someone deposits it adds the amount together example 1st deposit was $500 next deposit was $200.50 so it becomes $700.50 and when i withdraw it deducts from the account balance. there would also be a text box showing this history of transactions. Any idea on how i could do this?

    ****LINK FIXED****
    Below is a picture of my form:
    Please view to get a better picture, its hard for me to explain..


    on form load the account balance textbox should automatically display the current balance which is retrieve from ("\Data\" & "balance.txt")

    the top textbox is to enter amount wanted to deposit and it update the account balance.
    Last edited by eklips; Oct 26th, 2006 at 11:28 AM.

  6. #6
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Re: [VB6] Txtbox shows account balance

    Quote Originally Posted by eklips
    Hi there Gavio, i tired your code but it keep saying file not found even when i put the correct location in...
    Well, you must be specifying the filename wrong cause the code works for me. Also, if this is your project folder you can also do it like this:
    VB Code:
    1. Open [B]App.Path & "\data\balance.txt"[/B] For Input As #1
    2. '...

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Oct 2006
    Posts
    74

    Re: [VB6] Txtbox shows account balance

    it still doesnt work though.. i've even tried

    VB Code:
    1. Private Sub Form_Load()
    2.     Open "C:\balance.txt" For Input As #1
    3.     txtAccountbalance.Text = Input(LOF(1), 1)
    4. Close #1

    and place the balance.txt file in my C: and it still says file not found?

  8. #8
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: [VB6] Txtbox shows account balance

    Try txtAccountbalance.Text = Input(LOF(1), #1)

    Are you sure you want to stick to textfiles rather than a database?
    Last edited by leinad31; Oct 26th, 2006 at 01:00 PM.

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Oct 2006
    Posts
    74

    Re: [VB6] Txtbox shows account balance

    well... first.. i already dont know how to stick it to textfiles hence i'm asking over here for everyones help.. database would just be harder for me to learn the codes people write.. as in harder for me to understand to get it to work.. haha

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Oct 2006
    Posts
    74

    Re: [VB6] Txtbox shows account balance

    it keep saying Run-time error 53
    file not found.. my code

    VB Code:
    1. Private Sub Form_Load()
    2. Open "C:\Documents and Settings\Virii.EKLIPS\Desktop\Eklips Banking\data\balance.txt" For Input As #1
    3.     txtAccountbalance.Text = Input(LOF(1), #1)
    4. Close #1

    help me pros!!~

  11. #11
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: [VB6] Txtbox shows account balance

    Check the filename... are you sure your file is not named balance.txt.txt or some similar problem? Are you sure the file already exists? For Input doesn;t automatically create the textfile

  12. #12

    Thread Starter
    Lively Member
    Join Date
    Oct 2006
    Posts
    74

    Re: [VB6] Txtbox shows account balance

    OHHHH soooo soorrryyy ok so many people is gona shoot me in the head now.. i stupidly renamed it as balance.txt.txt........ sorry guys.. =X heee...

    ok now on form load it does displays wad i wrote in the txt file which is "$0.00"

    Now my next step is, on keypress in the textboxDeposit it catches the amount and writes it into the txt file still maintaining the format of $0.00.
    Is it possible for anyone to communicate with me via msn messenger?
    Last edited by eklips; Oct 26th, 2006 at 01:46 PM.

  13. #13
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: [VB6] Txtbox shows account balance

    If your just gonna add entries to the end of the file, then I suggst you open the file For Append. And I suggest you drop the dollar sign when writing to the file, save just numeric amounts with no currency sign.

  14. #14

    Thread Starter
    Lively Member
    Join Date
    Oct 2006
    Posts
    74

    Re: [VB6] Txtbox shows account balance

    ok, drop the $ sign since i've added the symbol as a label on the form.
    how do i get amount entered into txtDeposit textbox to be written into balance.txt upon keying the number in and pressing enter?

    VB Code:
    1. Private Sub txtWithdrawamount_KeyPress(KeyAscii As Integer)
    2. If KeyAscii = 13 Then
    3. Open ("Data\" & "balance.txt") For Output As #1
    4.     Print #1, txtDepositAmount.Text
    5. Close #1
    6.  
    7. End If
    8. End Sub

    like this?

  15. #15
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: [VB6] Txtbox shows account balance

    Nope don't do it per key cause you won't be able to handle backspace, deletions, pastes... do it as a batch/the complete amount... when the user presses the button to commit the amount execute your file For append... For Output deletes the previous content of the file.

    Open ("Data\" & "balance.txt") For Append As #1
    Print #1, txtDepositAmount.Text
    Close #1

  16. #16

    Thread Starter
    Lively Member
    Join Date
    Oct 2006
    Posts
    74

    Re: [VB6] Txtbox shows account balance

    how do i create a history textbox which shows the history of transactions? example:

    Date Time Transaction Current Balance
    27/10/2006 3:50AM Withdraw $500 $500
    26/10/2006 12:30PM Deposit $1000 $1000

  17. #17

  18. #18

    Thread Starter
    Lively Member
    Join Date
    Oct 2006
    Posts
    74

    Re: [VB6] Txtbox shows account balance

    im not even sure on how to store it...

  19. #19
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Re: [VB6] Txtbox shows account balance

    Quote Originally Posted by eklips
    im not even sure on how to store it...
    Ok... if you're dealing with a simple text file then you could do that by storing each entry in each line. For example (create a TextBox named "txtHistory" and two CommandButtons - one for save and one for load):
    VB Code:
    1. Option Explicit
    2.     Private filename As String
    3.  
    4. Private Sub Form_Load()
    5.     filename = App.Path & "\balance.txt"
    6. End Sub
    7.  
    8. Private Sub Command1_Click()
    9.     'to add - date and time are added automatically by addEntry method
    10.     addEntry "Withdraw", 500, 500
    11.     addEntry "Deposit", 1000, 1000
    12. End Sub
    13.  
    14. Private Sub Command2_Click()
    15.     'to load
    16.     Dim tmp As String
    17.     Dim ff As Integer
    18.     ff = FreeFile
    19.    
    20.         If Dir(filename) <> vbNullString Then
    21.             Open filename For Input As #ff
    22.                 txtHistory.Text = Input(LOF(ff), ff)
    23.             Close #ff
    24.         End If
    25. End Sub
    26.  
    27. Private Sub addEntry(transaction As String, current As Long, ballance As Long)
    28.     Dim ff As Integer
    29.     ff = FreeFile
    30.                
    31.         Open filename For Append As #ff
    32.             Print #ff, Date & " " & Time & " " & transaction & _
    33.                        " $" & current & " $" & ballance
    34.         Close #ff
    35. End Sub

  20. #20

    Thread Starter
    Lively Member
    Join Date
    Oct 2006
    Posts
    74

    Re: [VB6] Txtbox shows account balance

    Ok sorry i might not be clear with my explanations, thank you for your replies all of you

    Below is a screenshot of the Deposit section of my ATM Simulator


    First textbox it for user to key in amount to deposit.
    Doing so will: deposit amount + account balance = msgbox says Done and second textbox labeled Account Balance will show updated amount.

    Below is a screeshot of the Withdraw section of my ATM Simulator


    First textbox it for user to key in amount to withdraw
    Doing so will: account balance - withdraw amount = msgbox says Done and second textbox labeled Account Balance will show updated amount.

    Lastly, the History section which i've not complete the GUI
    it will show date, time, type of transaction, amount, account balance after transaction.

    How do i perform these actions? I'm reading and learning at the same time with some books i borrowed from the library. Please help me out, thank you.

  21. #21

    Thread Starter
    Lively Member
    Join Date
    Oct 2006
    Posts
    74

    Re: [VB6] Txtbox shows account balance

    does anyone know who can help? any open sources?

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