?
Solved

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

Posted on 2010-08-18
5
Medium Priority
?
385 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:
Meir Rivkin 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
Suggested Courses

649 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