?
Solved

Listview Execution off  sellected Items

Posted on 2000-03-16
14
Medium Priority
?
202 Views
Last Modified: 2006-11-17
Hi,
I Have a listview and i want to execute files in it when a user bubbelclick the sellected item in it. Is there a easy code for it..

Thanks, Folks,,,
0
Comment
Question by:patrickvisser
[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
  • 4
  • 3
  • 2
  • +4
14 Comments
 

Author Comment

by:patrickvisser
ID: 2626038
Need it Badley
0
 
LVL 4

Expert Comment

by:TigerZhao
ID: 2626109
what's mean? open a file with default application ( txt with notepad, htm with IE, etc.)?
0
 

Author Comment

by:patrickvisser
ID: 2626150
Yes Yes, thats is. Just like the explorer does with files. When you dubbelklick a *.txt file the the notpad starts and when a *.doc is dubbelclk then word is starting..
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 70

Expert Comment

by:Éric Moreau
ID: 2626166
Use this:

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_SHOWNORMAL = 1
Private Const ERROR_FILE_NOT_FOUND = 2&
Private Const ERROR_PATH_NOT_FOUND = 3&
Private Const ERROR_BAD_FORMAT = 11&
Private Const SE_ERR_ACCESSDENIED = 5
Private Const SE_ERR_ASSOCINCOMPLETE = 27
Private Const SE_ERR_DDEBUSY = 30
Private Const SE_ERR_DDEFAIL = 29
Private Const SE_ERR_DDETIMEOUT = 28
Private Const SE_ERR_DLLNOTFOUND = 32
Private Const SE_ERR_FNF = 2
Private Const SE_ERR_NOASSOC = 31
Private Const SE_ERR_OOM = 8
Private Const SE_ERR_PNF = 3
Private Const SE_ERR_SHARE = 26

Private Sub Command1_Click()
Dim lngResult As Long

    lngResult = ShellExecute(Me.hwnd, "open", List1.List(list1.listindex), vbNullString, "", SW_SHOWNORMAL)

    'If the function fails, the return value is an error value that is less than or equal to 32.
    If lngResult >= 33 Then Exit Sub
   
    Select Case lngResult
        Case 0
            MsgBox "The operating system is out of memory or resources."
        Case ERROR_FILE_NOT_FOUND
            MsgBox "Le document est introuvable."
        Case ERROR_PATH_NOT_FOUND
            MsgBox "Le chemin d'accès est introuvable."
        Case ERROR_BAD_FORMAT
            MsgBox "The .EXE file is invalid (non-Win32 .EXE or error in .EXE image)."
        Case SE_ERR_ACCESSDENIED
            MsgBox "The operating system denied access to the specified file."
        Case SE_ERR_ASSOCINCOMPLETE
            MsgBox "The filename association is incomplete or invalid."
        Case SE_ERR_DDEBUSY
            MsgBox "The DDE transaction could not be completed because other DDE transactions were being processed."
        Case SE_ERR_DDEFAIL
            MsgBox "The DDE transaction failed."
        Case SE_ERR_DDETIMEOUT
            MsgBox "The DDE transaction could not be completed because the request timed out."
        Case SE_ERR_DLLNOTFOUND
            MsgBox "The specified dynamic-link library was not found."
        Case SE_ERR_FNF
            MsgBox "The specified file was not found."
        Case SE_ERR_NOASSOC
            MsgBox "Ce type de document n'est pas ASSOCIÉ à une application dans Windows."
        Case SE_ERR_OOM
            MsgBox "There was not enough memory to complete the operation."
        Case SE_ERR_PNF
            MsgBox "The specified path was not found."
        Case SE_ERR_SHARE
            MsgBox "A sharing violation occurred."
    End Select
End Sub
0
 
LVL 32

Expert Comment

by:Erick37
ID: 2626185
??
Case SE_ERR_NOASSOC
    MsgBox "Ce type de document n'est pas ASSOCIÉ à une application dans Windows."
0
 

Expert Comment

by:chrisblevins
ID: 2626195
Use the Shell function and pass it the Text property (or Tag property, whichever you're using to store the filename). Keep in mind this won't work with non-executable files, and your VB program will have no way of knowing when the called program finishes execution.

0
 

Expert Comment

by:chrisblevins
ID: 2626199
chrisblevins changed the proposed answer to a comment
0
 
LVL 4

Expert Comment

by:TigerZhao
ID: 2626210
'the function ShellOpen will use defautl application open a file, if not success will show "Open With..." dialog

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 Declare Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
Public Sub ShellOpen(strFile As String)
    Dim lngRet As Long
    Dim strDir As String
    lngRet = ShellExecute(GetDesktopWindow, "open", strFile, vbNullString, vbNullString, vbNormalFocus)
    If lngRet < 32 Then
        ' no association exists
        strDir = Space(260)
        lngRet = GetSystemDirectory(strDir, Len(strDir))
        strDir = Left(strDir, lngRet)
        ' show the Open with dialog box
        Call ShellExecute(GetDesktopWindow, vbNullString, "RUNDLL32.EXE", "shell32.dll,OpenAs_RunDLL " & strFile, strDir, vbNormalFocus)
    End If
End Sub
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 2626245
Erick37,

"Ce type de document n'est pas ASSOCIÉ à une application dans Windows."

Means: File type is not associated.
0
 

Author Comment

by:patrickvisser
ID: 2626252
Please Engles No FRNS..
0
 
LVL 20

Expert Comment

by:hes
ID: 2626300
As everyboy has said use
Use the following:
(uses a textbox for filename, with path, and a command button to start the file)

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 Sub Command1_Click()
Call ShellExecute(0&, vbNullString, Text1.Text, vbNullString, _
vbNullString, vbNormalFocus)
End Sub
 
0
 
LVL 4

Expert Comment

by:wileecoy
ID: 2626420
That's it patrickvisser - I have to agree.  All 3 of them work (some even in French).
0
 

Author Comment

by:patrickvisser
ID: 2626996
Whel the Code from emoreau works just fine. and i can finnnish my work..
0
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 400 total points
ID: 2627861
I was the first presenting this solution so I think I deserve the points!
0

Featured Post

Independent Software Vendors: 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

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month14 days, 14 hours left to enroll

771 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