Click to See Complete Forum and Search --> : vbs 2 js


despre
June 15th, 2005, 01:42 PM
I want to use this VBScript style progbar on my up comming webpage in JScript
but I can't convert it to js with this http://slingfive.com/pages/code/scriptConverter/demo.html

can some1 help me?

here's the .vbs code: '-- This progress bar is a variation on #1 sample. It takes a different approach by
'-- writing a default bar webpage during class initialization and sending the created IE
'-- instance to open that file. It writes default property values to the file, hard-coded
'-- into the class. You can then programmatically change the properties
'-- in script.
'-- Most properties can be changed anytime while the script is running, which allows
'-- for an updating caption and window re-use.

Dim bar, i
On Error Resume Next
'-- create a class instance. --------
Set bar = new IEProgBar
'-- set some bar properties and run it. ----------
With bar
.Move -1, -1, 300, -1
.Show
.Background = "toolback.jpg" '-- image paths seem to work as relative path.
For i = 0 to 19
WScript.Sleep 300
If i = 8 Then .Caption = "Halfway."
If i = 16 Then .Caption = "Almost done."
.Advance
Next
.Hide
End With

'-- second running of bar using the same instance/webpage.
'-- This resets the count and makes changes to appearance before running
'-- the bar again. Note that if you change BackColor it should be done before calling Reset
'-- because the Reset sub resets background color of the progress units to BackColor value.

With bar
.Background = ""
.Icon = "progicon.gif"
.BackColor = "FFDCA8"
.Reset '-- Reset should be called after BackColor is set because Reset will recolor progress units to back color value.
.TextColor = "4F009D"
.Title = "Second Version"
.Caption = "This demo shows more options."
.ProgressColor = "109494"
.Move 400, 300, 350, 150
.Show
For i = 0 to 19
WScript.Sleep 500
If i = 8 Then .Caption = "A back picture can be used."
If i = 14 Then .Caption = "Most properties can be changed while running."
.Advance
Next
.Hide
End With

Set bar = Nothing

'-------- Start Progress bar Class ----------------------------------
Class IEProgBar
Private FSO, IE, BackCol, ProgressCol, ProgressUnits, Q2, sTemp, iProgress

Private Sub Class_Initialize()
On Error Resume Next
Set FSO = CreateObject("Scripting.FileSystemObject")
sTemp = FSO.GetSpecialFolder(2)
Q2 = chr(34)
Set IE = CreateObject("InternetExplorer.Application")
With IE
.AddressBar = False
.menubar = False
.ToolBar = False
.StatusBar = False
.width = 400
.height = 120
.resizable = True
.visible = False
End With
'-- set internal variable defaults. These variables are needed for Reset sub and Advance sub.
BackCol = "E0E0E4" '--background color.
ProgressCol = "0000A0" '--progress color.
ProgressUnits = 20 'number of progress units. Change this value to change unit number.
iProgress = 0 '--to track progress.
'--writes webpage and loads it:
PrepPage
Do Until IE.ReadyState = 4
Loop
End Sub

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

Public Sub Show()
IE.Visible = True
End Sub

Public Sub Hide()
IE.Visible = False
End Sub

'-- Advance method colors one progress unit. iProgress 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 (iProgress < ProgressUnits) and (IE.Visible = True) Then
IE.Document.parentWindow.Prog1(iProgress).bgcolor = ProgressCol
iProgress = iProgress + 1
End If
End Sub

'------ Reset progress for another use. --------------------------------
Public Sub Reset()
Dim i2
On Error Resume Next
For i2 = 0 to (ProgressUnits - 1)
IE.Document.parentWindow.Prog1(i2).bgcolor = BackCol
Next
iProgress = 0
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

'------------- Set background picture: ---------------------
Public Property Let BackGround(sPic)
Dim Boo1, sFil, sFilPath
On Error Resume Next
If (Len(sPic) = 0) or (FSO.FileExists(sPic) = False) Then
Boo1 = IE.Document.Body.removeAttribute("Background", 0)
Else
sFil = FSO.GetFileName(sPic)
sFilPath = sTemp & "\" & sFil
If FSO.FileExists(sFilPath) Then FSO.DeleteFile sFilPath, True
FSO.CopyFile sPic, sFilPath, True
IE.Document.Body.background = sFil
End If
End Property

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

Public Property Let BackColor(sCol)
If (TestColor(sCol) = True) Then
BackCol = scol
IE.Document.bgColor = sCol
End If
End Property

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

Public Property Let TextColor(sCol)
If (TestColor(sCol) = True) Then IE.Document.Body.Text = sCol
End Property

'------------- Set progress color: ---------------------
'-- this must be set before any Advance calls, or after a Reset call, in order to avoid multi-colored units.
Public Property Let ProgressColor(sCol)
If (TestColor(sCol) = True) Then ProgressCol = sCol
End Property

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

Public Property Let Icon(sPic)
Dim sTag, sFil, sFilPath
On Error Resume Next
If (Len(sPic) = 0) or (FSO.FileExists(sPic) = False) Then Exit Property
sFil = FSO.GetFileName(sPic)
sFilPath = sTemp & "\" & sFil
If FSO.FileExists(sFilPath) Then FSO.DeleteFile sFilPath, True
FSO.CopyFile sPic, sFilPath, True
sTag = "<IMG SRC=" & Q2 & sFil & Q2 & " ALIGN=" & Q2 & "Left" & Q2 & ">"
IE.Document.Body.insertAdjacentHTML "AfterBegin", sTag
End Property

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

Public Property Let Title(sCap)
IE.Document.Title = sCap
End Property

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

Public Property Let Caption(sCap)
IE.Document.parentWindow.Cap1.innerText = sCap
End Property

'--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 = "HKLM\Software\Microsoft\Internet Explorer\Main\Window Title"
sR2 = "HKCU\Software\Microsoft\Internet Explorer\Main\Window Title"
Set SH = CreateObject("WScript.Shell")
SH.RegWrite sR1, "", "REG_SZ"
SH.RegWrite sR2, "", "REG_SZ"
Set SH = Nothing
End Sub

'----------------- ////////////////////// Private functions /////////////////////////// ------------------------------

'--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

'-- Write the initial webpage, with default values for properties. ------------------
Private Sub PrepPage()
Dim s, i, TS
On Error Resume Next
s = "<HTML><HEAD><TITLE>Progress</TITLE></HEAD>"
s = s & "<BODY SCROLL=" & Q2 & "NO" & Q2 & " BGCOLOR=" & Q2 & "#E0E0E4" & Q2 & " TEXT=" & Q2 & "#000000" & Q2 & ">"
s = s & "<FONT FACE=" & Q2 & "arial" & Q2 & " SIZE=2><LABEL ID=" & Q2 & "Cap1" & Q2 & ">Progress...</LABEL></FONT><BR><BR>"
s = s & "<TABLE BORDER=1><TR><TD><TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0><TR>"
For i = 1 to ProgressUnits
s = s & "<TD WIDTH=16 HEIGHT=16 ID=" & Q2 & "Prog1" & Q2 & ">"
Next
s = s & "</TR></TABLE></TD></TR></TABLE><BR><BR></BODY></HTML>"
Set TS = FSO.CreateTextFile(sTemp & "\iebar3.html", True)
TS.Write s
TS.Close
Set TS = Nothing
IE.Navigate "file:///" & sTemp & "\iebar3.html"
End Sub

End Class

PeejAvery
June 15th, 2005, 02:39 PM
Read the part on the limitations of the ScriptConverter. If you know any JavaScripting at all, then you should be able to do the work yourself.
http://slingfive.com/pages/code/scriptConverter/

My guess is that most people here don't have the time to rewrite that whole code for you. That is a time consumer.