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 :

Liste deroulante avec fichier txt


Sujet :

VBScript

  1. #1
    Membre du Club
    Inscrit en
    Juillet 2012
    Messages
    50
    Détails du profil
    Informations forums :
    Inscription : Juillet 2012
    Messages : 50
    Points : 42
    Points
    42
    Par défaut Liste deroulante avec fichier txt
    Bonjour

    J'ai une petite question, surtout un problème
    je souhaiterais faire une liste déroulante a partir d'un fichier txt
    ce fichier txt contiendrait une liste du genre:

    toto
    tata
    titi
    tutu

    je souhaiterait que lorsque titi est sélectionner dans la liste déroulante par un bouton OK
    pouvoir récupérer titi dans une variable pour lancer une commande du genre

    dwrcc.exe -m:titi



    avec mes remerciements

  2. #2
    Membre averti
    Homme Profil pro
    Administrateur systèmes et réseaux
    Inscrit en
    Novembre 2011
    Messages
    163
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Administrateur systèmes et réseaux
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Novembre 2011
    Messages : 163
    Points : 304
    Points
    304
    Par défaut
    Salut yoyo-tns !

    Voici un exemple (vite fait) pour t'exposer le principe.

    Liste.txt
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    toto
    tata
    titi
    tutu
    Fichier.hta
    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
    <head>
    <title>MonTitre</title>
    <HTA:APPLICATION
    APPLICATION="Liste déroulante"
    BORDER="thin"
    SCROLL="no"
    SINGLEINSTANCE="no"
    WINDOWSTATE="normal">
    </head>
    <script language="VBScript">
    	Sub Window_onLoad
    	Me.ResizeTo 100,150
    	Me.MoveTo ((Screen.Width / 2) - 200),((Screen.Height / 2) - 150)
    	Dim Valeur(), oFSO
    	Liste = "./Liste.txt"
    	Set oFSO = CreateObject("Scripting.FileSystemObject")
    	Set lect = oFSO.OpenTextFile(Liste, 1)
    	Set oFl = oFSO.GetFile(Liste)
    	ts = lect.ReadAll
    	Nbr_Valeurs = lect.Line -1
    	Redim Valeurs(Nbr_Valeurs)
    	lect.close
    	Set lect = oFSO.OpenTextFile(Liste, 1)
    	i = 0
    	while Not lect.AtEndOfStream
    	Valeurs(i) = lect.Readline
    	i = i + 1
    	Wend
    	lect.Close
    	For i = 0 to Nbr_Valeurs
    	Set oOption = Document.createElement("OPTION")
    	oOption.Text = Valeurs(i)
    	oOption.Value = Valeurs(i)
    	Liste_Valeurs.Add(oOption)
    	Next
    	End Sub
     
    	Sub Clic_OnClick
    	MsgBox Liste_Valeurs.Value
    	End Sub
    </script>
    <body STYLE="font:12 pt calibri; color:white;filter:progid:DXImageTransform.Microsoft.Gradient
    (GradientType=1, StartColorStr='#000033', EndColorStr='#0000FF')">
    </SELECT>
    <SELECT NAME="Liste_Valeurs" SIZE=1>
    </SELECT></p>
    <p align="left"><input type="button" value="Clic_Me" name="Clic"></p>
    </body>
    ++

  3. #3
    Expert éminent
    Avatar de hackoofr
    Homme Profil pro
    Enseignant
    Inscrit en
    Juin 2009
    Messages
    3 840
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 49
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Juin 2009
    Messages : 3 840
    Points : 9 225
    Points
    9 225
    Par défaut

    J'ai modifié un peu depuis un ancien projet :

    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
    108
    <html>
    <head>
    <title>Create a dynamic listbox from file by Hackoo</title>
    <HTA:APPLICATION 
    ID="IPTV"
    APPLICATIONNAME="IPTV"
    SCROLL="no"
    ICON="Winver.exe"
    SINGLEINSTANCE="yes"
    WINDOWSTATE="maximize"
    >
    <style>
    body {
    color:white;
    background-color:lightblue;
    background-image:url(http://financialtribune.com/sites/default/files/field/image/11_IRIB.jpg);
    background-repeat:repeat;
    background-size: 100%;
    }
     
    select{
    margin:0px;
    padding:0px;
    background: lightblue;
    color:#000H;
    text-shadow:0 1px 0 rgba(0,0,0,0.4);
    }
    option:not(:checked) { 
    background-color: #FFF0; 
    }    
     
    Span
            {
     
                border:2px solid lightblue;
                background-color:Red;
                display: inline;
            }
            Span:hover
            {
                background-color:fuchsia;
                Cursor:hand;
            }
    </style>
    </head>
    <body> 
        <script type="text/vbscript">
        Sub Window_OnLoad()
        Dim MyFile
        MyFile = "List.txt"
            Call LoadFile(MyFile)
        End Sub
        '**********************************************************************************************
    Sub LoadFile(strFile)
        Const ForReading = 1
        Const ForWriting = 2
        Call ClearListbox()
        Dim fso,f,i,Count,Title
        Title = "Create a dynamic listbox from file by Hackoo"
        Set fso = CreateObject("Scripting.FileSystemObject")
        If Not fso.FileExists(strFile) Then 
            MsgBox "Erreur "& vbcr & "Vérifier si le fichier "& DblQuote(strFile) & " existe ?",VbCritical,Title
            Exit Sub
        End If
        Count = 0
            Set f = fso.OpenTextFile(strFile,ForReading)
            Do Until f.AtEndOfStream
                strLine = f.Readline
                strLine = Trim(strLine)
                If Len(strLine) > 0 Then
                    strNewContents = strNewContents & strLine & vbCrLf
                End If
            Loop
            f.Close
            Tab = split(strNewcontents,vbcrlf)
            For i = lbound(Tab) to ubound(Tab) 
                    Count = Count + 1
                    Set objOption = Document.createElement("OPTION")
                    objOption.Text = Count & " - " & Tab(i)
                    k = i+1
                    If k > UBound(tab) Then Exit For
                    objOption.Value = Tab(i)
                    List.Add(objOption)        
            Next
    End Sub
    '***********************************************************************************************
    Sub ClearListbox()
        For Each objOption in List.Options
            objOption.RemoveNode
        Next 
    End Sub
    '**********************************************************************************************
    Function DblQuote(Str)
        DblQuote = Chr(34) & Str & Chr(34)
    End Function
    '**********************************************************************************************
    Sub Run()
    Dim Command
        Command = "dwrcc.exe -m:"
        Msgbox Command & List.Value
    End Sub
    '**********************************************************************************************
        </script>
        <center><select size="1" name="List"></select><br><br>
        <input type="Button" name="submit" Value="Exécuter" onclick='Run()'>
        </center>
    </body>
    </html>

  4. #4
    Membre du Club
    Inscrit en
    Juillet 2012
    Messages
    50
    Détails du profil
    Informations forums :
    Inscription : Juillet 2012
    Messages : 50
    Points : 42
    Points
    42
    Par défaut
    Bonjour CachLab,

    je rame complètement, mais ou je défini ma commande

    dwrcc.exe -m: ( variable )


    Merci pour ton aide

  5. #5
    Membre du Club
    Inscrit en
    Juillet 2012
    Messages
    50
    Détails du profil
    Informations forums :
    Inscription : Juillet 2012
    Messages : 50
    Points : 42
    Points
    42
    Par défaut
    Bonjour hackoofr

    cela fonctionne parfaitement merci

    J'ai juste une question sur l'exécution du fichier dwrcc.exe, le fichier HTA et le fichier liste.txt se trouvent au même endroit
    pourtant il ne s'exécute pas.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
      Function DblQuote(Str)
        DblQuote = Chr(69) & Str & Chr(69)
    End Function
    '**********************************************************************************************
    Sub Run()
    Dim Command
        Command = "dwrcc.exe -c: -v: -u:frsofly-admin -p:*Mazter2004 -m:"
        Msgbox Command & List.Value
    End Sub
    Merci pour votre aide

  6. #6
    Expert éminent
    Avatar de hackoofr
    Homme Profil pro
    Enseignant
    Inscrit en
    Juin 2009
    Messages
    3 840
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 49
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Juin 2009
    Messages : 3 840
    Points : 9 225
    Points
    9 225
    Par défaut
    Citation Envoyé par yoyo-tns Voir le message
    Bonjour hackoofr

    cela fonctionne parfaitement merci

    J'ai juste une question sur l'exécution du fichier dwrcc.exe, le fichier HTA et le fichier liste.txt se trouvent au même endroit
    pourtant il ne s'exécute pas.

    Function DblQuote(Str)
    DblQuote = Chr(69) & Str & Chr(69)
    End Function
    '**********************************************************************************************
    Sub Run()
    Dim Command
    Command = "dwrcc.exe -c: -v: -u:frsofly-admin -p:*Mazter2004 -m:"
    Msgbox Command & List.Value
    End Sub

    Merci pour votre aide
    Oui, il ne s'exécute pas car juste c'est un Msgbox pour vérifier toi-même si la syntaxe est bonne ou non ?

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    Sub Run()
    Dim Command,ws
        set ws = CreateObject("wscript.shell")
        Command = "dwrcc.exe -c: -v: -u:frsofly-admin -p:*Mazter2004 -m:"
        Msgbox Command & List.Value
        ws.run Command & List.Value
    End Sub
    http://support.dameware.com/kb/article.aspx?ID=300002

  7. #7
    Membre du Club
    Inscrit en
    Juillet 2012
    Messages
    50
    Détails du profil
    Informations forums :
    Inscription : Juillet 2012
    Messages : 50
    Points : 42
    Points
    42
    Par défaut
    Super


    Un grand merci pour votre aide

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

Discussions similaires

  1. Réponses: 3
    Dernier message: 05/05/2006, 03h05
  2. Importer des donnees avec fichier txt
    Par flOZ dans le forum Requêtes
    Réponses: 8
    Dernier message: 21/04/2006, 17h26
  3. Zone de liste deroulante avec preselection précise
    Par dynexd dans le forum Access
    Réponses: 7
    Dernier message: 20/02/2006, 17h25
  4. Liste deroulante avec Zone de texte associée
    Par ahage4x4 dans le forum ASP
    Réponses: 7
    Dernier message: 26/05/2005, 12h19
  5. liste deroulante avec plusieurs champs
    Par JulienT dans le forum Struts 1
    Réponses: 4
    Dernier message: 20/04/2004, 17h17

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