Link to home
Start Free TrialLog in
Avatar of PvBredow
PvBredow

asked on

Convert .vbs script to vbscript in .htm

I have a VbScript file (.vbs) which works fine on my machine (i.e. no permissioning problems.        I want to produce the equivalent in a webpage, using client-side vbscript.        My current script is:

RT_FRV_UPDATED = 2
RT_FCV_VALUE   = 32
RT_MODE_ONUPDATE = 3

set AdxRtlist = WScript.CreateObject("AdfinXRtLib.AdxRtList","EventListner_")

AdxRtlist.Source="IDN"
AdxRtlist.RegisterItems "EUR=","ASK"
AdxRtlist.startUpdates RT_MODE_ONUPDATE

Sub EventListner_OnUpdate(ItemName,UserTag,ItemStatus)
    FieldArray = AdxRtlist.ListFields(itemName, RT_FRV_UPDATED, RT_FCV_VALUE)
    If VarType(FieldArray) <> vbEmpty Then
        For i = LBound(FieldArray, 1) To UBound(FieldArray, 1)
            WScript.echo "[" & ItemName,"]" & " " & FieldArray(i, 0) & ", " & FieldArray(i, 1)
        Next
    End If
End Sub

I have tried to convert this, but with no success.     Converting the output display isn't a problem, but the issue is creating the ActiveX object, and handling the events produced.

Can anyone advise how the syntax needs to be changed?

           thanks!

                    PvBredow
Avatar of uncle_med
uncle_med

Did you say client side? You can not use createobject on client side, that is a server object
Avatar of fritz_the_blank
What you have above will only work if the user has the .wsc file registered on his/her machine. Otherwise, you will need to to this with server-side scripting.

FtB
Avatar of PvBredow

ASKER

Uncle Med,
         Thanks for the comment.        Perhaps it is a dumb question, but I would like to clarify your comment:
Are you saying that ActiveX objects can only be created by scripts on the server side, or that the statement 'createobject' can only be used on the server side?          Is there some equivalent statement for client side scripting?

        PvBredow
There is an equivalient. However, you must have the class registered on the client machine in order for it to work.

FtB
Here is an example, all client-side VBScript:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title> New Document </title>
<script language=VBScript>
Dim strList
Class objFieldHolder
      public field1
      public field2
      public field3
      public function toString()
            toString = field1 & "~" &  field2 & "~" & field3
      end function
      public sub toArray(strValues)
       dim arrFields
             arrFields = split(strValues,"~")
             field1 = arrFields(0)
             field2 =arrFields(1)
             field3 = arrFields(2)
      end sub
End Class

</script>
</head>

<body>
<script language=VBScript>
set objFieldHolder1 = new objFieldHolder
objFieldHolder1.field1 = "Fritz the Blank"
objFieldHolder1.field2 = "www.FairfieldConsulting.com"
objFieldHolder1.field3 = "Where you go to hire a programmer"
strList = objFieldHolder1.toString()
MsgBox strList
Set objFieldHolder1 = Nothing


set objFieldHolder2 = new objFieldHolder
objFieldHolder2.toArray strList
MsgBox objFieldHolder2.field1
MsgBox objFieldHolder2.field2
MsgBox objFieldHolder2.field3


</script>


</body>
</html>
Thanks Fritz, for the reply.

So far, I haven't been able to make use of the example that you sent though.        I believe the root of my problem is that I don't know the correct method/syntax for writing an event handler for events produced by an ActiveX object.
I'm not very strong in OOP, but as I read your example (above), you are creating your own class, but not writing an event handler.

Do you have an example that shows an event handler for an ActiveX object, in VbScript?    that would be very helpful!

                regards,
                              PvBredow
There is no way of doing this on client side, because client side by definition only uses objects within your browser or objects intstalled on client machine. To create an instance of an ActiveX object on client side you need to have the Activex object registered on the client machine. That is the only way to do it, but then that is not really Client side.
Uncle Med,
           In this specific case, I know that every machine that will use the page I am trying to develop will have the ActiveX control I want to use.      (This is for a page on a company internal web, and will only be of use to those user's who have an application installed that uses that ActiveX control).

        PvBredow
If you wrap your activex control into a .wsc file and register it on each machine, alll functionality will be available.

FtB
Fritz,
      I'm not sure I know what you mean by that.    However, if the control in question is already installed & registered on every user's machine, is there any need for it anyway?

If it really is needed, do you have an example of how that is done?

       PvBredow
I am not sure what you mean exactly.

I am looking at this line of code:

set AdxRtlist = WScript.CreateObject("AdfinXRtLib.AdxRtList","EventListner_")

You would need to have the component installed and registered on each client machine in order for your page to work without server-side scripting. Most often, components like this are wrapped in a .dll or in a .wsc file.

FtB
Fritz,
      The .dll file would be installed and registered on all the client machines on which this page could be loaded.      My page does not need to be able to handle any machine on which this isn't true (this is for an internal company intranet, and the .dll is part of an inhouse application).
That is why I believed server-side scripting would not be necessary.

If this can be eventually made to work, it will be part of a training system to help staff learn a complex in-house application.       Essentially, the web page I am trying to develop would be part of a training simulator, so staff can can experience without using the live application.

The dll in question is one that returns real-time data, and produces events when that data changes.
The .vbs that I quoted works, but I am trying to use a webpage as the UI, so I am trying to convert it to be used as client-side scripting inside a webpage.

The issues I am stuck with are how to do event handling for events thrown by ActiveX objects in VbScript.

Does that clarify the situation?

        thanks,
                  PvBredow
ASKER CERTIFIED SOLUTION
Avatar of fritz_the_blank
fritz_the_blank
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The question is how to get the .vbs to work, on client side script on a htm page. fritz_the_blank's solution won't work unless its in a VB script (vbs) file.
If this kind of ActiveX functionality was exposed to client side scripting, then our computers would be wiped out by malicious scripts as soon as we surf the net!
My page works fine as an htm. Give it a try. Make sure to disable NAV script blocking or your computer will hang.

FtB