|
-
Jun 3rd, 2001, 06:46 AM
#1
Thread Starter
Hyperactive Member
Writing to a file...
I want to record the data inputed by a user in 7 textboxes to a txt file...
the code that I have is this...
Code:
Open "C:\File.txt" For Append As #1
Print #1, txtTime1.Text, txtTime2.Text, txtTime3.Text, txtTime4.Text, txtTime5.Text, txtTime6.Text, txtTime7.Text
Close #1
But for some reason, it doesn't record the data, it just puts spaces in the file.. there is nothing in it..
What am I doing wrong?
Thanks!
-Emo
-=VB6 Enterprise Edition=-
-=VC++6Enterprise Edition=-
«¤E³m°O²™¤»
-
Jun 3rd, 2001, 06:49 AM
#2
You needto write just a single string to the file:
Code:
Dim lstrOut as String
lstrOut = Text1.Text & "," & Text2.Text & "," & Text3.Text 'And so on
Open "C:\File.txt" For Append As #1
Print #1, lstrOut
Close #1
And don't use #1 - use the FreeFile function instead to get a valid file handle
- gaffa
-
Jun 3rd, 2001, 07:00 AM
#3
Junior Member
I found that this also worked fine, and formatted the entries into
columns within the files itself.
Code:
Option Explicit
Private Sub Command1_Click()
Dim iFileNum As Integer
iFileNum = FreeFile
Open App.Path & "\test.txt" For Append As iFileNum
Print #iFileNum, Text1.Text, Text2.Text, Text3.Text
Close #iFileNum
End Sub
I would also look towards using a control array of text box's.
Last edited by Smithy; Jun 3rd, 2001 at 07:04 AM.
"Three minutes thought would suffice to find this out; but thought is irksome and three minutes is a long time."
"The supreme irony of life is that hardly anyone gets out of it alive."
-
Jun 3rd, 2001, 07:13 AM
#4
Thread Starter
Hyperactive Member
gaffa, with you code all I got was ,,,,,,,
Smithy, with you code I got the same as me... nothing in text file and whole lotta spaces...
Am I doing this worng??? Why can it work with other people and it can't work with me? 
-Emo
-=VB6 Enterprise Edition=-
-=VC++6Enterprise Edition=-
«¤E³m°O²™¤»
-
Jun 3rd, 2001, 07:19 AM
#5
Addicted Member
Smithy,
With the exception of FreeFile, that is exactly the same code that Emo posted orginally. So if it works for you then Emo must have another problem.
Emo,
Put a break point on the Print line and check the value of text in the textboxes.
-
Jun 3rd, 2001, 07:24 AM
#6
Thread Starter
Hyperactive Member
Found something...
With gaffa's code... when I input everything in the textboxes and press the command button the first time it displays ,,,,,,, but then if I press it again, it works... I have no Idea how, but it does!
Thanks Gaffa!
By the way, how can make it write to a new line of the txt file whenever it reaches a point, let's say at the end of textbox7 it should go to a new line if something else is written afterwords?
Thanks!
-Emo
-=VB6 Enterprise Edition=-
-=VC++6Enterprise Edition=-
«¤E³m°O²™¤»
-
Jun 3rd, 2001, 07:35 AM
#7
Junior Member
Just add vbCrlf (visual basic carriage return line feed) or vbNewLine to your code where you want it:
Code:
Print #iFileNum, Text1.Text, Text2.Text & vbNewLine & Text3.Text
"Three minutes thought would suffice to find this out; but thought is irksome and three minutes is a long time."
"The supreme irony of life is that hardly anyone gets out of it alive."
-
Jun 3rd, 2001, 07:38 AM
#8
Thread Starter
Hyperactive Member
-=VB6 Enterprise Edition=-
-=VC++6Enterprise Edition=-
«¤E³m°O²™¤»
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
|