Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 210
  • Last Modified:

Listview Execution off sellected Items

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
patrickvisser
Asked:
patrickvisser
  • 4
  • 3
  • 2
  • +4
1 Solution
 
patrickvisserAuthor Commented:
Need it Badley
0
 
TigerZhaoCommented:
what's mean? open a file with default application ( txt with notepad, htm with IE, etc.)?
0
 
patrickvisserAuthor Commented:
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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
Éric MoreauSenior .Net ConsultantCommented:
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
 
Erick37Commented:
??
Case SE_ERR_NOASSOC
    MsgBox "Ce type de document n'est pas ASSOCIÉ à une application dans Windows."
0
 
chrisblevinsCommented:
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
 
chrisblevinsCommented:
chrisblevins changed the proposed answer to a comment
0
 
TigerZhaoCommented:
'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
 
Éric MoreauSenior .Net ConsultantCommented:
Erick37,

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

Means: File type is not associated.
0
 
patrickvisserAuthor Commented:
Please Engles No FRNS..
0
 
hesCommented:
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
 
wileecoyCommented:
That's it patrickvisser - I have to agree.  All 3 of them work (some even in French).
0
 
patrickvisserAuthor Commented:
Whel the Code from emoreau works just fine. and i can finnnish my work..
0
 
Éric MoreauSenior .Net ConsultantCommented:
I was the first presenting this solution so I think I deserve the points!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 3
  • 2
  • +4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now