Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

More efficient / manageable way to code this HTA w/ VBScript?

bdwilcox

Technical User
Jul 7, 2022
6
0
1
US
I have about 300 links I want to put in a reference HTA file for new people to refer to. For each link, I want the user to be able to either copy the URL or launch the site for each. The problem I'm running into is I can't find a way for the HTML code to set the value of a generic variable, use that in the input field then pass that through to generic VBScript subroutines that use those variables in their actions. Instead, I'm having to create a sub for each link, where a specifically named variable is set by the field's HTML code then passed to a subroutine that only uses that specific variable. So for 300 links, I'm ending up with 300 variables I need to set and 600 subroutines, one for link copy and one for link launch, for each and every URL. Is there any way to make this more efficient and more manageable? I was hoping I could set a variable to the URL, use that variable in the input field and then pass that variable to the VBScript subs as a generic variable name so I can have just one sub per action that any link to it can utilize by feeding it that generically named variable. Any help would be appreciated.

Here's some sample code to show you what I've come up with so far to just get this to work:

HTML:
<!DOCTYPE html>

<html lang="en-US">

<head>
<title>Reference Websites Test</title>

<HTA:APPLICATION
     APPLICATIONNAME="Reference Websites Test
     Caption="Yes"
     MaximizeButton="Yes"
     MinimizeButton="Yes"
     SCROLL="Yes"
     SINGLEINSTANCE="yes"
     WINDOWSTATE="Normal"
     BORDER="Normal"
     Icon=C:\Windows\System32\Magnify.exe
     <font face=Arial>
</head>

<script language="VBScript">
dim WebsiteX,YahooSite,AOLSite,DuckDuckGoSite

YahooSite="https://www.yahoo.com"
AOLSite="https://www.AOL.com"
DuckDuckGoSite="https://www.duckduckgo.com"

Sub YahooOpen
WebsiteX=YahooSite
OpenSite
End Sub

Sub YahooCopy()
    document.parentwindow.clipboardData.SetData "text", YahooURL.value
    MsgBox "Link Copied to the Clipboard",vbInformation,Title
End Sub


Sub AOLOpen
WebsiteX=AOLSite
OpenSite
End Sub

Sub AOLCopy()
    document.parentwindow.clipboardData.SetData "text", AOLURL.value
    MsgBox "Link Copied to the Clipboard",vbInformation,Title
End Sub


Sub DuckDuckGoOpen
WebsiteX=DuckDuckGoSite
OpenSite
End Sub

Sub DuckDuckGoCopy()
    document.parentwindow.clipboardData.SetData "text", DuckDuckGoURL.value
    MsgBox "Link Copied to the Clipboard",vbInformation,Title
End Sub


Sub OpenSite
Set browobj = CreateObject("Wscript.Shell")
browobj.Run "chrome.exe -new-window -start-maximized -url " & WebsiteX
End Sub

</script>


<body>
<font face=Arial>
<font color=FFFF23>
<body bgcolor=#1D4D7C>
<font size="-1">

<text><b>This site is not used much anymore except for webmail.</b></text>
<br>
<!-- The Yahoo text field -->
<input type="text" value="https://www.yahoo.com" id="YahooURL" size="50" readonly="readonly">

<!-- The button used to copy the text -->
<input type="button" name="ButtonCopy" value="Copy Link" onclick="YahooCopy">

<!-- The button used to open browser to that page -->
<button onclick="YahooOpen">Click to Open Site</button>

<br>
<br>

<text><b>This site is old.</b></text>
<br>
<!-- The AOL text field -->
<input type="text" value="https://www.aol.com" id="AOLURL" size="50" readonly="readonly">

<!-- The button used to copy the text -->
<input type="button" name="ButtonCopy" value="Copy Link" onclick="AOLCopy">

<!-- The button used to open browser to that page -->
<button onclick="AOLOpen">Click to Open Site</button>

<br>
<br>

<text><b>This site is newer and spies less than Google.</b></text>
<br>
<!-- The DuckDuckGo text field -->
<input type="text" value="https://www.duckduckgo.com" id="DuckDuckGoURL" size="50" readonly="readonly">

<!-- The button used to copy the text -->
<input type="button" name="ButtonCopy" value="Copy Link" onclick="DuckDuckGoCopy">

<!-- The button used to open browser to that page -->
<button onclick="DuckDuckGoOpen">Click to Open Site</button>

</font>
</body>
 
Last edited:

Part and Inventory Search

Sponsor

Back
Top