Oppure

Loading
21/04/11 14:39
g.patera
Ciao a tutti!
Per prima cosa vorrei davvero congratularmi con voi per lo splendido lavoro su questo sito e ringraziarvi per tutte le volte che mi avete aiutato, anche senza saperlo! :k:
Ora però vorrei un aiuto ad un errore davvero strano che sto riscontrando su VB6:

Praticamente ho creato un' applicazione con una serie di tasti che mi aprono diversi programmi con questa tecnica:

Private Sub Command14_Click()
Shell (App.Path & "\flash")
End Sub


Ho creato circa 14 button con diverse applicazioni associate, ora però ho un problema.
Praticamente vorrei aggiungere un documento .txt con la stessa tecnica, ma quando scrivo:

Private Sub Command14_Click()
Shell (App.Path & "\documento.txt")
End Sub


Mi da errore 53 : file non trovato. Vi anticipo già che il nome è corretto e il file si trova nella cartella di vb come gli altri. :(
Sapete darmi un consiglio??

Ringrazio tutti in anticipo e buona giornata! :k:
Ultima modifica effettuata da g.patera 21/04/11 14:40
aaa
21/04/11 20:33
BigMitch
Ciao prova ad usare la libreria ShellExecute. Ti allego il file .bas con la relativa funzione


Attribute VB_Name = "Shell"
Option Explicit
'API STUFF ====================================================================
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 SW_SHOWMINIMIZED = 2
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

'strProgram is the name of a program to run, or a file to open
'EX: calc.exe or c:\test.doc or http:\www.microsoft.com
Public Sub RunProgram(strProgram As String)
    Dim lRet As Long    ' Get the return value
    
    ' Execute the API call
    lRet = ShellExecute(vbNull, "", strProgram, "", "", SW_SHOWNORMAL)
    'Stampa il file
   ' lRet = ShellExecute(vbNull, "open", strProgram, "", "", SW_SHOWNORMAL) 'print
    
    
    ' If ShellExecute works it will return a number greate than 32
    ' Otherwise call our ReportError function to see what went wrong
    If lRet <= 32 Then
        ReportShellExecuteError (lRet)
    End If
End Sub

Private Sub ReportShellExecuteError(lErrNum As Long)
    Dim strErr As String
    Select Case lErrNum
        Case ERROR_FILE_NOT_FOUND
            strErr = "The specified file was not found."
        Case ERROR_PATH_NOT_FOUND
            strErr = "The specified path was not found."
        Case ERROR_BAD_FORMAT
            strErr = "The .exe file is invalid (non-Win32® .exe or error in .exe image)."
        Case SE_ERR_ACCESSDENIED
            strErr = "The operating system denied access to the specified file. "
        Case SE_ERR_ASSOCINCOMPLETE
            strErr = "The file name association is incomplete or invalid."
        Case SE_ERR_DDEBUSY
            strErr = "The DDE transaction could not be completed because other DDE transactions were being processed."
        Case SE_ERR_DDEFAIL
            strErr = "The DDE transaction failed."
        Case SE_ERR_DDETIMEOUT
            strErr = "The DDE transaction could not be completed because the request timed out."
        Case SE_ERR_DLLNOTFOUND
            strErr = "The specified dynamic-link library was not found. "
        Case SE_ERR_FNF
            strErr = "The specified file was not found. "
        Case SE_ERR_NOASSOC
            strErr = "There is no application associated with the given file name extension. This error will also be returned if you attempt to print a file that is not printable."
        Case SE_ERR_OOM
            strErr = "There was not enough memory to complete the operation."
        Case SE_ERR_PNF
            strErr = "The specified path was not found."
        Case SE_ERR_SHARE
            strErr = "A sharing violation occurred."
    End Select
    
    MsgBox strErr, vbExclamation, "Error running program"
End Sub

Ultima modifica effettuata da BigMitch 21/04/11 20:35
aaa
22/04/11 7:19
poeo85
oppure più semplicemente

Shell("notepad c:\nomefile.txt", vbNormalFocus)


a te mancava l'applicazione... :heehee:
Ultima modifica effettuata da poeo85 22/04/11 7:20
aaa