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
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