?
Solved

Open file without specifying the executable program to use (VB6)

Posted on 2010-08-18
5
Medium Priority
?
380 Views
Last Modified: 2013-11-07
Hi
Is it possible in Visual Basic Classic to open a file (let's say c:\test.txt) without specifying the executable program to use (notepad.exe). Instead specifying the executable program i want to rely on the windows default executable that is set up to open that kind of file.

Regards,
Cristi
0
Comment
Question by:Cristi_E
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 42

Accepted Solution

by:
sedgwick earned 800 total points
ID: 33462192
use shellExecute:
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

ShellExecute 0, vbNullString, """"c:\test.txt"""", vbNullString, vbNullString, vbNormalFocus

Open in new window

0
 
LVL 53

Assisted Solution

by:Dhaest
Dhaest earned 1200 total points
ID: 33462203
Use the ShellExecute API function to execute a file, launch the Find utility, and perform default actions
http://www.vb-helper.com/howto_shellexecute.html


Example: ShellExecute hWnd, "open", "C:\whatever\test.html", _
    vbNullString, vbNullString, SW_SHOWNORMAL

For more information see link
0
 
LVL 53

Assisted Solution

by:Dhaest
Dhaest earned 1200 total points
ID: 33462209
If you want to pass the program you want to use, you can also perform this through shellExecute

You can use ShellExecute to do this and also pass other options to the receiving application. View below

Source: http://www.daniweb.com/forums/thread63235.html

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 'Magical functionPublic Function OpenLocation(ByVal WhichFilePath As String, Optional sParams As String = "", Optional sStartIn As String = vbNullString, Optional lngOpenMode As Long = 1) As Long    OpenLocation = ShellExecute(0, "Open", WhichFilePath, sParams, sStartIn, lngOpenMode)End Function 'Your button clickPrivate Sub Command1_Click() If OpenLocation("notepad.exe", "c:\myfile.txt", "", 1) < 32 Then    'Failed to openElse    'OpenedEnd If End Sub'Put this at the top of your form or module

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

'Magical function
Public Function OpenLocation(ByVal WhichFilePath As String, Optional sParams As String = "", Optional sStartIn As String = vbNullString, Optional lngOpenMode As Long = 1) As Long
    OpenLocation = ShellExecute(0, "<strong class="highlight">Open</strong>", WhichFilePath, sParams, sStartIn, lngOpenMode)
End Function

'Your button click
Private Sub Command1_Click()

If OpenLocation("notepad.exe", "c:\myfile.txt", "", 1) < 32 Then
    'Failed to <strong class="highlight">open</strong>
Else
    'Opened
End If

End Sub

Open in new window

0
 

Expert Comment

by:ziameo
ID: 33462259
Spend the day watching some CBT nuggets on the subject.
0
 
LVL 4

Author Closing Comment

by:Cristi_E
ID: 33462786
Works great !
Thanks!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand column That will then direct you to their download page. From that p…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.
Suggested Courses
Course of the Month9 days, 4 hours left to enroll

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question