Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7986933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:59:48+00:00 2026-06-04T11:59:48+00:00

has anyone experience with passing a parameter to a function called with getref ?

  • 0

has anyone experience with passing a parameter to a function called with getref ?
Following code is just an example, doens’t work, how to pass the parameter to the mySub sub?

<button id="myBtn">Click me</button>

<script type="text/vbscript">
  document.getElementById("myBtn").onclick=GetRef("mySub") 

  Sub mySub(parameter)
   alert(parameter)
  End Sub
</script>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T11:59:50+00:00Added an answer on June 4, 2026 at 11:59 am

    First look at this article about event handling (anybody knows a better reference?) to get the context for:

    The code provided in the onclick attribute will be called when the
    user clicks on the text enclosed in the span. This mechanism is great
    for small snippets of code, but it becomes cumbersome when you have a
    lot of script. This event mechanism works with both VBScript and
    JScript.

    What happens behind the scenes is that Internet Explorer calls into
    the script engine with the script code and tells the engine to create
    an anonymous function (a function with no name). Those of you who know
    VBScript are probably wondering how it does this, since VBScript
    doesn’t support anonymous functions. VBScript actually creates a
    subroutine called “anonymous” containing the script and returns a
    pointer to the function that is then hooked up to the event.

    Then experiment with this .hta:

    <html>
     <!-- !! http://stackoverflow.com/questions/10741292/vbscript-getref-with-parameter
     -->
     <head>
      <title>GetRef HTA</title>
      <HTA:APPLICATION
        APPLICATIONNAME="GetRef HTA"
      >
      <SCRIPT Language="VBScript">
       Sub SetClickHandlers()
         Set bttB.onClick = GetRef("NoParmsBttB")
         Set bttE.onClick = GetRef("Magic")
         Set bttF.onClick = GetRef("Magic")
       End Sub
       ' trivial handler, literally set
       Sub NoParmsBttA()
         Log "NoParmsBttA() called."
       End Sub
       ' trivial handler, set via GetRef
       Sub NoParmsBttB()
         Log "NoParmsBttB() called."
       End Sub
       ' one handler for many buttons, literally set
       Sub handleClickCD(oBtt)
         Log "handleClickCD() called; you clicked " & oBtt.id
       End Sub
       ' one handler for many buttons, set via Magic() & GetRef
       Sub handleClickEF(oBtt, dtWhen)
         Log "handleClickEF() called; you clicked " & oBtt.id & " at " & CStr(dtWhen)
       End Sub
       ' stuffed via GetRef into onClick
       Sub Magic()
         handleClickEF Me, Now
       End Sub
       Sub Log(s)
         MsgBox s, 0, Now
       End Sub
      </SCRIPT>
     </head>
      <body onLoad="SetClickHandlers">
       <!-- literal onClick handler in html code -->
       <button id="bttA" onClick="NoParmsBttA">A</button>
       <!-- no literal onClick handler, will be set by SetClickHandlers via GetRef() -->
       <button id="bttB">B</button>
       <!-- literal onClick handlers with parameter (Me, i.e. the Button) -->
       <button id="bttC" onClick="handleClickCD Me">C</button>
       <button id="bttD" onClick="handleClickCD Me">D</button>
       <!-- Two params handler via SetClickHandlers & Magic -->
       <button id="bttE">E</button>
       <button id="bttF">F</button>
     </body>
    </html>
    

    to see

    1. that/how you can specify a Sub with no params to handle clicks literally or via GetRef (A resp. B)
    2. that you can use one parameterized Sub to handle clicks on many buttons, because the engine puts the literal code into an anonymous Sub (with no params) (C/D)
    3. that you can’t use GetRef(“SubWithLotsOfParms”) to set the onClick attribute – it needs s Sub with no params
    4. that you can let a named Sub with no params (e.g. Magic) do the work of the engine’s anonymous one; this Sub then can be used with GetRef

    WRT Salman A’s answer:

    If you really need an error message like:

    ---------------------------
    Error
    ---------------------------
    A Runtime Error has occurred.
    Do you wish to Debug?
    
    Line: 54
    Error: Wrong number of arguments or invalid property assignment: 'mySub'
    ---------------------------
    Yes   No   
    ---------------------------
    

    then you just have to add:

       Sub mySub(parameter)
         alert(parameter.toString())
       End Sub
    

    and

       <!-- literal onClick handler in html code -->
       <button id="bttG" onClick="mySub">G</button>
    

    to the test .hta.

    WRT Peter’s proposal – it pays to keep it simple:

    Option Explicit
    Sub WithLotsOfParms(a, b, c, d)
      WScript.Echo Join(Array(a, b, c, d))
    End Sub
    Dim f : Set f = GetRef("WithLotsOfParms")
    WithLotsOfParms 1, 2, 3, 4
    f               1, 2, 3, 4
    

    output:

    cscript 01.vbs
    1 2 3 4
    1 2 3 4
    

    That you use the name of the variable set with GetRef() exactly as you use the literal Sub/Function name could have been established yesterday.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

has anyone experience with trapdoor hashes? I was looking for some code example or
Has anyone had experience using SSL with net.tcp binding in WCF? Ive read its
Has anyone had any experience in saving app preferences (within app, not in Settings
Has anyone had any experience using Adobe Air to create BitTorrent application? Is there
Has anyone had any experience writing a web control (in either ASP.net, or javascript/HTML/CSS),
Has anyone got practical experience or a reference for a scheme that implements a
Has anyone got any experience/thoughts on the CSLA.netContrib project on codeplex - here .
Has anyone had any experience of talking between an iSeries (using IBM's Websphere MQ)
I am wondering if anyone has experience working on Django projects in a small
I am using IIS 7.0 + Windows Server 2008. Anyone has experience to configure

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.