|
-
Aug 13th, 2002, 07:45 PM
#1
Thread Starter
Lively Member
Opening a txt file
How do I put text from a notepad .txt file into a text box on my form?
I am using this code
VB Code:
Dim iFileNum
Dim txtInput
iFileNum = FreeFile
Open "C:\Test.txt" For Input As iFileNum
Print #iFileNum, txtInput
Close iFileNum
Text1.Text = txtInput
but it says that its a bad file mode. how do I fix this?
-
Aug 13th, 2002, 07:48 PM
#2
You can't use Print when the file is open for Input. Try opening it for Output or Append.
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Aug 13th, 2002, 07:51 PM
#3
So Unbanned
Try this:
open "file" for binary as #1
filecontents = input(lof(1),#1)
close #1
text1.text = filecontents
-
Aug 13th, 2002, 07:51 PM
#4
Put this in a module
Function LoadFile(FileName As String)
Dim FileNumber As Long
DIm Data As String
FileNumber = FreeFile
If FileName = "" Then Exit Function
Open FileName For Binary Access Read As FileNumber
Data = String(FileLen(FileName), Chr(0))
Get FileNumber,,Data
Close FileNumber
LoadFile = Data
End Function
'Example Text1 = LoadFile("C:\test.txt")
Have Fun
«°°phReAk°°»
Visual Studio 6, Visual Studio.NET 2005, MASM
-
Aug 13th, 2002, 07:53 PM
#5
Thread Starter
Lively Member
may I see some working code plzzz?
-
Aug 13th, 2002, 07:56 PM
#6
VB Code:
Dim iFileNum As Integer
Dim txtInput As String
iFileNum = FreeFile
Open "C:\Test.txt" For Input As #iFileNum
txtInput = Input$(LOF(iFileNum),iFileNum)
Close #iFileNum
Text1.Text = txtInput
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
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
|