Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
Visual Basic 6 - problema collegamento button e applicazione
Forum - Visual Basic 6 - problema collegamento button e applicazione

Avatar
g.patera (Normal User)
Newbie


Messaggi: 1
Iscritto: 21/04/2011

Segnala al moderatore
Postato alle 16:39
Giovedì, 21/04/2011
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:

Codice sorgente - presumibilmente VB.NET

  1. Private Sub Command14_Click()
  2. Shell (App.Path & "\flash")
  3. 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:

Codice sorgente - presumibilmente VB.NET

  1. Private Sub Command14_Click()
  2. Shell (App.Path & "\documento.txt")
  3. 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 il 21/04/2011 alle 16:40
PM Quote
Avatar
BigMitch (Member)
Rookie


Messaggi: 43
Iscritto: 15/02/2009

Segnala al moderatore
Postato alle 22:33
Giovedì, 21/04/2011
Ciao prova ad usare la libreria ShellExecute. Ti allego il file .bas con la relativa funzione

Codice sorgente - presumibilmente VB.NET

  1. Attribute VB_Name = "Shell"
  2. Option Explicit
  3. 'API STUFF ====================================================================
  4. Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
  5.     (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, _
  6.     ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd _
  7.     As Long) As Long
  8. Private Const SW_SHOWNORMAL = 1
  9. Private Const SW_SHOWMINIMIZED = 2
  10. Private Const ERROR_FILE_NOT_FOUND = 2&
  11. Private Const ERROR_PATH_NOT_FOUND = 3&
  12. Private Const ERROR_BAD_FORMAT = 11&
  13. Private Const SE_ERR_ACCESSDENIED = 5
  14. Private Const SE_ERR_ASSOCINCOMPLETE = 27
  15. Private Const SE_ERR_DDEBUSY = 30
  16. Private Const SE_ERR_DDEFAIL = 29
  17. Private Const SE_ERR_DDETIMEOUT = 28
  18. Private Const SE_ERR_DLLNOTFOUND = 32
  19. Private Const SE_ERR_FNF = 2
  20. Private Const SE_ERR_NOASSOC = 31
  21. Private Const SE_ERR_OOM = 8
  22. Private Const SE_ERR_PNF = 3
  23. Private Const SE_ERR_SHARE = 26
  24.  
  25. 'strProgram is the name of a program to run, or a file to open
  26. 'EX: calc.exe or c:\test.doc or http:\\www.microsoft.com
  27. Public Sub RunProgram(strProgram As String)
  28.     Dim lRet As Long    ' Get the return value
  29.    
  30.     ' Execute the API call
  31.     lRet = ShellExecute(vbNull, "", strProgram, "", "", SW_SHOWNORMAL)
  32.     'Stampa il file
  33.    ' lRet = ShellExecute(vbNull, "open", strProgram, "", "", SW_SHOWNORMAL) 'print
  34.    
  35.    
  36.     ' If ShellExecute works it will return a number greate than 32
  37.     ' Otherwise call our ReportError function to see what went wrong
  38.     If lRet <= 32 Then
  39.         ReportShellExecuteError (lRet)
  40.     End If
  41. End Sub
  42.  
  43. Private Sub ReportShellExecuteError(lErrNum As Long)
  44.     Dim strErr As String
  45.     Select Case lErrNum
  46.         Case ERROR_FILE_NOT_FOUND
  47.             strErr = "The specified file was not found."
  48.         Case ERROR_PATH_NOT_FOUND
  49.             strErr = "The specified path was not found."
  50.         Case ERROR_BAD_FORMAT
  51.             strErr = "The .exe file is invalid (non-Win32® .exe or error in .exe image)."
  52.         Case SE_ERR_ACCESSDENIED
  53.             strErr = "The operating system denied access to the specified file. "
  54.         Case SE_ERR_ASSOCINCOMPLETE
  55.             strErr = "The file name association is incomplete or invalid."
  56.         Case SE_ERR_DDEBUSY
  57.             strErr = "The DDE transaction could not be completed because other DDE transactions were being processed."
  58.         Case SE_ERR_DDEFAIL
  59.             strErr = "The DDE transaction failed."
  60.         Case SE_ERR_DDETIMEOUT
  61.             strErr = "The DDE transaction could not be completed because the request timed out."
  62.         Case SE_ERR_DLLNOTFOUND
  63.             strErr = "The specified dynamic-link library was not found. "
  64.         Case SE_ERR_FNF
  65.             strErr = "The specified file was not found. "
  66.         Case SE_ERR_NOASSOC
  67.             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."
  68.         Case SE_ERR_OOM
  69.             strErr = "There was not enough memory to complete the operation."
  70.         Case SE_ERR_PNF
  71.             strErr = "The specified path was not found."
  72.         Case SE_ERR_SHARE
  73.             strErr = "A sharing violation occurred."
  74.     End Select
  75.    
  76.     MsgBox strErr, vbExclamation, "Error running program"
  77. End Sub


Ultima modifica effettuata da BigMitch il 21/04/2011 alle 22:35
PM Quote
Avatar
poeo85 (Normal User)
Pro


Messaggi: 104
Iscritto: 27/01/2010

Segnala al moderatore
Postato alle 9:19
Venerdì, 22/04/2011
oppure più semplicemente

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


a te mancava l'applicazione... :heehee:

Ultima modifica effettuata da poeo85 il 22/04/2011 alle 9:20
PM Quote