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

VBScript Discussion :

Equivalence Goto en VBS


Sujet :

VBScript

  1. #1
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Octobre 2006
    Messages
    79
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2006
    Messages : 79
    Points : 30
    Points
    30
    Par défaut Equivalence Goto en VBS
    Bonjour,

    Y a t il une commande equivalente a goto en VBS

    merci

  2. #2
    Expert confirmé
    Avatar de pc75
    Profil pro
    Inscrit en
    Septembre 2004
    Messages
    3 662
    Détails du profil
    Informations personnelles :
    Âge : 68
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Septembre 2004
    Messages : 3 662
    Points : 4 047
    Points
    4 047
    Par défaut
    Bonjour,

    Il faudrait que tu sois plus précis. Tu veux faire quoi exactement ?

  3. #3
    Expert confirmé
    Avatar de ced600
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Août 2006
    Messages
    3 364
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Août 2006
    Messages : 3 364
    Points : 4 061
    Points
    4 061
    Par défaut
    Le goto est à bannir des codes !!!
    Pourquoi faire compliqué lorsque l'on peut faire encore plus compliqué.

  4. #4
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Octobre 2006
    Messages
    79
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2006
    Messages : 79
    Points : 30
    Points
    30
    Par défaut
    Voila mon code

    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
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    Dim ETAT_SERVICE
    Dim WIN_SERVICE1
     
    Set FSO = CreateObject("Scripting.FileSystemObject")
    On Error Resume Next
     
    Set Ftxt = FSO.CreateTextFile("D:\production\home\tws\log\SYS_LOG_systeme.log", False)
     
    Function getSystemVar(VarName)
        Dim wss, env
        Set wss = CreateObject("WScript.Shell")
        Set env = wss.environment("process")
        getSystemVar = env(VarName)
    End Function
     
    Dim objWMIService, objItem, objService
    Dim colListOfServices, strComputer, intSleep
    strComputer = "."
    intSleep = 5000
     
    Set args  = Wscript.Arguments
    ETAT_SERVICE = args(0) 
    WIN_SERVICE1 = args(1)
     
    message = "The service" & (WIN_SERVICE1)  & "is in state :" & (ETAT_SERVICE)
     
    Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" _
    & strComputer & "\root\cimv2")
    Set colListOfServices = objWMIService.ExecQuery _
    ("Select * from Win32_Service Where Name ="_
    & WIN_SERVICE1 & " ")
    For Each objService in colListOfServices
     
     
     
    If (ETAT_SERVICE) <> "Startservice" and (ETAT_SERVICE) <> "Stopservice" Then
     
    parametre = "Parametre Invalide"
    If Err.Number = 0 Then 'Fichier Log n'existe pas
      Set Ftxt = FSO.GetFile("D:\production\home\tws\log\SYS_LOG_systeme.log") 
      Set FtxtBis = Ftxt.OpenAsTextStream(8, -2)
      FtxtBis.writeline (parametre)
      FtxtBis.Close 
      Set FtxtBis = Nothing
      Ftxt.Close 
      Set Ftxt = Nothing
     
    Else 'Fichier log existe
      Set Ftxt = FSO.CreateTextFile("D:\production\home\tws\log\SYS_LOG_systeme.log", False)
      Set Ftxt = FSO.GetFile("D:\production\home\tws\log\SYS_LOG_systeme.log") 
      Set FtxtBis = Ftxt.OpenAsTextStream(8, -2) 
      FtxtBis.writeline (parametre)
      FtxtBis.Close 'Fermeture
      Set FtxtBis = Nothing
      Ftxt.Close
      Set Ftxt = Nothing
    End If
    FSO.Close
     
    end if
     
     
    If (ETAT_SERVICE) = "Startservice" Then
      return = objService.StartService(WIN_SERVICE1)
          if Return = 5 then
             Return = 0
          else 
             if Return = 10 then
                Return = 0
             end if
          end if
      Else If (ETAT_SERVICE) = "Stopservice" Then
       return = objService.StopService(WIN_SERVICE1)
          if Return = 5 then
             Return = 0
          else 
             if Return = 10 then
                Return = 0
             end if
          end if
     End If
    End If
     
    WSCript.Sleep intSleep
    Next
     
    If Err.Number = 0 Then 'Fichier Log n'existe pas
      Set Ftxt = FSO.GetFile("D:\production\home\tws\log\SYS_LOG_systeme.log") 
      Set FtxtBis = Ftxt.OpenAsTextStream(8, -2)
      FtxtBis.writeline (Year(date)) & vbTab & (Month(date)) & vbTab & (Day(date)) & vbTab & (time) & vbTab & (getSystemVar("COMPUTERNAME")) & vbTab & resultat1 & vbTab & resultat2 & vbTab & (PID) & vbTab & (terminal) & vbTab & resultat5 & vbTab & resultat4 & vbTab & return & vbTab & (gravite) & vbTab & resultat3 & vbTab & (getSystemVar("UNISON_JOBNUM")) & vbTab & (valeur) & vbTab &(parametre) & vbTab & (message)
      FtxtBis.Close 
      Set FtxtBis = Nothing
      Ftxt.Close 
      Set Ftxt = Nothing
     
    Else 'Fichier log existe
      Set Ftxt = FSO.CreateTextFile("D:\production\home\tws\log\SYS_LOG_systeme.log", False)
      Set Ftxt = FSO.GetFile("D:\production\home\tws\log\SYS_LOG_systeme.log") 
      Set FtxtBis = Ftxt.OpenAsTextStream(8, -2) 
      FtxtBis.writeline (Year(date)) & vbTab & (Month(date)) & vbTab & (Day(date)) & vbTab & (time) & vbTab & (getSystemVar("COMPUTERNAME")) & vbTab & resultat1 & vbTab & resultat2 & vbTab & (PID) & vbTab & (terminal) & vbTab & resultat5 & vbTab & resultat4 & vbTab & return & vbTab & (gravite) & vbTab & resultat3 & vbTab & (getSystemVar("UNISON_JOBNUM")) & vbTab & (valeur) & vbTab &(parametre)& vbTab & (message)
      FtxtBis.Close 'Fermeture
      Set FtxtBis = Nothing
      Ftxt.Close
      Set Ftxt = Nothing
    End If
    FSO.Close
    Ce que je veux faire c'est la chose suivante:

    Lorsque je teste mon parametre et que celui ci est pas bon je veux qu il ecrive dans mon fichier "parametre invalide" sinon qu il ecrive les valeurs recuperées.
    Sur ce script j arrive a ecrire ce que je veux maisle soucis est qu il m ecrit les ligne en double lorsque la commande est bonne.
    Voici mon resultat
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    2006 11 16 14:03:34	Parametre Invalide The Service 'Alerter'is in state :StopService
    2006 11 16 14:03:49 0 The service 'Alerter' is in state :Startservice
    Normalement j aurais du avoir une ligne d'ecrite.

    Merci de m aider

  5. #5
    Expert confirmé
    Avatar de ced600
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Août 2006
    Messages
    3 364
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Août 2006
    Messages : 3 364
    Points : 4 061
    Points
    4 061
    Par défaut
    Sinon en VBS, le goto est utilisé pour la gestion des erreurs.
    Pourquoi faire compliqué lorsque l'on peut faire encore plus compliqué.

  6. #6
    Expert confirmé
    Avatar de ced600
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Août 2006
    Messages
    3 364
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Août 2006
    Messages : 3 364
    Points : 4 061
    Points
    4 061
    Par défaut
    Heu...
    pkoi veut tu te servir du goto ?
    Pourquoi faire compliqué lorsque l'on peut faire encore plus compliqué.

  7. #7
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Octobre 2006
    Messages
    79
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2006
    Messages : 79
    Points : 30
    Points
    30
    Par défaut
    Je ne veux pas forcement utiliser le goto mais je veux que dans l ecriture de la log il n 'y ait qu'une seul fois l'ecriture et pas 2 fois.

    Merci

  8. #8
    Expert confirmé
    Avatar de ced600
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Août 2006
    Messages
    3 364
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Août 2006
    Messages : 3 364
    Points : 4 061
    Points
    4 061
    Par défaut
    Bah si tu ne veux rentrer qu'une seul fois dans ta condition, tu l'encadre avec uen autre condition. Du genre et tu positionnes compteur à 1 lorsque tu rentre pour la première fois dans ta condition.
    Pourquoi faire compliqué lorsque l'on peut faire encore plus compliqué.

  9. #9
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Octobre 2006
    Messages
    79
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2006
    Messages : 79
    Points : 30
    Points
    30
    Par défaut
    Excuse moi mais je vois pas comment faire et je vois pas ou le mettre.

    Merci

  10. #10
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Octobre 2006
    Messages
    79
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2006
    Messages : 79
    Points : 30
    Points
    30
    Par défaut
    Je me suis peut etre mal exprimé. En faite je voudrais remplir le fichier log en fonction du parametre que je rentre.

    C'est a dire si (ETAT_SERVICE) est ok alors il ecrit le fichier de log normalement est il stop.
    Par contre si (ETAT_SERVICE) not ok il rentre seulement dans la condition

    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
    If (ETAT_SERVICE) <> "Startservice" and (ETAT_SERVICE) <> "Stopservice" Then
     
    parametre = "Parametre Invalide"
    If Err.Number = 0 Then 'Fichier Log n'existe pas
      Set Ftxt = FSO.GetFile("D:\production\home\tws\log\SYS_LOG_systeme.log") 
      Set FtxtBis = Ftxt.OpenAsTextStream(8, -2)
      FtxtBis.writeline (parametre)
      FtxtBis.Close 
      Set FtxtBis = Nothing
      Ftxt.Close 
      Set Ftxt = Nothing
     
    Else 'Fichier log existe
      Set Ftxt = FSO.CreateTextFile("D:\production\home\tws\log\SYS_LOG_systeme.log", False)
      Set Ftxt = FSO.GetFile("D:\production\home\tws\log\SYS_LOG_systeme.log") 
      Set FtxtBis = Ftxt.OpenAsTextStream(8, -2) 
      FtxtBis.writeline (parametre)
      FtxtBis.Close 'Fermeture
      Set FtxtBis = Nothing
      Ftxt.Close
      Set Ftxt = Nothing
    End If
    FSO.Close
     
    end if
    j espere ete un peu plus claire

    merci

  11. #11
    Expert confirmé
    Avatar de ced600
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Août 2006
    Messages
    3 364
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Août 2006
    Messages : 3 364
    Points : 4 061
    Points
    4 061
    Par défaut
    tu veut sortir de koi, de la boucle ? dans ce cas met un Exit For.
    Pourquoi faire compliqué lorsque l'on peut faire encore plus compliqué.

  12. #12
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Octobre 2006
    Messages
    79
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2006
    Messages : 79
    Points : 30
    Points
    30
    Par défaut
    Merci a toi pour ta reponse mais c ok j'ai resolu le probleme.

    Si quelqu'un veux le code je vous le met

  13. #13
    Modérateur
    Avatar de AlainTech
    Homme Profil pro
    Consultant informatique
    Inscrit en
    Mai 2005
    Messages
    4 235
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 70
    Localisation : Belgique

    Informations professionnelles :
    Activité : Consultant informatique
    Secteur : Finance

    Informations forums :
    Inscription : Mai 2005
    Messages : 4 235
    Points : 24 327
    Points
    24 327
    Par défaut
    Ben, c'est un peu la notion d'échange qu'on attend des utilisateurs d'un forum.

    Rien de plus frustrant, pour quelqu'un qui cherche une réponse à un problème similaire, que (en voyant le tag Résolu) de parcourir toute une discussion pour se rendre compte que la solution n'est pas au bout.
    N'oubliez pas de cliquer sur quand vous avez obtenu ou trouvé vous-même la réponse à votre question.
    Si vous trouvez seul, pensez à poster votre solution. Elle peut servir à d'autres!
    Pensez aussi à voter pour les réponses qui vous ont aidés.
    ------------
    Je dois beaucoup de mes connaissances à mes erreurs!

  14. #14
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Octobre 2006
    Messages
    79
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2006
    Messages : 79
    Points : 30
    Points
    30
    Par défaut
    Voila la solution

    il faut mettre WScript.Quit en fin de script pour le forcer a sortir

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

Discussions similaires

  1. Equivalent de ShowModalDialog pour un VBS
    Par papyxy dans le forum VBScript
    Réponses: 6
    Dernier message: 23/11/2012, 15h58
  2. Equivalent "On Cancel GoTo"???
    Par Monfy29 dans le forum Macros et VBA Excel
    Réponses: 10
    Dernier message: 31/03/2010, 10h06
  3. equivalent de goto dans access
    Par Skizo dans le forum Access
    Réponses: 3
    Dernier message: 12/05/2006, 15h22
  4. [VBS] Redirection (équivalent Goto ms-dos)
    Par Edoxituz dans le forum VBScript
    Réponses: 8
    Dernier message: 23/02/2006, 20h14
  5. Equivalent de Left() de VBS en PHP
    Par mioux dans le forum Langage
    Réponses: 2
    Dernier message: 09/12/2005, 15h15

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