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 :

[VBS] Liste Deroulante via (fichier init)


Sujet :

VBScript

  1. #1
    Membre averti
    Homme Profil pro
    RAS
    Inscrit en
    Mai 2008
    Messages
    27
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 49
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : RAS
    Secteur : Industrie

    Informations forums :
    Inscription : Mai 2008
    Messages : 27
    Par défaut [VBS] Liste Deroulante via (fichier init)
    Bonjour à tous,

    J'ai un projet personnel qui m'oriente vers le VBScript pour avancer.
    Je suis 100% débutant dans ce domaine, et j'ai grand besoin de votre aide SVP

    Voici mes premières ecritures:
    PS : ce sont des bouts de code copier dans ce site.

    Mon VBS : Module de lecture du 1er Fichier *.ini
    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
     
    ' Récupération des informations du fichier INI pour les associer dans leurs variables respectives.
     
    Const ForReading = 1
    Dim oFSO
    Set oFSO = WScript.CreateObject("Scripting.FileSystemObject" )
     
    FichierIni = "Config_T01.ini"
     
    Set lect = oFso.OpenTextFile(FichierIni, ForReading)
    	While Not lect.AtEndOfStream
    		Ligne = lect.ReadLine
    			propriete = Left(Ligne,InStrRev(Ligne,"="))
    			value = right(Ligne, len(Ligne) - len(Propriete))
    				if propriete = "Arbre01 =" Then Arb01 = value
    				if propriete = "Arbre02 =" Then Arb02 = value
    				if propriete = "Arbre03 =" Then Arb03 = value
    	Wend
     
    lect.close
     
    Dim MonText
    MonText = ("variable1 = " & Arb01 & vbCrLf & "variable2 = " & Arb02 & vbCrLf & "variable3 = " & Arb03)
     
     
    msgbox(MonText)

    mon premier problème :
    Je trouve pas comment crée une boucle sur : Ligne = lect.ReadLine
    Ceci pour avoir toutes les lignes à afficher sans modifier mon script...

    mon second problème :
    Je trouve pas comment crée une liste déroulante sur la valeur "ArbreXX" predifini si-dessus...

    mon troisième probleme :
    Afficher dans une boite de msg la correspondance : ArbreXX -> LienXX, de la valeur choisi si-dessus.


    mon 1er Fichier Config.ini
    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
     
    ; Fichier : Config_T01.ini
    ; Lien vers les paramètres des Arbres à créer
    ;
     
    Arbre01 = Arbre01.ini
    Lien01 = E:\Genealogie\Decoupages\VBScript\Arbre01.ini
     
    Arbre02 = Arbre02.ini
    Lien02 = E:\Genealogie\Decoupages\VBScript\Arbre01.ini
     
    Arbre03 = Arbre03.ini
    Lien03 = E:\Genealogie\Decoupages\VBScript\Arbre01.ini
     
    Arbre04 = Arbre04.ini
    Lien04 = E:\Genealogie\Decoupages\VBScript\Arbre01.ini
    Merci

  2. #2
    Expert éminent


    Profil pro
    Inscrit en
    Juin 2003
    Messages
    14 008
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2003
    Messages : 14 008
    Par défaut
    Bonjour,

    tu nous présente pour la deuxième fois ton projet complet ....

    essai de poser une seule question par message ... ainsi dans ce message je ne comprends pas ta question :

    mon premier problème :
    Je trouve pas comment crée une boucle sur :

    ?? il semble manquer des mots ....

  3. #3
    Membre averti
    Homme Profil pro
    RAS
    Inscrit en
    Mai 2008
    Messages
    27
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 49
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : RAS
    Secteur : Industrie

    Informations forums :
    Inscription : Mai 2008
    Messages : 27
    Par défaut
    Désoler bbil,

    je suis aller un peux vite...
    non ce n'est pas la deuxiémé fois.
    c'est le premier module : choix de départ.
    je corrige de suite mon poste.

    Merci de la remmarque

  4. #4
    Expert éminent


    Profil pro
    Inscrit en
    Juin 2003
    Messages
    14 008
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2003
    Messages : 14 008
    Par défaut
    ben je comprends pas la question ...

    tu as déjà une boucle avec ton While ?


    Le nombre d'Arbre est-il toujours 3 ? car la tu utilise 3 variables ...une par arbre ?

    si ce n'est pas le cas utilise plutôt un tableau

    ou un dictionnaire pour stocker les informations de tes arbres..

  5. #5
    Membre averti
    Homme Profil pro
    RAS
    Inscrit en
    Mai 2008
    Messages
    27
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 49
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : RAS
    Secteur : Industrie

    Informations forums :
    Inscription : Mai 2008
    Messages : 27
    Par défaut Boucle
    Bonjour bbil,
    merci de ton aide mais je débute depuis hier dans ce type de code.

    En fait je cherche à lister toutes les lignes du fichier *.ini comportant : Arbrexx = et à les afficher dans un msgbox
    --> Peux etre que mon fichier *.ini doit évoluer aussi.

    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
     
    ; Fichier : Config_T02.ini
    ; Lien vers les paramètres des Arbres à créer
    ;
     
    Arbre01 = Arbre01.ini
    Lien01 = E:\Genealogie\Decoupages\VBScript\Arbre01.ini
     
    Arbre02 = Arbre02.ini
    Lien02 = E:\Genealogie\Decoupages\VBScript\Arbre02.ini
     
    Arbre03 = Arbre03.ini
    Lien03 = E:\Genealogie\Decoupages\VBScript\Arbre03.ini
     
    Arbre04 = Arbre04.ini
    Lien04 = E:\Genealogie\Decoupages\VBScript\Arbre04.ini

  6. #6
    Membre averti
    Homme Profil pro
    RAS
    Inscrit en
    Mai 2008
    Messages
    27
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 49
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : RAS
    Secteur : Industrie

    Informations forums :
    Inscription : Mai 2008
    Messages : 27
    Par défaut MsgBox... au lieu d'une liste deroulantes...
    Re-bonjour BBIL,

    Je suis allé trop vite en te lisant, je tourne autour des models, depuis ce matin :

    Citation Envoyé par bbil Voir le message
    ben je comprends pas la question ...

    tu as déjà une boucle avec ton While ?
    Pour te répondre :
    - Oui j'ai cette boucle : "While Not lect.AtEndOfStream", mais je sais utiliser le comptage de ligne avec un paramétre... ex: "Arbrexx : "

    Citation Envoyé par bbil Voir le message
    Le nombre d'Arbre est-il toujours 3 ? car la tu utilise 3 variables ...une par arbre ?

    si ce n'est pas le cas utilise plutôt un tableau

    ou un dictionnaire pour stocker les informations de tes arbres..
    Pour te répondre :
    - En faite c'est mon fichier ini qui determine le nombre d'arbre, aujourd'hui je les ais decoupés en 7.
    - Oui j'en ai tois car c'est pour avoir une trame de travail...
    -> pour le stockage des infos j'avais justement pensé au fichier *.ini, comme ça mon code n'avais pas besoin d'etre retouché, seul le fichier *.ini et modifiable...
    -->> mon problémé c'est que je débute depuis hier soir, donc tout à aprendre !!!
    -->> Du coup je sais pas si ta solution et bien adapté (tableau ou dictionnaire)


    En cherchant je me rend compte qu'un menu deroulant n'est pas possible en VBS!!!
    Mais peux etre avec un Msgbox (Voir fichier joint)...
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    value1=InputBox("Choisi le numéro (deux carractéres) de l'arbre à traiter" & vbCrLf & "01 - Arbre_01" & vbCrLf & "02 - Arbre_02","Choix d'arbre à traiter","00" & vbCrLf & "etc...")
     
    Dim MonChoix
    MonChoix = ("Arbre" & value1)
    Wscript.Echo MonChoix
    Je pensé faire de la variable : 'MonChoix' une concatenation de toutes les valeurs touvé dans le fichier *.ini, si possible bien sur ???
    Mais je trouve pas comment faire
    Images attachées Images attachées  

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

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Juin 2009
    Messages : 3 843
    Par défaut
    un petit exemple pour créer une liste déroulante dynamique
    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
    Choix = ChooseOne("01 - Arbre_01,02 - Arbre_02,03 - Arbre_03,04 - Arbre_04,04 - Arbre_04,05 - Arbre_05,06 - Arbre_06,07 - Arbre_07,08 - Arbre_08")
    MsgBox "Vous avez choisi " & Choix,64,"Votre Choix"
    Function ChooseOne(Limiteparvirgule)
    'Returns one of several string choices. 
    'Returns empty string if there is a problem.
    Dim fs, web, doc
    Dim strFile, strChoice
    Dim intChars
    Dim dtTime
        On Error Resume Next
        Set web = CreateObject("InternetExplorer.Application")
        If web Is Nothing Then
            ChooseOne = ""
            Exit Function
        End If
        'Increase displayed width to accomodate longest string choice
        intChars = 0
        For Each strChoice In Split(Limiteparvirgule,",")
            If Len(strChoice) > intChars Then intChars = Len(strChoice)
        Next
        If intChars > 20 Then
            web.Width = 250 + 6 * (intChars - 20)
        Else
            web.Width = 250
        End If
        web.Height = 200
        web.Offline = True
        web.AddressBar = False
        web.MenuBar = False
        web.StatusBar = False
        web.Silent = True
        web.ToolBar = False
        web.Navigate "about:blank"
        'Wait for the browser to navigate to nowhere
        dtTime = Now
        Do While web.Busy
            'Don't wait more than 5 seconds
            Wscript.Sleep 100
            If (dtTime + 5/24/60/60) < Now Then
                ChooseOne = ""
                web.Quit
                Exit Function
            End If
        Loop
        'Wait for a good reference to the browser document
        Set doc = Nothing
        dtTime = Now
        Do Until Not doc Is Nothing
            Wscript.Sleep 100
            Set doc = web.Document
            'Don't wait more than 5 seconds
            If (dtTime + 5/24/60/60) < Now Then
                ChooseOne = ""
                web.Quit
                Exit Function
            End If
        Loop
        'Write the HTML form
        doc.Write "<html><head><title>Choose</title></head>"
        doc.Write "<body><b>Choose One:</b><br><form><select name=""choice"">"
        For Each strChoice In Split(Limiteparvirgule,",")
            doc.Write "<option value=""" & strChoice & """>" & strChoice
        Next
        doc.Write "</select>"
        doc.Write "<br><br><input type=button "
        doc.Write "name=submit "
        doc.Write "value=""OK"" onclick='javascript:submit.value=""Done""'>"
        doc.Write "</form></body></html>"
        'Show the form
        web.Visible = True
        'Wait for the user to choose, but fail gracefully if a popup killer.
        Err.Clear
        Do Until doc.Forms(0).elements("submit").Value <> "OK"
            Wscript.Sleep 100
            If doc Is Nothing Then
                ChooseOne = ""
                web.Quit
                Exit Function
            End If
            If Err.Number <> 0 Then
                ChooseOne = ""
                web.Quit
                Exit Function
            End If
        Loop
        'Retrieve the chosen value
        ChooseOne = doc.Forms(0).elements("choice").Value
        web.Quit
    End Function
    Source : http://www.ericphelps.com/scripting/...HTA/Choose.txt

  8. #8
    Membre averti
    Homme Profil pro
    RAS
    Inscrit en
    Mai 2008
    Messages
    27
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 49
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : RAS
    Secteur : Industrie

    Informations forums :
    Inscription : Mai 2008
    Messages : 27
    Par défaut :ccool:
    Bonjour hackoofr,

    superbe ce lien et le bout du code!
    Je vais voir si j'arrive a bien le comprendre avant d'aller plus loin...
    Merci beaucoup de votre aide


    Voici le code complet, reste à le nettoyer un peux...
    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
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    msgbox("Début de JojoSs DEV...")
    ' Récupération des informations du fichier INI pour les associer dans leurs variables respectives.
     
    Const ForReading = 1
    Dim oFSO
    Set oFSO = WScript.CreateObject("Scripting.FileSystemObject" )
     
    ' Définitions du fichier *.ini pour la lecture des paramètres.
    Dim FichierIni
    FichierIni = "Config_T04.ini"
     
    Set lect = oFso.OpenTextFile(FichierIni, ForReading)
    	Count = 0
    	lig = 1
    	Message1 = ""
    	msgbox("Count => " & Count)
    	While Not lect.AtEndOfStream
    		Ligne = lect.ReadLine
    			Propriete = "[" & Left(Ligne,InStrRev(Ligne,"["))
    				Propriete1 = "faux"
    				If Propriete = "[[" then Propriete1 = "Vrais" Else
    			Value1 = right( Ligne, len(Ligne) )
    			Value2 = "[Arb" & Count & "]"
    				if Propriete1 = "Vrais" Then if Message1 ="" then Message1 = ( Count & " - " & Value2 ) else Message1 = ( Message1 & ", " & Count & " - " & Value2 )
    ' Choix = ChooseOne("01 - Arbre_01,02 - Arbre_02,03 - Arbre_03,04 - Arbre_04,04 - Arbre_04,05 - Arbre_05,06 - Arbre_06,07 - Arbre_07,08 - Arbre_08")
    '				msgbox("Message1 => " & Message1)
     
    		if Value1 = Value2 Then Count = Count+1
    		Lig = lig+1
    	Wend
    lect.close
     
     
     
     
     
    				msgbox("Message1 => " & Message1)
     
     
    'Choix = ChooseOne("01 - Arbre_01,02 - Arbre_02,03 - Arbre_03,04 - Arbre_04,04 - Arbre_04,05 - Arbre_05,06 - Arbre_06,07 - Arbre_07,08 - Arbre_08")
    Choix = ChooseOne(Message1)
    MsgBox "Vous avez choisi " & Choix,64,"Votre Choix"
     
     
    Function ChooseOne(Limiteparvirgule)
    ' Returns one of several string choices.
    '	Retourne l'un des choix de chaînes.
    ' Returns empty string if there is a problem.
    '	Retourne une chaîne vide si il ya un problème.
    Dim fs, web, doc
    Dim strFile, strChoice
    Dim intChars
    Dim dtTime
     
    	On Error Resume Next
    	Set web = CreateObject("InternetExplorer.Application")
    	If web Is Nothing Then
    		ChooseOne = ""
    		Exit Function
    	End If
     
    	'Increase displayed width to accomodate longest string choice
    	'	Augmenter la largeur d'affichage pour accueillir plus longue choix de chaîne
    	intChars = 0
    	For Each strChoice In Split(Limiteparvirgule,",")
    		If Len(strChoice) > intChars Then intChars = Len(strChoice)
    	Next
    	If intChars > 20 Then
    		web.Width = 250 + 6 * (intChars - 20)
    	Else
    		web.Width = 250
    	End If
     
    	web.Height = 200
    	web.Offline = True
    	web.AddressBar = False
    	web.MenuBar = False
    	web.StatusBar = False
    	web.Silent = True
    	web.ToolBar = False
    	web.Navigate "about:blank"
    	'Wait for the browser to navigate to nowhere
    	dtTime = Now
     
    	Do While web.Busy
    		'Don't wait more than 5 seconds
    		Wscript.Sleep 100
    		If (dtTime + 5/24/60/60) < Now Then
    			ChooseOne = ""
    			web.Quit
    			Exit Function
    		End If
    	Loop
     
    	'Wait for a good reference to the browser document
    	Set doc = Nothing
    	dtTime = Now
    	Do Until Not doc Is Nothing
    		Wscript.Sleep 100
    		Set doc = web.Document
    		'Don't wait more than 5 seconds
    		If (dtTime + 5/24/60/60) < Now Then
    			ChooseOne = ""
    			web.Quit
    			Exit Function
    		End If
    	Loop
     
    	'Write the HTML form
    	doc.Write "<html><head><title>Choose</title></head>"
    	doc.Write "<body><b>Votre Choix :</b><form><select name=""choice"">"
    '	doc.Write "<body><b>Votre Choix :</b><br><form><select name=""choice"">"
    	For Each strChoice In Split(Limiteparvirgule,",")
    		doc.Write "<option value=""" & strChoice & """>" & strChoice
    	Next
    	doc.Write "</select>"
    	doc.Write "<br><br><input type=button "
    	doc.Write "name=submit "
    	doc.Write "value=""OK"" onclick='javascript:submit.value=""Done""'>"
    	doc.Write "</form></body></html>"
    	'Show the form
    	web.Visible = True
    	'Wait for the user to choose, but fail gracefully if a popup killer.
    	Err.Clear
     
    	Do Until doc.Forms(0).elements("submit").Value <> "OK"
    		Wscript.Sleep 100
    		If doc Is Nothing Then
    			ChooseOne = ""
    			web.Quit
    			Exit Function
    		End If
    		If Err.Number <> 0 Then
    			ChooseOne = ""
    			web.Quit
    			Exit Function
    		End If
    	Loop
     
    	'Retrieve the chosen value
    	ChooseOne = doc.Forms(0).elements("choice").Value
    	web.Quit
    End Function
    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
    [Arb00]
    Arbre = Arbre00.ini
    Lien = E:\Genealogie\Decoupages\VBScript\Arbre00.ini
     
    [Arb01]
    Arbre = Arbre01.ini
    Lien = E:\Genealogie\Decoupages\VBScript\Arbre01.ini
     
    [Arb02]
    Arbre = Arbre02.ini
    Lien = E:\Genealogie\Decoupages\VBScript\Arbre02.ini
     
    [Arb03]
    Arbre = Arbre03.ini
    Lien = E:\Genealogie\Decoupages\VBScript\Arbre03.ini

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

Discussions similaires

  1. Réponses: 1
    Dernier message: 24/08/2013, 21h58
  2. alimenter une liste deroulante via un popup
    Par mitch46000 dans le forum Général JavaScript
    Réponses: 2
    Dernier message: 27/04/2007, 11h40
  3. Réponses: 1
    Dernier message: 06/12/2006, 18h25
  4. PHP Passer une variable via une liste deroulante
    Par lepierre dans le forum Langage
    Réponses: 3
    Dernier message: 20/10/2006, 12h09
  5. [VBS] Liste de fichiers sur un repertoire
    Par sebos63 dans le forum VBScript
    Réponses: 3
    Dernier message: 08/02/2006, 18h13

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