Milonic provide full featured pull down web menus for some of the worlds largest companies
click here to see what it can do for you

Download Milonic DHTML Menu
Buy Milonic DHTML Menu

Back To Start Of Archive
Taken From The Forum: Help & Support for DHTML Menu Version 5+
Forum Topic: Click to view post
Last Updated: Saturday July 14 2012 - 06:07:22

Calling a VBScript sub using the menu text as a parameter?


Poster: Ginolard
Dated: Monday December 5 2005 - 10:44:41 GMT

I'm using the MenuEdit API to dynamically create a menu of a list of shares available on a machine.

So you have a menu entitled BROWSE and then a submenu from that with the various share names (e.g. C$, ADMIN$, IPC$ etc). When a menu item is clicked I would like to call a VBScript subroutine that receives the name of the menu item that was clicked so that I can open Windows Explorer for that partiular share.

How can I do this?

Alternatively, is there a way to dynamically create the menu item so that the onclick command is "Open windows Explorer at this share"?


Poster: Andy
Dated: Wednesday December 7 2005 - 12:49:25 GMT

Hi,

This should be posible.

Do you have any code that you have already created so that we can see how you are declaring the Shares. It will help us to be able to see how we can advise further.

-- Andy


Poster: Ginolard
Dated: Wednesday December 7 2005 - 16:51:29 GMT

I get various information about the shares but I guess the two most important variables I need to pass are the machine name (e.g. HBRUXXXX1) and the path of the share (e.g. \\SERVER\FOLDER1\FOLDER2)

I used to call a simple VBscript subroutine that would open Windows Explorer passing the path as a parameter. Now that I am using the menu system I would like it to either

a) Call the same VBscript subroutine passing the path as parameter
b) Open the path directly (window.open??)

OK here's the code that creates the menu items

function BrowseMenus(machine,share,path)
{
mm_insertItem('BrowseMenuSubs',1,'text=' + share + ';url='+ path +';')

}

share is the name of the share (e.g. C$) and path is, obviously, the name of the share's path

This is the VBscript function that (previously) was called to open a selected share. The user would select the share from a listbox (hence the ShareList.Value) parameter. Ideally, I would like this Function called when the user clicks the submenu item

Function OpenShare()
If IPBox.Checked Then
objShell.Run("explorer.exe \\" & varIP & "\" & ShareList.Value)
Else
objShell.Run("explorer.exe \\" & PCList.Value & "\" & ShareList.Value)
End If

End Function


Poster: Ginolard
Dated: Thursday December 8 2005 - 15:38:42 GMT

Any ideas on this? It's the last main hurdle to overcome before I can release the latest version of my HTA ;)

I've got a semi-OK workaround that builds a parameter from the machine name and the sharename (e.g. \\HBRUXXXX\C$) and then passes that as the URL value. That's OK but it means the share is opened in Internet Explorer rather than Windows Explorer.


Poster: Ginolard
Dated: Friday December 9 2005 - 11:16:13 GMT

It looks like I should be able to use the PassItemRef module to get this information but I'm having trouble with it. Here's how I build the menu items for the shares

mm_insertItem('BrowseMenuSubs',1,'clickfunction=TestSub2();text=' + share +';')

So, each menu item just contains the name of the share and, when clicked, called TestSub2. What I need TestSub2 to do is find out what menu item called it. Can I use the PassItemRef module for this somehow?


Poster: Ginolard
Dated: Friday December 9 2005 - 13:22:49 GMT

Never mind - after much trial and error I've found a way to do it. The menu items are built, as I said, with menuedit.js and it was simply a matter of formatting!

function BrowseMenus(share)
{
shareforfunction=String.fromCharCode(34) + share + String.fromCharCode(34)

mm_insertItem('BrowseMenuSubs',1,'clickfunction=OpenShare(' + shareforfunction + ');text=' + share +';')

}

The function that builds the menu items receives the variable share but now has to add quotes around it so that it can be passed BACK to a Vbscript function as a variable when the menu item is clicked. I guess it's a bit of a hack but it works well enough.