OVH Cloud OVH Cloud

barre de progression ou compteur

2 réponses
Avatar
Pierre
Bonjour,
j'ai =E9crit un script qui sert =E0 concat=E9ner de gros=20
fichiers (je vous passe les d=E9tails).
Je voudrais afficher la progression du script, si possible=20
tout b=EAtement dans la fen=EAtre noire d'ex=E9cution du VBS, en=20
affichant le n=B0 de ligne courant ou une barre de=20
progression (ou un pourcentage, soyons fous), =E0=20
l'int=E9rieur d'une boucle qui fait des readline/writeline.
Rien trouv=E9 dans la doc en ligne chez microsoft.
Une astuce ?
merci

2 réponses

Avatar
Jérôme Cornier [MS]
Bonjour,

Il existe plusieurs solutions plus ou moins complexes.
ScriptCenter propose 2 exemples :
http://www.microsoft.com/technet/scriptcenter/scripts/misc/progress/default.mspx

Et MSDN un exemple de l'usage d'ie comme moyen de présentation :
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnwsvbs/html/progressbars.asp

--
Cordialement,
_________________________________________________________
Jérôme Cornier
Microsoft Services France

"Pierre" a écrit dans le message de news:
18a001c4fc77$527e1940$
Bonjour,
j'ai écrit un script qui sert à concaténer de gros
fichiers (je vous passe les détails).
Je voudrais afficher la progression du script, si possible
tout bêtement dans la fenêtre noire d'exécution du VBS, en
affichant le n° de ligne courant ou une barre de
progression (ou un pourcentage, soyons fous), à
l'intérieur d'une boucle qui fait des readline/writeline.
Rien trouvé dans la doc en ligne chez microsoft.
Une astuce ?
merci
Avatar
Lord Mathius
voici le script que j'utilise pour faire ma progresse bar.
il est jolie meme s'il est pas de moi il marche tres bien
-------------------------------------------------------------------------------------------
Option Explicit
'Example of sleep (10000 = 10 second pause)
'WScript.Sleep 30000
On Error Resume Next
Dim
ws,adGrp,objWMIService,colNetCards,objNetworkSettings,arrDNSSuffixes,strComputer,compname,objNetCard
'Progress bar
Dim bar, i
Set bar = new IEProgBar
With bar
.Move -1, -1, 500, -1
.Units = 100
.Show
.Icon = ""
For i = 0 to 100
WScript.Sleep 100
.Advance
Next
End With
Set bar = Nothing

'-----
//////////////////////////////////////////////////////////////////////////////////////////////
' -- Progress bar Class that can be pasted into scripts.
'-- To create Progress bar: Dim ob
' Set ob = New IEProgBar

'-- This progress bar is created with an HTML file, which is written to the
Temp folder
'-- and opened from there.

'-- Methods and Properties:

' Methods -
' Show - displays progress bar by writing file, causing IE to
open it and setting IE visible.
' Advance - advances progress by 1 unit.
' Move(Left, Top, Width, Height) - moves and/or resizes window.
All parameters must be used.
' use -1 For any
dimension Not being changed: ob.Move 10, 10, -1, -1
' default size is
400 W x 120 H. default position is Windows default.

' CleanIETitle - removes Registry settings that append
advertising to the page
' title in the IE title bar so that only the
specified Title Property
' will be displayed. (This is a general change
to IE and is Not reversible
' with this script as written.)
' Properties -
' BackColor - 6-character hex code to specify background color.
default is "E0E0E4".
' TextColor - 6-character hex code to specify caption text
color. default is "000000".
' ProgressColor - 6-character hex code to specify progress
color. default is "0000A0".
' Title - window title text. default is "Progress"
' Caption - text caption in window. default is "Progress. . ."
' Units - number of progress units to use. default is 20.
' Icon - path of any image file that can be used as an icon.
(JPG, GIF, BMP or ICO)
' default is no icon. If an icon is specifed it appears
to left of caption.
'---
////////////////////////////////////////////////////////////////////////////////////////


'-------- Start Progress bar Class ----------------------------------
Class IEProgBar
Private FSO, IE, BCol, TCol, ProgCol, ProgNum, ProgCaption, Pic, Q2,
sTemp, iProg, ProgTitle
Private Sub Class_Initialize()
On Error Resume Next
Set FSO = CreateObject("Scripting.FileSystemObject")
sTemp = FSO.GetSpecialFolder(2)
Set IE = CreateObject("InternetExplorer.Application")
With IE
.AddressBar = False
.menubar = False
.ToolBar = False
.StatusBar = False
.width = 400
.height = 120
.resizable = False
End With
BCol = "FFFFFF" '--background color.
TCol = "000000" '--caption text color.
ProgCol = "0000CC" '--progress color.
ProgNum = 20 'number of progress units.
ProgCaption = "Please wait while the script runs. Thank you."
ProgTitle = "::Your Company Name Here::"
Q2 = chr(34)
iProg = 0 '--to track progress.
Icon = "" 'Full path to image file for icon here
End Sub

Private Sub Class_Terminate()
On Error Resume Next
IE.Quit
Set IE = Nothing
Set FSO = Nothing
End Sub

Public Sub Show()
Dim s, i, TS
On Error Resume Next
s = "<HTML><HEAD><TITLE>" & ProgTitle & "</TITLE></HEAD>"
s = s & "<BODY SCROLL=" & Q2 & "NO" & Q2 & " BGCOLOR=" & Q2 & "#" &
BCol & Q2 & " TEXT=" & Q2 & "#" & TCol & Q2 & ">"
If (Pic <> "") Then
s = s & "<IMG SRC=" & Q2 & Pic & Q2 & " ALIGN=" & Q2 & "Left" &
Q2 & ">"
End If
If (ProgCaption <> "") Then
s = s & "<FONT FACE=" & Q2 & "arial" & Q2 & " SIZE=2>" &
ProgCaption & "</FONT><BR><BR>"
Else
s = s & "<BR>"
End If
s = s & "<TABLE BORDER=1><TR><TD><TABLE BORDER=0 CELLPADDING=0
CELLSPACING=0><TR>"
For i = 1 to ProgNum
s = s & "<TD WIDTH HEIGHT ID=" & Q2 & "P" & Q2 & ">"
Next
s = s & "</TR></TABLE></TD></TR></TABLE><BR><BR></BODY></HTML>"
Set TS = FSO.CreateTextFile(sTemp & "iebar1.html", True)
TS.Write s
TS.Close
Set TS = Nothing
IE.Navigate "file:///" & sTemp & "iebar1.html"
IE.visible = True
End Sub

'-- Advance method colors one progress unit. iProg variable tracks how many
'-- units have been colored. Each progress unit is a <TD> with ID="P". They
can be
'-- accessed in sequence through Document.All.Item.
Public Sub Advance()
On Error Resume Next
If (iProg < ProgNum) and (IE.Visible = True) Then
IE.Document.All.Item("P", (iProg)).bgcolor = Q2 & "#" & ProgCol & Q2
iProg = iProg + 1
End If
End Sub

'--resize and/or position window. Use -1 For any value Not being Set.
Public Sub Move(PixLeft, PixTop, PixWidth, PixHeight)
On Error Resume Next
If (PixLeft > -1) Then IE.Left = PixLeft
If (PixTop > -1) Then IE.Top = PixTop
If (PixWidth > 0) Then IE.Width = PixWidth
If (PixHeight > 0) Then IE.Height = PixHeight
End Sub

'--remove Registry settings that display advertising in the IE title bar.
'-- This change won't show up the first time it's used because the IE
'-- instance has already been created when the method is called.

Public Sub CleanIETitle()
Dim sR1, sR2, SH
On Error Resume Next
sR1 = "HKLMSoftwareMicrosoftInternet ExplorerMainWindow Title"
sR2 = "HKCUSoftwareMicrosoftInternet ExplorerMainWindow Title"
Set SH = CreateObject("WScript.Shell")
SH.RegWrite sR1, "", "REG_SZ"
SH.RegWrite sR2, "", "REG_SZ"
Set SH = Nothing
End Sub

'------------- Set background color: ---------------------

Public Property Let BackColor(sCol)
If (TestColor(sCol) = True) Then BCol = sCol
End Property

'------------- Set caption color: ---------------------

Public Property Let TextColor(sCol)
If (TestColor(sCol) = True) Then TCol = sCol
End Property

'------------- Set progress color: ---------------------

Public Property Let ProgressColor(sCol)
If (TestColor(sCol) = True) Then ProgCol = sCol
End Property

'------------- Set icon: ---------------------

Public Property Let Icon(sPath)
If (FSO.FileExists(sPath) = True) Then Pic = sPath
End Property

'------------- Set title text: ---------------------

Public Property Let Title(sCap)
ProgTitle = sCap
End Property

'------------- Set caption text: ---------------------

Public Property Let Caption(sCap)
ProgCaption = sCap
End Property

'------------- Set number of progress units: ---------------------

Public Property Let Units(iNum)
ProgNum = iNum
End Property

'--confirm that color variables are valid 6-character hex color codes:
'-- If Not 6 characters Then TestColor = False
'-- If any character is Not 0-9 or A-F Then TestColor = False
Private Function TestColor(Col6)
Dim iB, sB, iB2, Boo1
On Error Resume Next
TestColor = False
If (Len(Col6) <> 6) Then Exit Function
For iB = 1 to 6
sB = Mid(Col6, iB, 1)
iB2 = Asc(UCase(sB))
If ((iB2 > 47) and (iB2 < 58)) or ((iB2 > 64) and (iB2 < 71)) Then
Boo1 = True
Else
Boo1 = False
Exit For
End If
Next
If (Boo1 = True) Then TestColor = True
End Function
End Class

-------------------------------------------------------------------------------------------

"Jérôme Cornier [MS]" wrote:

Bonjour,

Il existe plusieurs solutions plus ou moins complexes.
ScriptCenter propose 2 exemples :
http://www.microsoft.com/technet/scriptcenter/scripts/misc/progress/default.mspx

Et MSDN un exemple de l'usage d'ie comme moyen de présentation :
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnwsvbs/html/progressbars.asp

--
Cordialement,
_________________________________________________________
Jérôme Cornier
Microsoft Services France

"Pierre" a écrit dans le message de news:
18a001c4fc77$527e1940$
Bonjour,
j'ai écrit un script qui sert à concaténer de gros
fichiers (je vous passe les détails).
Je voudrais afficher la progression du script, si possible
tout bêtement dans la fenêtre noire d'exécution du VBS, en
affichant le n° de ligne courant ou une barre de
progression (ou un pourcentage, soyons fous), à
l'intérieur d'une boucle qui fait des readline/writeline.
Rien trouvé dans la doc en ligne chez microsoft.
Une astuce ?
merci