Solved

Convert .vbs script to vbscript in .htm

Posted on 2006-10-30
17
1,267 Views
Last Modified: 2009-12-16
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
0
Comment
Question by:PvBredow
  • 7
  • 5
  • 3
17 Comments
 
LVL 2

Expert Comment

by:uncle_med
ID: 17834437
Did you say client side? You can not use createobject on client side, that is a server object
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 17837491
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
 

Author Comment

by:PvBredow
ID: 17838415
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
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 17838422
There is an equivalient. However, you must have the class registered on the client machine in order for it to work.

FtB
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 17838456
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
 

Author Comment

by:PvBredow
ID: 17840262
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
 
LVL 2

Expert Comment

by:uncle_med
ID: 17841305
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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

Author Comment

by:PvBredow
ID: 17842027
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
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 17842866
If you wrap your activex control into a .wsc file and register it on each machine, alll functionality will be available.

FtB
0
 

Author Comment

by:PvBredow
ID: 17848303
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
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 17885145
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
 

Author Comment

by:PvBredow
ID: 17887496
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
 
LVL 46

Accepted Solution

by:
fritz_the_blank earned 500 total points
ID: 17918084
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
 
LVL 2

Expert Comment

by:uncle_med
ID: 17919663
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
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 17922875
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

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
X-Frame-Options - click-jacking 7 46
CSS Question.. 3 72
two submit buttons one form 15 66
Need help editing script 3 54
I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now