Opening text file in a text box using common dialog 
Author Message
 Opening text file in a text box using common dialog

how can i open a text file into a text box using a common dialog?

thanks...



Sat, 04 Oct 2003 09:00:50 GMT  
 Opening text file in a text box using common dialog
On Tue, 17 Apr 2001 02:00:50 +0100, "Stuart Gilbert"

Untested code !

Sub DoOpenFile()
        dim fNo as integer
        dim aLine as string

        cmd1.cancelerror = true
        on error goto no_open
        cmd1.showopen
        fNo = freefile()
        open cmd1.filename for input as fno
                do while not eof(fno)
                        line input #fno, aLine
                        text1.text = text1.text & aLine
                loop
no_open:                
        if err then msgbox("Error :" & Err.Description)
        close
End Sub

Quote:
>how can i open a text file into a text box using a common dialog?

>thanks...

Regards, Frank.


Sat, 04 Oct 2003 12:09:25 GMT  
 Opening text file in a text box using common dialog
If you do "On Error Goto no_open" then it will return an error if you click
Cancel on this dialog box. A better way would be:

sub DoOpenFile()
On Error Resume Next
dim fNo as integer
dim aLine as string
cmd1.cancelerror = true
cmd1.showopen
if err = 0 then
    fNo = freefile()
    open cmd1.filename for input as fno
    do while not eof(fno)
    line input #fno, aLine
    text1.text = text1.text & aLine
    loop
    close
endif
end sub



Quote:
> On Tue, 17 Apr 2001 02:00:50 +0100, "Stuart Gilbert"

> Untested code !

> Sub DoOpenFile()
> dim fNo as integer
> dim aLine as string

> cmd1.cancelerror = true
> on error goto no_open
> cmd1.showopen
> fNo = freefile()
> open cmd1.filename for input as fno
> do while not eof(fno)
> line input #fno, aLine
> text1.text = text1.text & aLine
> loop
> no_open:
> if err then msgbox("Error :" & Err.Description)
> close
> End Sub

> >how can i open a text file into a text box using a common dialog?

> >thanks...

> Regards, Frank.



Sat, 04 Oct 2003 12:37:18 GMT  
 Opening text file in a text box using common dialog


Wed, 18 Jun 1902 08:00:00 GMT  
 Opening text file in a text box using common dialog
or with using Input(LOF(fNo), #fNo):

Sub DoOpenFile()
On Error Resume Next
Dim fNo As Integer
Dim aLine As String
Dim FileContents As String

cmd1.cancelerror = True
cmd1.showopen
If Err = 0 Then
    fNo = FreeFile()
    Open cmd1.FileName For Input As fNo
    FileContents = Input(LOF(fNo), #fNo)
    Close
    Text1.Text = FileContents
End If
End Sub



Quote:
> If you do "On Error Goto no_open" then it will return an error if you
click
> Cancel on this dialog box. A better way would be:

> sub DoOpenFile()
> On Error Resume Next
> dim fNo as integer
> dim aLine as string
> cmd1.cancelerror = true
> cmd1.showopen
> if err = 0 then
>     fNo = freefile()
>     open cmd1.filename for input as fno
>     do while not eof(fno)
>     line input #fno, aLine
>     text1.text = text1.text & aLine
>     loop
>     close
> endif
> end sub



> > On Tue, 17 Apr 2001 02:00:50 +0100, "Stuart Gilbert"

> > Untested code !

> > Sub DoOpenFile()
> > dim fNo as integer
> > dim aLine as string

> > cmd1.cancelerror = true
> > on error goto no_open
> > cmd1.showopen
> > fNo = freefile()
> > open cmd1.filename for input as fno
> > do while not eof(fno)
> > line input #fno, aLine
> > text1.text = text1.text & aLine
> > loop
> > no_open:
> > if err then msgbox("Error :" & Err.Description)
> > close
> > End Sub

> > >how can i open a text file into a text box using a common dialog?

> > >thanks...

> > Regards, Frank.



Sat, 04 Oct 2003 18:05:13 GMT  
 Opening text file in a text box using common dialog


Wed, 18 Jun 1902 08:00:00 GMT  
 Opening text file in a text box using common dialog


I'm rather picky about where i use Resume Next.
In this case things can still go wrong after the dialog code. Another
user could have locked or killed the file, it may be zero length or
the programmer may have made a subtle mistake which will go unnoticed
because of the Resume and become a pita to find bug when the code
grows. Not that the latter ever occurs. :-)  

Usually i'd have a Select Case after the no_open label if Err is
detected and cater for the most common errors, with a chance to jump
back to the open dialog again.  

Quote:
>If you do "On Error Goto no_open" then it will return an error if you click
>Cancel on this dialog box. A better way would be:

>sub DoOpenFile()
>On Error Resume Next
>dim fNo as integer
>dim aLine as string
>cmd1.cancelerror = true
>cmd1.showopen
>if err = 0 then
>    fNo = freefile()
>    open cmd1.filename for input as fno
>    do while not eof(fno)
>    line input #fno, aLine
>    text1.text = text1.text & aLine
>    loop
>    close
>endif
>end sub



>> On Tue, 17 Apr 2001 02:00:50 +0100, "Stuart Gilbert"

>> Untested code !

>> Sub DoOpenFile()
>> dim fNo as integer
>> dim aLine as string

>> cmd1.cancelerror = true
>> on error goto no_open
>> cmd1.showopen
>> fNo = freefile()
>> open cmd1.filename for input as fno
>> do while not eof(fno)
>> line input #fno, aLine
>> text1.text = text1.text & aLine
>> loop
>> no_open:
>> if err then msgbox("Error :" & Err.Description)
>> close
>> End Sub

>> >how can i open a text file into a text box using a common dialog?

>> >thanks...

>> Regards, Frank.

Regards, Frank.


Sun, 05 Oct 2003 00:51:04 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. SIMPLE HELP NEEDED - Saving a text file using a common dialog box

2. problem determining file to open using common dialog box

3. problems determining file to open using common dialog box

4. Centering a Open Dialog box using the Common dialog

5. opening 1 text file to multiple text boxes

6. opening text files into text boxes and more!

7. opening text files into text boxes and more!

8. opening / saving files with MS rich text box control (viewing open files)

9. Common Dialog and plain text box

10. Fonts Common Dialog and Rich Text Box problem...please help

11. using isam text driver to open comma delimited text file

12. Open File Common Dialog Boxes in Access95 VBA Code

 

 
Powered by phpBB® Forum Software