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
Avatar of isaackhazi
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

Avatar of Mike_Carroll
Mike_Carroll
Flag of Ireland image

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

If my memory serves me correctly (c;


Avatar of Whing Dela Cruz

ASKER

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


Avatar of 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)?
Avatar of Whing Dela Cruz

ASKER

Yes Idle mind,
I want to simply PROGRAMMATICALLY open the file and make changes to it (and print it)
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

Avatar of Whing Dela Cruz

ASKER

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

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Whing Dela Cruz

ASKER

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
Avatar of Whing Dela Cruz

ASKER

Thanks and More POwer
Visual Basic Classic
Visual Basic Classic

Visual Basic is Microsoft’s event-driven programming language and integrated development environment (IDE) for its Component Object Model (COM) programming model. It is relatively easy to learn and use because of its graphical development features and BASIC heritage. It has been replaced with VB.NET, and is very similar to VBA (Visual Basic for Applications), the programming language for the Microsoft Office product line.

165K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo