Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Convert .vbs script to vbscript in .htm

Posted on 2006-10-30
17
Medium Priority
?
1,284 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
15 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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
 

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

810 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