Avatar of Whing Dela Cruz
Whing Dela CruzFlag for Anguilla asked on

Open Notepad

How to open notepad using vb6?
Visual Basic Classic

Avatar of undefined
Last Comment
Whing Dela Cruz

8/22/2022 - Mon
isaackhazi

same as how u open a text file..... ie .txt.....
Dim FILE_NAME As String = "C:\test.txt"
 
Dim objReader As New System.IO.StreamReader(FILE_NAME)

Open in new window

Mike_Carroll

ReturnValue = Shell("C:\windows\system32\notepad.exe", 1)

If my memory serves me correctly (c;


ASKER
Whing Dela Cruz

Sorry, I don't explain exactly what i wanted, But what i want is to open .text file then save it.. using vb6. or may i have an option to print and save the file. Is it possible ? if yes, please give me good examples I'm vb6 beginner... Thanks!!!


I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
Mike Tomlinson

Please be more specific...

Do you want to make an EDITOR for the user to make changes to the file and then save/print it?

...or do you want to simply PROGRAMMATICALLY open the file and make changes to it (and print it)?
ASKER
Whing Dela Cruz

Yes Idle mind,
I want to simply PROGRAMMATICALLY open the file and make changes to it (and print it)
Mike Tomlinson

See here for "raw" printing:
http://support.microsoft.com/kb/q154078/

You can also print this way:

Option Explicit
 
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
 
Private Const SW_HIDEWINDOW = &H80
 
Private Sub Command1_Click()
    ShellExecute Me.hwnd, "Print", "c:\abc.txt", 0&, 0&, SW_HIDEWINDOW
End Sub

Open in new window

Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ASKER
Whing Dela Cruz

Thank you so much Idle mind! I've got it, But what about to save this file? can i make it?
ASKER CERTIFIED SOLUTION
Mike Tomlinson

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
Whing Dela Cruz

I can now open the file and print it base on the given code above. Upon opening the file i want to save it to another path or make it some changes before saving.Below is the code i used...

' I want to make another command3 to edit and save the file. is it possible? if yes Pls help. thanks!

Option Explicit
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Private Const SW_HIDEWINDOW = &H80

Public Sub Command1_Click()
Dim ff As Integer
Dim fileName As String
Dim entireFile As String
   
ff = FreeFile
fileName = "c:\someFile.txt"
Open fileName For Binary Access Read As #ff
entireFile = Input(LOF(ff), ff)
Close #ff
 
Text1.Text = entireFile
End Sub
Private Sub Command2_Click()
    ShellExecute Me.hwnd, "Print", "c:\someFile.txt", 0&, 0&, SW_HIDEWINDOW
End Sub
ASKER
Whing Dela Cruz

Thanks and More POwer
Your help has saved me hundreds of hours of internet surfing.
fblack61