|
-
Oct 26th, 2006, 09:59 AM
#1
Thread Starter
Lively Member
[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.
-
Oct 26th, 2006, 10:17 AM
#2
Re: [VB6] Txtbox shows account balance
What's in the text file? Can you post sample please?
-
Oct 26th, 2006, 10:28 AM
#3
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
-
Oct 26th, 2006, 10:34 AM
#4
Re: [VB6] Txtbox shows account balance
@Gavio:
What's the rush? How do you know what's in the file?
-
Oct 26th, 2006, 10:49 AM
#5
Thread Starter
Lively Member
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..

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.
-
Oct 26th, 2006, 11:50 AM
#6
Re: [VB6] Txtbox shows account balance
 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
'...
-
Oct 26th, 2006, 12:10 PM
#7
Thread Starter
Lively Member
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?
-
Oct 26th, 2006, 12:56 PM
#8
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.
-
Oct 26th, 2006, 01:07 PM
#9
Thread Starter
Lively Member
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
-
Oct 26th, 2006, 01:09 PM
#10
Thread Starter
Lively Member
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!!~
-
Oct 26th, 2006, 01:13 PM
#11
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
-
Oct 26th, 2006, 01:41 PM
#12
Thread Starter
Lively Member
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.
-
Oct 26th, 2006, 01:52 PM
#13
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.
-
Oct 26th, 2006, 01:56 PM
#14
Thread Starter
Lively Member
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?
-
Oct 26th, 2006, 02:08 PM
#15
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
-
Oct 26th, 2006, 02:54 PM
#16
Thread Starter
Lively Member
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
-
Oct 26th, 2006, 02:58 PM
#17
Re: [VB6] Txtbox shows account balance
And this is loaded from "balance.txt"?
-
Oct 26th, 2006, 03:03 PM
#18
Thread Starter
Lively Member
Re: [VB6] Txtbox shows account balance
im not even sure on how to store it...
-
Oct 26th, 2006, 03:14 PM
#19
Re: [VB6] Txtbox shows account balance
 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:
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
-
Oct 26th, 2006, 03:30 PM
#20
Thread Starter
Lively Member
-
Oct 27th, 2006, 01:14 AM
#21
Thread Starter
Lively Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|