|
-
Mar 9th, 2002, 08:03 PM
#1
Thread Starter
Member
help pls
Anyone know how to (using VB6):
a) create a .txt file
b) read from any of the created file
c) write or put information into the .txt file
I tried MSscript but it gives me a lot of problem(I'm not farmiliar
with it).
The text stored in the .txt file is just for information storage, not
for controling any objects or script.
-
Mar 9th, 2002, 08:12 PM
#2
VB Code:
Option Explicit
Private Sub cmdLoad_Click()
Text1.Text = FileToString("C:\File.txt")
End Sub
Private Sub cmdSave_Click()
StringToFile Text1.Text, "C:\File.txt"
End Sub
Function FileToString(ByVal sFile As String) As String
Dim iFile As Integer
Dim sData As String
iFile = FreeFile
Open sFile For Binary Access Read As iFile
sData = Space(LOF(iFile))
Get #iFile, , sData
Close iFile
FileToString = sData
End Function
Sub StringToFile(ByVal sString As String, ByVal sFile As String)
Dim iFile As Integer
If Len(Dir(sFile)) > 0 Then Kill sFile
iFile = FreeFile
Open sFile For Binary Access Write As iFile
Put #iFile, , sString
Close iFile
End Sub
-
Mar 9th, 2002, 08:19 PM
#3
Thread Starter
Member
the code have stopped at :
Open sFile For Binary Access Write As iFile
what sure i do??
-
Mar 9th, 2002, 08:28 PM
#4
What do you mean?
Did you add 2 command buttons (cmdLoad, cmdSave) and a Multiline Textbox (Text1)?
-
Mar 9th, 2002, 08:28 PM
#5
Thread Starter
Member
it says path/file access error, so i change i change the path to:
App.Path & "\text.txt"
but it still would not run.....
-
Mar 9th, 2002, 08:30 PM
#6
Do you have a C:\ drive (It's possible in W2K to have a different Drive Letter for the system drive.) or is the file File.txt already being used by something else, or do you not have Write permissions to the root of the Harddrive?
-
Mar 9th, 2002, 08:32 PM
#7
Thread Starter
Member
thanks i got it working ......
but there is one thing that i need to know,
can i do indent on the text file, say have 2 rows of information
like what i can do in Script????
Using functions like:
Skip(no of spaces)
SkipLine
-
Mar 9th, 2002, 08:36 PM
#8
VB Code:
sString = sString & vbCrLf ' Go To Next Line
sString = sString & Space(20) ' Skip in 20 Spaces
-
Mar 9th, 2002, 08:43 PM
#9
Thread Starter
Member
Thanks for your time and help,
but last of all, when i have the spacing and lines, how do i read
them??
for ur information, I'm using matrix(array) to do calculation,
but i have to check, save and read from the text file.
i will have no problem writing it down(on the .txt) and check the
procedures for constructing it but how do I read from the .txt
and put it back into an array????
-
Mar 9th, 2002, 08:51 PM
#10
If you're storing data for calulcations why don't you store it in a CSV (Comma Separated Values) fashion,
then you can use the Split() function to extract the values into an Array, i.e.
VB Code:
Dim sData As String
Dim vLine As Variant
Dim vValue As Variant
Dim lLine As Long
sData = FileToString("C:\File.txt")
vLine = Split(sData, vbCrLf)
For lLine = 0 To Ubound(vLine)
vValue = Split(vLine(lLine), ",")
' Do Whatever with vValue Array
Next
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
|