VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



How to open a file with one line of code

by Nick Pordash (1 Submission)
Category: Files/File Controls/Input/Output
Compatability: Visual Basic 3.0
Difficulty: Unknown Difficulty
Date Added: Wed 3rd February 2021
Rating: (38 Votes)

You create a funtion that can open a file with just one line of code.

Inputs
Form is your Form, RichTextBox is your RichTextBox, and Commondialog is your Commondialog.
Assumes
This code requires a Commondialog and a RichTextBox.
Code Returns
The file you just open in the richtextbox you picked.
API Declarations

Rate How to open a file with one line of code

Public Function Openf(frm As Form, Text As RichTextBox, Dialog As CommonDialog)
   On Error Resume Next
    Dialog.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*|" 'Edit the filter how you want it 
    Dialog.Flags = cdlOFNPathMustExist & cdlOFNHideReadOnly
    Dialog.Action = 1
    Screen.MousePointer = vbHourglass
    Text.Text = ""
    Text.LoadFile Dialog.filename
    frm.Show
    frm.Refresh
    Screen.MousePointer = vbNormal
End Function
Private Sub Command1_Click()
Call Openf(Me, RichTextBox1, CommonDialog1)
End Sub

Download this snippet    Add to My Saved Code

How to open a file with one line of code Comments

No comments have been posted about How to open a file with one line of code. Why not be the first to post a comment about How to open a file with one line of code.

Post your comment

Subject:
Message:
0/1000 characters