|
-
Sep 24th, 2000, 09:54 PM
#1
Thread Starter
New Member
I have just started VB programming, and I got a book to help me, it gives me lessons on how to do things...
One of the programs it is helping me make is a word process. Its just a simple one using buttons and a text box. It told me to put a CommonDialog box into it as well.
The problem is, in the Open button the code they asked me to put in is this:
Private Sub cmdOpen_Click()
CommonDialog1.ShowOpen
If CommonDialog1.FileName <> "" Then Text1.Text = CommonDialog1.FileName
End Sub
When i tried it, it just put the filepath into the textbox, how do i fix this.
I am completely new to VB (started yesterday), and so I really would appreciate any help
Thanx
Diablo_2097
-
Sep 24th, 2000, 11:01 PM
#2
Member
When the Dialog comes up you have to select a file, otherwise all you'll get is the path that was either set in code or navigated to by the user (you).
Glacius Cool
Concept Designer
VB5sp4,VC++6sp3
-
Sep 24th, 2000, 11:06 PM
#3
Frenzied Member
Actually, that is exactly what that code does..
The common dialog only gives you the name of the file, it does not actually open the file...
Code:
Dim intFileHandle as Integer
Dim intFileName as String
Dim strBuffer as String
CommonDialog1.ShowOpen
If CommonDialog1.FileName <> "" Then
strFileName = CommonDialog1.FileName
Else
Exit Sub
End If
intFileHandle = FreeFile(0)
Open strFileName For Read As #intFileHandle
Do Until EOF(intFileHandle)
Line Input #iErrorHandle, strBuffer
Text1.Text = Text1.Text & strBuffer & Chr(13) & Chr(10)
Loop
Close #intFileHandle
Although this would work, it is probably better to replace the textbox with a Richtextbox then you can use the .LoadFile method to easily load the contents of a file into it...
oOOo--oOOo
__ /\/\onte96
oOOo--oOOo
Senior Programmer/Analyst
MCP
[email protected]
[email protected]
Your results may vary.. some restrictions may apply.. pricing and participation may vary.. not available in all states.. professional driver closed course..quantities limited..
-
Sep 25th, 2000, 02:54 AM
#4
Thread Starter
New Member
Thanx Glacius, but what do you mean?? when i click on the open button, then click on a text file, it puts the filepath only in the text box, it doesnt load the contents.
Monte, so there isn't an easy way to open a file without a rich text box is there?? What is this??
Thanx i'm really appreciating the replys
-
Sep 25th, 2000, 06:54 AM
#5
Try this:
Code:
Private Sub Command1_Click()
Dim intFileHandle as Integer
Dim strFileName as String
CommonDialog1.CancelError = True
CommonDialog1.ShowOpen
If CommonDialog1.FileName <> "" Then
strFileName = CommonDialog1.FileName
Else
Exit Sub
End If
intFileHandle = FreeFile
Open strFileName for Input as #intFileHandle
Text1.text = Input(LOF(1), intFileHandle)
Close #intFileHandle
End Sub
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
|