IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

VB 6 et antérieur Discussion :

Shell pour fichier .bat Nconvert


Sujet :

VB 6 et antérieur

  1. #1
    Futur Membre du Club
    Homme Profil pro
    Rédacteur technique
    Inscrit en
    Février 2017
    Messages
    5
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Yvelines (Île de France)

    Informations professionnelles :
    Activité : Rédacteur technique

    Informations forums :
    Inscription : Février 2017
    Messages : 5
    Points : 5
    Points
    5
    Par défaut Shell pour fichier .bat Nconvert
    Bonjour à tous,

    j'ai un problème avec le code suivant:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    Option Compare Text
    Option Explicit
     
    Public Path As String
    Public TailleReel As String
    Public TextFile, Taille As String
    Public Txtpath, Tpath, TxtDest  As String
    Public Txtname, Txtnameshort, Extension As String
     
    Public F1 As String
     
     
    Private Const BIF_RETURNONLYFSDIRS = 1
    Private Const BIF_DONTGOBELOWDOMAIN = 2
     
    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 ShellExecuteForExplore Lib "shell32.dll" Alias "ShellExecuteA" _
      (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, lpParameters As Any, _
      lpDirectory As Any, ByVal nShowCmd As Long) As Long
    Private Declare Function SHBrowseForFolder Lib "shell32" (lpbi As BrowseInfo) As Long
    Private Declare Function SHGetPathFromIDList Lib "shell32" (ByVal pidList As Long, _
        ByVal lpBuffer As String) As Long
    Private Declare Function lstrcat Lib "kernel32" Alias "lstrcatA" (ByVal lpString1 As String, _
        ByVal lpString2 As String) As Long
    Private Type BrowseInfo
        hwndOwner As Long
        pIDLRoot As Long
        pszDisplayName As Long
        lpszTitle As Long
         ulFlags As Long
        lpfnCallback As Long
        lParam As Long
        iImage As Long
    End Type
    Private Declare Sub InitCommonControls Lib "comctl32.dll" ()
    Function FindAndReplace(ByVal strInString As String, _
        strFindString As String, _
        strReplaceString As String) As String
        Dim intPtr As Integer
            If Len(strFindString) > 0 Then 'catch if try to find empty string
                Do
                    intPtr = InStr(strInString, strFindString)
                    If intPtr > 0 Then
                        FindAndReplace = FindAndReplace & Left(strInString, intPtr - 1) & strReplaceString
                        strInString = Mid(strInString, intPtr + Len(strFindString))
                    End If
                Loop While intPtr > 0
            End If
        FindAndReplace = FindAndReplace & strInString
    End Function
    Sub Command1_Click()
    On Error GoTo error_handler
     
    F1 = FreeFile
    Tpath = App.Path & "\"
     
     
        With dlg
            .DialogTitle = "Select a file" 'titre de la boite
            .FileName = "*.*" 'on recherche un fichier d'extension txt
            .InitDir = "D:\LocalData\" 'repertoire par defaut
            .CancelError = True 'pour ne pas partir en erreur si on click sur annuler
            .ShowOpen
        End With
     
     
        Txtpath = dlg.FileName
        Txtname = dlg.FileTitle
        TailleReel = Len(Txtpath) - Len(Txtname)
        TxtDest = Left(Txtpath, TailleReel)
        Extension = Right(Txtname, 4)
        Txtnameshort = FindAndReplace(Txtname, Extension, "")
     
     
    Open Tpath & "F1.bat" For Output As #F1 'creation du FI.bat
    Print #F1, "nconvert -out jpeg -dpi 300 -resize 1004 708 -o Phenix_" & Txtnameshort & ".jpg " & Txtname
    Close #F1
     
    'FileCopy Tpath & "nconvert.exe", TxtDest & "nconvert.exe"
    FileCopy Txtpath, Tpath & Txtname
     
    Shell (Tpath & "F1.bat")
     
     
    Exit Sub
    error_handler: If Err.Number = 32755 Then                            'recupere l'erreur renvoyer si l'utilisateur clique sur annulé
                        MsgBox "Please select a file"
                        Exit Sub
                   End If
    End Sub
    avec ce code, mon fichier bat ne "fait rien" par contre si j'utilise
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    'FileCopy Tpath & "nconvert.exe", TxtDest & "nconvert.exe"
    c'est a dire que je déplace nconvert vers le dossier de mon image (au lieu d'importé l'image dans le repertoire de mon appli), mon .bat fonctionne bien (en pas à pas, car je pense que j'ai un problème de tempo entre la copie et le lancement du shell).

    j'ai recherche un peux partout sur Google et ici, j'ai essayer bcp de syntaxe différentes, pour toujours le même résultat.
    pourriez vous me dire ce que je fait de travers svp?

    cordialement,
    cedric

  2. #2
    Modérateur
    Avatar de ProgElecT
    Homme Profil pro
    Retraité
    Inscrit en
    Décembre 2004
    Messages
    6 077
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 68
    Localisation : France, Haute Savoie (Rhône Alpes)

    Informations professionnelles :
    Activité : Retraité
    Secteur : Communication - Médias

    Informations forums :
    Inscription : Décembre 2004
    Messages : 6 077
    Points : 17 171
    Points
    17 171
    Par défaut
    Salut

    Un peu tard .... mais
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    Option Compare Text
    Option Explicit
     
    Public Path As String
    Public TailleReel As String
    'Public TextFile, Taille As String ' <-*-*-*-*-*-*-*- non utilisé dans le code soumis -*-*-*-*-*-*-
    Public Txtpath  As String, Tpath  As String, TxtDest  As String
    Public Txtname As String, Txtnameshort As String, Extension As String
     
    Public F1 As Integer ' String
     
     
    'Private Const BIF_RETURNONLYFSDIRS = 1 ' <-*-*-*-*-*-*-*- non utilisé dans le code soumis -*-*-*-*-*-*-
    'Private Const BIF_DONTGOBELOWDOMAIN = 2 ' <-*-*-*-*-*-*-*- non utilisé dans le code soumis -*-*-*-*-*-*-
     
    '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 ' <-*-*-*-*-*-*-*- non utilisé dans le code soumis -*-*-*-*-*-*-
     
    'Private Declare Function ShellExecuteForExplore Lib "shell32.dll" Alias "ShellExecuteA" _
    '  (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, lpParameters As Any, _
    '  lpDirectory As Any, ByVal nShowCmd As Long) As Long ' <-*-*-*-*-*-*-*- non utilisé dans le code soumis -*-*-*-*-*-*-
    'Private Declare Function SHBrowseForFolder Lib "shell32" (lpbi As BrowseInfo) As Long ' <-*-*-*-*-*-*-*- non utilisé dans le code soumis -*-*-*-*-*-*-
    'Private Declare Function SHGetPathFromIDList Lib "shell32" (ByVal pidList As Long, _
    '    ByVal lpBuffer As String) As Long ' <-*-*-*-*-*-*-*- non utilisé dans le code soumis -*-*-*-*-*-*-
    'Private Declare Function lstrcat Lib "kernel32" Alias "lstrcatA" (ByVal lpString1 As String, _
    '    ByVal lpString2 As String) As Long ' <-*-*-*-*-*-*-*- non utilisé dans le code soumis -*-*-*-*-*-*-
    'Private Type BrowseInfo ' <-*-*-*-*-*-*-*- non utilisé dans le code soumis -*-*-*-*-*-*-
    '    hwndOwner As Long
    '    pIDLRoot As Long
    '    pszDisplayName As Long
    '    lpszTitle As Long
    '     ulFlags As Long
    '    lpfnCallback As Long
    '    lParam As Long
    '    iImage As Long
    'End Type
    'Private Declare Sub InitCommonControls Lib "comctl32.dll" () ' <-*-*-*-*-*-*-*- non utilisé dans le code soumis -*-*-*-*-*-*-
     
    Function FindAndReplace(ByVal strInString As String, strFindString As String, strReplaceString As String) As String
        Dim intPtr As Integer
            If Len(strFindString) > 0 Then 'catch if try to find empty string
                Do
                    intPtr = InStr(strInString, strFindString)
                    If intPtr > 0 Then
                        FindAndReplace = FindAndReplace & Left(strInString, intPtr - 1) & strReplaceString
                        strInString = Mid(strInString, intPtr + Len(strFindString))
                    End If
                Loop While intPtr > 0
            End If
        FindAndReplace = FindAndReplace & strInString
    End Function
     
    Sub Command1_Click()
    On Error GoTo error_handler
    ' -*-*-*-*-*-*-*- l'erreur commence ici car la variable était déclarée String alors que -*-*-*-*-
    ' -*-*-*-*-*-*-**-*-*-*-*-*-*- FreeFile renvoie un Integer -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
    F1 = FreeFile
    Tpath = App.Path & "\"
        With dlg
            .DialogTitle = "Select a file" 'titre de la boite
            .FileName = "*.*" 'on recherche un fichier d'extension txt
            .InitDir = "D:\LocalData\" 'repertoire par defaut
            .CancelError = True 'pour ne pas partir en erreur si on click sur annuler
            .ShowOpen
        End With
     
        Txtpath = dlg.FileName
        Txtname = dlg.FileTitle
        TailleReel = Len(Txtpath) - Len(Txtname)
        TxtDest = Left(Txtpath, TailleReel)
        Extension = Right(Txtname, 4)
        Txtnameshort = FindAndReplace(Txtname, Extension, "")
     
    'Creation du FI.bat
    ' -*-*-*-*-*-*-*- l'erreur était déclenché ici car la variable F1 était déclarée String -*-*-*-*-*-*-
    Open Tpath & "F1.bat" For Output As #F1
    Print #F1, "nconvert -out jpeg -dpi 300 -resize 1004 708 -o Phenix_" & Txtnameshort & ".jpg " & Txtname
    Close #F1
     
    'FileCopy Tpath & "nconvert.exe", TxtDest & "nconvert.exe"
    FileCopy Txtpath, Tpath & Txtname
     
    'Shell (Tpath & "F1.bat")' < -*-*- erreur de syntaxe
    Shell Tpath & "F1.bat"
     
    Exit Sub
    error_handler: ' récupère l'erreur renvoyer si l'utilisateur clique sur annulé
    If Err.Number = 32755 Then
        MsgBox "Please select a file"
        'Exit Sub ' <--------- inutile
    End If
    End Sub
    Après nettoyage, histoire d'y voire plus claire sur ton problème
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    Option Explicit
    Option Compare Text
     
    Public Path As String
    Public TailleReel As String
    Public Txtpath  As String, Tpath  As String, TxtDest  As String
    Public Txtname As String, Txtnameshort As String, Extension As String
    Public F1 As Integer
     
    Function FindAndReplace(ByVal strInString As String, strFindString As String, strReplaceString As String) As String
        Dim intPtr As Integer
            If Len(strFindString) > 0 Then 'catch if try to find empty string
                Do
                    intPtr = InStr(strInString, strFindString)
                    If intPtr > 0 Then
                        FindAndReplace = FindAndReplace & Left(strInString, intPtr - 1) & strReplaceString
                        strInString = Mid(strInString, intPtr + Len(strFindString))
                    End If
                Loop While intPtr > 0
            End If
        FindAndReplace = FindAndReplace & strInString
    End Function
     
    Sub Command1_Click()
    On Error GoTo error_handler
    F1 = FreeFile
    Tpath = App.Path & "\"
        With dlg
            .DialogTitle = "Select a file" 'titre de la boite
            .FileName = "*.*" 'on recherche un fichier d'extension txt
            .InitDir = "D:\LocalData\" 'repertoire par defaut
            .CancelError = True 'pour ne pas partir en erreur si on click sur annuler
            .ShowOpen
        End With
     
        Txtpath = dlg.FileName
        Txtname = dlg.FileTitle
        TailleReel = Len(Txtpath) - Len(Txtname)
        TxtDest = Left(Txtpath, TailleReel)
        Extension = Right(Txtname, 4)
        Txtnameshort = FindAndReplace(Txtname, Extension, "")
     
    'Creation du FI.bat
    Open Tpath & "F1.bat" For Output As #F1
    Print #F1, "nconvert -out jpeg -dpi 300 -resize 1004 708 -o Phenix_" & Txtnameshort & ".jpg " & Txtname
    Close #F1
     
    FileCopy Txtpath, Tpath & Txtname
    DoEvents
    Shell Tpath & "F1.bat"
     
    Exit Sub
    error_handler: ' recupere l'erreur renvoyer si l'utilisateur clique sur annulé
    If Err.Number = 32755 Then
        MsgBox "Please select a file"
    End If
    End Sub
    L'erreur survenant ligne 44 (en cause F1 déclaré String), de plus la syntaxe de la ligne 50 avait des parenthèses donc fausse, de fait déclenchement d'erreur et le branchement à la gestion d'erreur error_handler, ces 2 erreurs n'étant pas égal à 32755, aucun message informatif
    Lors d'un debug, penser à rémer toute gestion d'erreur, car cela masque les bugs.
    Soyez sympa, pensez -y
    Balises[CODE]...[/CODE]
    Balises[CODE=NomDuLangage]...[/CODE] quand vous mettez du code d'un autre langage que celui du forum ou vous postez.
    Balises[C]...[/C] code intégré dans une phrase.
    Balises[C=NomDuLangage]...[/C] code intégré dans une phrase quand vous mettez du code d'un autre langage que celui du forum ou vous postez.
    Le bouton en fin de discussion, quand vous avez obtenu l'aide attendue.
    ......... et pourquoi pas, pour remercier, un pour celui/ceux qui vous ont dépannés.
    👉 → → Ma page perso sur DVP ← ← 👈

  3. #3
    Futur Membre du Club
    Homme Profil pro
    Rédacteur technique
    Inscrit en
    Février 2017
    Messages
    5
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Yvelines (Île de France)

    Informations professionnelles :
    Activité : Rédacteur technique

    Informations forums :
    Inscription : Février 2017
    Messages : 5
    Points : 5
    Points
    5
    Par défaut
    merci bcp ProgElecT, je répond tardivement moi aussi dsl.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Fichier .bat pour ftp
    Par magnetyk dans le forum Windows
    Réponses: 7
    Dernier message: 15/09/2006, 15h31
  2. Réponses: 3
    Dernier message: 09/09/2006, 23h03
  3. [BAT] commande AT pour exécuter fichier .bat
    Par PatLogan dans le forum Scripts/Batch
    Réponses: 10
    Dernier message: 04/01/2005, 16h51
  4. Shell pour supprimer des lignes d'un fichier
    Par nelsa dans le forum Autres langages
    Réponses: 2
    Dernier message: 20/09/2004, 12h26

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo