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
PvBredowAsked:
Who is Participating?
 
fritz_the_blankConnect With a Mentor Commented:
I think that it may.

If you use IE only, you can run client-side VBScript to do what you need. Consider the following:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title> New Document </title>
</head>

<body>
<script language="VBScript">
      Dim objFSO, objFolders, objSubFolders
      Set objFSO = CreateObject("Scripting.FileSystemObject")
      Set objFolders = objFSO.GetFolder("C:\")
      Set objSubFolders = objFolders.Subfolders
      For Each objItem In objSubFolders
            MsgBox objITem.Name
      Next
</script>
</body>
</html>


This code calls upon an active x object that is installed and registered on your page. If you run it, you will get a prompt to allow ActiveX, and if you say yes, it will run.

It should be no different to access your component.

FtB
0
 
uncle_medCommented:
Did you say client side? You can not use createobject on client side, that is a server object
0
 
fritz_the_blankCommented:
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
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
PvBredowAuthor Commented:
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
0
 
fritz_the_blankCommented:
There is an equivalient. However, you must have the class registered on the client machine in order for it to work.

FtB
0
 
fritz_the_blankCommented:
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>
0
 
PvBredowAuthor Commented:
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
0
 
uncle_medCommented:
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.
0
 
PvBredowAuthor Commented:
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
0
 
fritz_the_blankCommented:
If you wrap your activex control into a .wsc file and register it on each machine, alll functionality will be available.

FtB
0
 
PvBredowAuthor Commented:
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
0
 
fritz_the_blankCommented:
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
0
 
PvBredowAuthor Commented:
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
0
 
uncle_medCommented:
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!
0
 
fritz_the_blankCommented:
My page works fine as an htm. Give it a try. Make sure to disable NAV script blocking or your computer will hang.

FtB

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.