[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. :)
Re: [VB6] Txtbox shows account balance
What's in the text file? Can you post sample please?
Re: [VB6] Txtbox shows account balance
VB Code:
'to load
Open "c:\balance.txt" For Input As #1
Text1.Text = Input(LOF(1),1)
Close #1
'to save
Open "c:\balance.txt" For Output As #1
Print #1, Text1.Text
Close #1
Re: [VB6] Txtbox shows account balance
@Gavio:
What's the rush? How do you know what's in the file?
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:
Private Sub Form_Load()
Open "C:\Documents and Settings\Virii.EKLIPS\Desktop\Eklips Banking\data\balance.txt" For Input As #1
txtAccountbalance.Text = Input(LOF(1), 1)
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..
http://www.3horns.com/temp/deposit.JPG
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.
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:
Open [B]App.Path & "\data\balance.txt"[/B] For Input As #1
'...
Re: [VB6] Txtbox shows account balance
it still doesnt work though.. i've even tried
VB Code:
Private Sub Form_Load()
Open "C:\balance.txt" For Input As #1
txtAccountbalance.Text = Input(LOF(1), 1)
Close #1
and place the balance.txt file in my C: and it still says file not found?
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?
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
Re: [VB6] Txtbox shows account balance
it keep saying Run-time error 53
file not found.. my code
VB Code:
Private Sub Form_Load()
Open "C:\Documents and Settings\Virii.EKLIPS\Desktop\Eklips Banking\data\balance.txt" For Input As #1
txtAccountbalance.Text = Input(LOF(1), #1)
Close #1
help me pros!!~ :)
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
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?
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.
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:
Private Sub txtWithdrawamount_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Open ("Data\" & "balance.txt") For Output As #1
Print #1, txtDepositAmount.Text
Close #1
End If
End Sub
like this?
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
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
Re: [VB6] Txtbox shows account balance
And this is loaded from "balance.txt"?
Re: [VB6] Txtbox shows account balance
im not even sure on how to store it...
Re: [VB6] Txtbox shows account balance
Quote:
Originally Posted by eklips
im not even sure on how to store it...
:confused: 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:
Option Explicit
Private filename As String
Private Sub Form_Load()
filename = App.Path & "\balance.txt"
End Sub
Private Sub Command1_Click()
'to add - date and time are added automatically by addEntry method
addEntry "Withdraw", 500, 500
addEntry "Deposit", 1000, 1000
End Sub
Private Sub Command2_Click()
'to load
Dim tmp As String
Dim ff As Integer
ff = FreeFile
If Dir(filename) <> vbNullString Then
Open filename For Input As #ff
txtHistory.Text = Input(LOF(ff), ff)
Close #ff
End If
End Sub
Private Sub addEntry(transaction As String, current As Long, ballance As Long)
Dim ff As Integer
ff = FreeFile
Open filename For Append As #ff
Print #ff, Date & " " & Time & " " & transaction & _
" $" & current & " $" & ballance
Close #ff
End Sub
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
http://www.3horns.com/temp/deposit1.JPG
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
http://www.3horns.com/temp/withdraw1.JPG
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.
Re: [VB6] Txtbox shows account balance
does anyone know who can help? any open sources?