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 :

Passage de variables dans une procédure ?


Sujet :

VBScript

  1. #1
    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 Passage de variables dans une procédure ?

    Je suis entrain d’écrire un vbscript pour qu'il me fasse un petit popup avec une image localisée sur mon disque dur.
    Donc, je dois connaitre les dimensions (Largeur x Hauteur) de cette dernière pour les passer à une procédure pour qu'elle les prenne automatiquement en charge .
    mais hélas, je rencontre une erreur de ce type :
    Ligne : 39
    Carct : 2
    Erreur : Argument ou appel de procédure incorrect
    Code : 800A0005
    Source : Erreur d'exécution Microsoft vbscript
    Voici le bout de 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
    Option Explicit
    Dim ws,fso,Srcimage,Temp,PathOutPutHTML,fhta,stRep,stFichier,oShell,oFolder,oFichier,Dimensions,W,H
    Set ws = CreateObject("wscript.Shell")
    Set fso = CreateObject("Scripting.FileSystemObject")
    Temp = WS.ExpandEnvironmentStrings("%Temp%")
    PathOutPutHTML = Temp & "\image.hta"
    Set fhta = fso.OpenTextFile(PathOutPutHTML,2,True)
    stRep="E:\HackooTest"
    stFichier ="MDR.gif"
    Set oShell = CreateObject("Shell.Application")
    Set oFolder = oShell.Namespace(stRep)
    Set oFichier = oFolder.Items.Item(stFichier)
    Dimensions = oFolder.GetDetailsOf(oFichier,31)
    Dimensions = Split(Dimensions,"x")
    W = Trim(Dimensions(0))
    H = Trim(Dimensions(1))
    msgbox "Largeur de l'image est " & W 
    msgbox "La hauteur de l'image est " & H 
    Srcimage = stRep & "\" & stFichier
    Call LoadImage(Srcimage,W,H)
    ws.run "mshta.exe " & PathOutPutHTML
    '********************************************************************************************************
    Sub LoadImage(Srcimage,W,H)
        fhta.WriteLine "<html>"
        fhta.WriteLine "    <hta:application id=""oHTA"" "
        fhta.WriteLine "        border=""none"" "
        fhta.WriteLine "        caption=""no"" "
        fhta.WriteLine "        contextmenu=""no"" "
        fhta.WriteLine "        innerborder=""no"" "
        fhta.WriteLine "        scroll=""no"" "
        fhta.WriteLine "        showintaskbar=""no"" "
        fhta.WriteLine "    />"
        fhta.WriteLine "<style>"
        fhta.WriteLine "{ margin: 0; padding: 0; }"
        fhta.WriteLine "body {background: url(" & DblQuote(Srcimage) & ") no-repeat center center fixed;}"
        fhta.WriteLine "</style>"
        fhta.WriteLine "    <script language=""VBScript"">"
        fhta.WriteLine "        Sub Window_OnLoad()"
        fhta.WriteLine "            width = "& W &" "
        fhta.WriteLine "            height = "& H &" "
        fhta.WriteLine "            window.resizeTo width, height"
        fhta.WriteLine "            window.moveTo screen.availWidth\2 - width\2, screen.availHeight\2 - height\2"
        fhta.WriteLine "            idTimer = window.setTimeout(""vbscript:window.close"",10000)"
        fhta.WriteLine "        End Sub"
        fhta.WriteLine "    </script>"
        fhta.WriteLine "<body>"
        fhta.WriteLine "</body>"
        fhta.WriteLine "</html>"
    End Sub
    '**********************************************************************************************
    Function DblQuote(Str)
        DblQuote = Chr(34) & Str & Chr(34)
    End Function
    '**********************************************************************************************

  2. #2
    Membre confirmé Avatar de nanooby
    Homme Profil pro
    IT Consultant
    Inscrit en
    Mai 2014
    Messages
    103
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Royaume-Uni

    Informations professionnelles :
    Activité : IT Consultant
    Secteur : Agroalimentaire - Agriculture

    Informations forums :
    Inscription : Mai 2014
    Messages : 103
    Par défaut
    Tes paramètres W et H doivent pouvoir être écrit et donc être formattés en string.

    Je ne peux t'aider plus loin, je n'ai jamais codé en VBscript

  3. #3
    Rédacteur
    Avatar de omen999
    Profil pro
    Inscrit en
    Février 2006
    Messages
    1 302
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2006
    Messages : 1 302
    Par défaut
    salut,
    encore un exemple des pièges du GetDetailsOf
    sous vista et sup la lecture des dimensions d'une image renvoie des caractères de contrôles : http://www.developpez.net/forums/d14...rs-numeriques/

    voir la fin de cet article
    nomen omen, nemo non omen - Consultez la FAQ VBScript et les cours et tutoriels VBScript
    le plus terrible lorsqu'une voiture renverse un piéton, c'est que ce sont les freins qui hurlent. (ramón)
    pas de questions techniques par mp

  4. #4
    Membre confirmé Avatar de nanooby
    Homme Profil pro
    IT Consultant
    Inscrit en
    Mai 2014
    Messages
    103
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Royaume-Uni

    Informations professionnelles :
    Activité : IT Consultant
    Secteur : Agroalimentaire - Agriculture

    Informations forums :
    Inscription : Mai 2014
    Messages : 103
    Par défaut
    C'est bon à savoir

  5. #5
    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
    Citation Envoyé par omen999 Voir le message
    salut,
    encore un exemple des pièges du GetDetailsOf
    sous vista et sup la lecture des dimensions d'une image renvoie des caractères de contrôles : http://www.developpez.net/forums/d14...rs-numeriques/

    voir la fin de cet article
    omen999
    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
    Option Explicit
    Dim ws,fso,Srcimage,Temp,PathOutPutHTML,fhta,stRep,stFichier,oShell,oFolder,oFichier,Dimensions
    Dim arrSize,intLength,intHorizontalSize,intVerticalSize
    Set ws = CreateObject("wscript.Shell")
    Set fso = CreateObject("Scripting.FileSystemObject")
    Temp = WS.ExpandEnvironmentStrings("%Temp%")
    PathOutPutHTML = Temp & "\image.hta"
    Set fhta = fso.OpenTextFile(PathOutPutHTML,2,True)
    stRep="E:\HackooTest"
    stFichier ="MDR.gif"
    Set oShell = CreateObject("Shell.Application")
    Set oFolder = oShell.Namespace(stRep)
    Set oFichier = oFolder.Items.Item(stFichier)
    Dimensions = oFolder.GetDetailsOf(oFichier,31)
    arrSize = Split(Dimensions,"x")	
    '***************************************Important à savoir **********************************************
    'Instead, we ended up retrieving item 31, which gave us the total dimensions of the picture,
    'using an output format similar to this: ?150 x 354?
    'http://blogs.technet.com/b/heyscriptingguy/archive/2008/05/16/how-can-i-search-a-folder-for-all-the-image-files-that-are-not-a-specified-height-and-width.aspx
    'Un grand merci à omen999 ==> 
    'http://www.developpez.net/forums/d1504644/autres-langages/general-visual-basic-6-vbscript/vbscript/passage-variables-procedure/#post8163406
    intLength = Len(arrSize(0))
    intHorizontalSize = Right(arrSize(0),intLength -1)
    intLength = Len(arrSize(1))
    intVerticalSize = Left(arrSize(1),intLength - 1) 
    '***************************************Important à savoir **********************************************
    Srcimage = stRep & "\" & stFichier
    Call LoadImage(Srcimage,intHorizontalSize,intVerticalSize)
    ws.run "mshta.exe " & PathOutPutHTML
    '********************************************************************************************************
    Sub LoadImage(Srcimage,W,H)
    	fhta.WriteLine "<html>"
    	fhta.WriteLine "	<hta:application id=""oHTA"" "
    	fhta.WriteLine "		border=""none"" "
    	fhta.WriteLine "		caption=""no"" "
    	fhta.WriteLine "		contextmenu=""no"" "
    	fhta.WriteLine "		innerborder=""no"" "
    	fhta.WriteLine "		scroll=""no"" "
    	fhta.WriteLine "		showintaskbar=""no"" "
    	fhta.WriteLine "	/>"
    	fhta.WriteLine "<style>"
    	fhta.WriteLine "{ margin: 0; padding: 0; }"
    	fhta.WriteLine "body {background: url(" & DblQuote(Srcimage) & ") no-repeat center center fixed;}"
    	fhta.WriteLine "</style>"
    	fhta.WriteLine "	<script language=""VBScript"">"
    	fhta.WriteLine "		Sub Window_OnLoad()"
    	fhta.WriteLine "			width = " & intHorizontalSize
    	fhta.WriteLine "			height = " & intVerticalSize
    	fhta.WriteLine "			window.resizeTo width, height"
    	fhta.WriteLine "			window.moveTo screen.availWidth\2 - width\2, screen.availHeight\2 - height\2"
    	fhta.WriteLine "			idTimer = window.setTimeout(""vbscript:window.close"",10000)"
    	fhta.WriteLine "		End Sub"
    	fhta.WriteLine "	</script>"
    	fhta.WriteLine "<body>"
    	fhta.WriteLine "</body>"
    	fhta.WriteLine "</html>"
    End Sub
    '**********************************************************************************************
    Function DblQuote(Str)
    	DblQuote = Chr(34) & Str & Chr(34)
    End Function
    '**********************************************************************************************

  6. #6
    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 Mise à jour : Téléchargement de l'image à partir du net en jouant du son en arrière plan

    Mise à jour : Téléchargement de l'image à partir du net en jouant du son en arrière plan testé seulement sur Windows 7 32 bits
    J'ai fait une petite mise à jour et je veux que les personnes qui vont tester me confirme le résultat du test ou bien me dire s'ils ont rencontrés des bugs en mentionnant bien sûr l’environnement du test !
    Remarque : Ce code ne marche pas sur windows XP, donc ce n'est pas la peine de tester sur ce système
    J'ai choisi comme image le drapeau tunisien en jouant l'hymne national officiel de la TUNISIE



    Popup d'une image en jouant du son en arrière plan

    Tunisie.vbs
    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
    Option Explicit
    Dim URL,ws,fso,Srcimage,Temp,PathOutPutHTML,fhta,stRep,stFichier,oShell,oFolder,oFichier,Dimensions
    Dim arrSize,intLength,intHorizontalSize,intVerticalSize,Tab
    URL = "http://www.animatedimages.org/data/media/902/animated-tunisia-flag-image-0023.gif"
    Set ws = CreateObject("wscript.Shell")
    Set fso = CreateObject("Scripting.FileSystemObject")
    Temp = WS.ExpandEnvironmentStrings("%Temp%")
    PathOutPutHTML = Temp & "\image.hta"
    Set fhta = fso.OpenTextFile(PathOutPutHTML,2,True)
    stRep = Temp
    Tab = split(url,"/")
    stFichier = Tab(UBound(Tab))
    Srcimage = stRep & "\" & stFichier
    If Not fso.FileExists(Srcimage) Then
        Call DownloadingFile(URL,Srcimage)
    Set oShell = CreateObject("Shell.Application")
    Set oFolder = oShell.Namespace(stRep)
    Set oFichier = oFolder.Items.Item(stFichier)
    Dimensions = oFolder.GetDetailsOf(oFichier,31)
    arrSize = Split(Dimensions,"x")    
    '***************************************Important à savoir **********************************************
    'Instead, we ended up retrieving item 31, which gave us the total dimensions of the picture,
    'using an output format similar to this: ?150 x 354?
    'http://blogs.technet.com/b/heyscriptingguy/archive/2008/05/16/how-can-i-search-a-folder-for-all-the-image-files-that-are-not-a-specified-height-and-width.aspx
    'Un grand merci à omen999 ==> 
    'http://www.developpez.net/forums/d1504644/autres-langages/general-visual-basic-6-vbscript/vbscript/passage-variables-procedure/#post8163406
    intLength = Len(arrSize(0))
    intHorizontalSize = Right(arrSize(0),intLength -1)
    intLength = Len(arrSize(1))
    intVerticalSize = Left(arrSize(1),intLength - 1) 
    '***************************************Important à savoir **********************************************
        Call LoadImage(Srcimage,intHorizontalSize,intVerticalSize,Timeout(51))
        ws.run "mshta.exe " & PathOutPutHTML
    Else
    Set oShell = CreateObject("Shell.Application")
    Set oFolder = oShell.Namespace(stRep)
    Set oFichier = oFolder.Items.Item(stFichier)
    Dimensions = oFolder.GetDetailsOf(oFichier,31)
    arrSize = Split(Dimensions,"x")
    intLength = Len(arrSize(0))
    intHorizontalSize = Right(arrSize(0),intLength -1)
    intLength = Len(arrSize(1))
    intVerticalSize = Left(arrSize(1),intLength - 1) 
        Call LoadImage(Srcimage,intHorizontalSize,intVerticalSize,Timeout(51))
        ws.run "mshta.exe " & PathOutPutHTML
    End If
    '********************************************************************************************************
    Function TimeOut(T)
        TimeOut = T * 1000
    End Function    
    '********************************************************************************************************
    Sub LoadImage(Srcimage,intHorizontalSize,intVerticalSize,TimeOut)
        fhta.WriteLine "<html>"
        fhta.WriteLine "    <hta:application id=""oHTA"" "
        fhta.WriteLine "        border=""none"" "
        fhta.WriteLine "        caption=""no"" "
        fhta.WriteLine "        contextmenu=""no"" "
        fhta.WriteLine "        innerborder=""no"" "
        fhta.WriteLine "        scroll=""no"" "
        fhta.WriteLine "        showintaskbar=""no"" "
        fhta.WriteLine "    />"
        fhta.WriteLine "<style>"
        fhta.WriteLine "{ margin: 0; padding: 0; }"
        fhta.WriteLine "body {background: url(" & DblQuote(Srcimage) & ") no-repeat center center fixed;}"
        fhta.WriteLine "</style>"
        fhta.WriteLine "    <script language=""VBScript"">"
        fhta.WriteLine "        Sub Window_OnLoad()"
        fhta.WriteLine "            width = " & intHorizontalSize
        fhta.WriteLine "            height = " & intVerticalSize
        fhta.WriteLine "            window.resizeTo width, height"
        fhta.WriteLine "            window.moveTo screen.availWidth\2 - width\2, screen.availHeight\2 - height\2"
        fhta.WriteLine "            idTimer = window.setTimeout(""vbscript:window.close"","& TimeOut &")"
        fhta.WriteLine "             window.setInterval ""setfocus()"",100"
        fhta.WriteLine "        End Sub"
        fhta.WriteLine "        Function setfocus"
        fhta.WriteLine "            Window.Focus()"
        fhta.WriteLine "        End Function"
        fhta.WriteLine "    </script>"
        fhta.WriteLine "<body>"
        fhta.WriteLine "<bgsound src=""http://hackoo.alwaysdata.net/Tunisie.mp3"">"
        fhta.WriteLine "</body>"
        fhta.WriteLine "</html>"
    End Sub
    '**********************************************************************************************
    Function DblQuote(Str)
        DblQuote = Chr(34) & Str & Chr(34)
    End Function
    '**********************************************************************************************
    Sub DownloadingFile(URL,strHDLocation)
    Dim Titre,objFSO,Ws,objXMLHTTP,PathScript,Tab,objADOStream,Command,Start,File
    Dim MsgTitre,MsgAttente,StartTime,DurationTime,ProtocoleHTTP
    Set objFSO = Createobject("Scripting.FileSystemObject")
    Set Ws = CreateObject("wscript.Shell")
    ProtocoleHTTP = "http://"
    If Left(URL,7) <> ProtocoleHTTP Then
    URL = ProtocoleHTTP & URL
    End if
    Tab = split(url,"/")
    File =  Tab(UBound(Tab))
    File = Replace(File,"%20"," ")
    File = Replace(File,"%28","(")
    File = Replace(File,"%29",")")
        Set objXMLHTTP = CreateObject("MSXML2.ServerXMLHTTP.3.0")
        strHDLocation = PathScript & "\" & File
        On Error Resume Next
        objXMLHTTP.open "GET",URL,false
        objXMLHTTP.send()
    If Err.number <> 0 Then
       MsgBox err.description,16,err.description
       Exit Sub
       Else
        If objXMLHTTP.Status = 200 Then
             strHDLocation = Temp & "\" & File
             Set objADOStream = CreateObject("ADODB.Stream")
             objADOStream.Open
             objADOStream.Type = 1 'adTypeBinary
             objADOStream.Write objXMLHTTP.ResponseBody
             objADOStream.Position = 0    'Set the stream position to the start
             objADOStream.SaveToFile strHDLocation,2 '2=adSaveCreateOverWrite
             objADOStream.Close
        Set objADOStream = Nothing
        End If
    End if
    Set objXMLHTTP = Nothing
    End Sub
    pour le test

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

Discussions similaires

  1. Passage d'une variable dans une procédure
    Par Sakapatate dans le forum Langage
    Réponses: 19
    Dernier message: 03/06/2007, 10h22
  2. Réponses: 8
    Dernier message: 03/11/2006, 15h55
  3. Passage de variables dans une fonction
    Par renaud26 dans le forum Général JavaScript
    Réponses: 4
    Dernier message: 01/07/2006, 17h49
  4. Réponses: 9
    Dernier message: 31/01/2006, 09h04
  5. Passage de variable dans une requête
    Par zestrellita dans le forum Langage SQL
    Réponses: 5
    Dernier message: 02/09/2004, 13h27

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