locked
VBscript HTA RRS feed

  • Question

  • Dear Exprt,

    How to display value when start hta file.

    <html>
    <head>
    <title>HTA Test</title>
    <HTA:APPLICATION
         ID="objTest"
         APPLICATIONNAME="HTA Test"
         SCROLL="yes"
         SINGLEINSTANCE="yes"
    >
    </head>

    <SCRIPT LANGUAGE="VBScript">

        Sub Computername
            Dim objPC
               Set objPC = WScript.CreateObject( "WScript.Network" )
              objPC = objPC.ComputerName
              BasicTextbox.value
        End Sub

    </SCRIPT>

    <body>

      <input type="text" name="BasicTextbox" size="30"><P>

    </body>


    Support@Mytechnet.me

    • Moved by Bill_Stewart Tuesday, July 15, 2014 6:27 PM Unanswerable drive-by question
    Monday, May 12, 2014 12:47 PM

Answers

  • Go back and learn the fundamentals of DHTML.

    I gave you the solution and you didn't even use it.

    You cannot have multip0le functions/subs with the same name. Only the last one will ever be valid.

    Study this then go to W3Schools and learn VBScript with HTML.

    <html>
      <head>
      <title>HTA Test</title>
      <HTA:APPLICATION 
          ID="objTest" 
          APPLICATIONNAME="HTA Test"
           SCROLL="yes"
           SINGLEINSTANCE="yes"
      >  
     <script language="vbscript">
      
         Sub window_onload
            Set objPC = CreateObject( "WScript.Network" )
            Computernm.value = objPC.ComputerName
            Username.value = objPC.UserName
                 
         End Sub
      
     </script>
    </head>
    
    <body>
    
        <label for="Computernm">Computer Name:<input type="text" id="Computernm" size="20"></label><br />
        <label for="Username">User Name:<input type="text" id="Username" size="20"></label><br />
    
    </body>
    </html>


    ¯\_(ツ)_/¯

    • Proposed as answer by jrv Tuesday, July 15, 2014 7:26 PM
    • Marked as answer by Just Karl Wednesday, July 23, 2014 8:25 PM
    Monday, May 12, 2014 5:17 PM

All replies

  • Change to this:

        Sub window_onload
              Set objPC = WScript.CreateObject( "WScript.Network" )
              BasicTextbox.value = objPC.ComputerName
               
         End Sub

      <input type="text" ID="BasicTextbox" size="30">


    ¯\_(ツ)_/¯

    Monday, May 12, 2014 1:00 PM
  • JRV correctly exposed one problem in that the text box is not instatiated until the HTA window is loaded, thus the use of the onload routine, but there remains one other problem.  The WScript object is not instantiated in mshta.exe, so it can't be used here.  Just remove that part and the CreateObject() method inherent in VBS will do the job.


    Tom Lavedas

    Monday, May 12, 2014 3:57 PM
  • Yes - missed that little piece

    Set objPC = CreateObject( "WScript.Network" )


    ¯\_(ツ)_/¯

    Monday, May 12, 2014 4:32 PM
  • Thanks its work!

    But when i add another textbox its load only last one not first

    <html>
     <head>
     <title>HTA Test</title>
     <HTA:APPLICATION
         ID="objTest"
         APPLICATIONNAME="HTA Test"
          SCROLL="yes"
          SINGLEINSTANCE="yes"
     >
     </head>
     
    <SCRIPT LANGUAGE="VBScript">
     
        Sub window_onload
        Computernm.Focus
             Dim objPC
                Set objPC = CreateObject( "WScript.Network" )
               Computernm.value = objPC.ComputerName
              
               
        End Sub
         
          Sub window_onload
             Dim objPC
                Set objPC = CreateObject( "WScript.Network" )
               Username.value = objPC.UserName
               
        End Sub
     
    </SCRIPT>

     
    <body>
     
    <label for="Computer Name">Computer Name:</label>  <input type="text" name="Computernm" size="20"><P>
     <label for="Usernm Name">User Name:</label> <input type="text" name="Username" size="20"><P>
     
    </body>


    Support@Mytechnet.me

    Monday, May 12, 2014 5:06 PM
  • Go back and learn the fundamentals of DHTML.

    I gave you the solution and you didn't even use it.

    You cannot have multip0le functions/subs with the same name. Only the last one will ever be valid.

    Study this then go to W3Schools and learn VBScript with HTML.

    <html>
      <head>
      <title>HTA Test</title>
      <HTA:APPLICATION 
          ID="objTest" 
          APPLICATIONNAME="HTA Test"
           SCROLL="yes"
           SINGLEINSTANCE="yes"
      >  
     <script language="vbscript">
      
         Sub window_onload
            Set objPC = CreateObject( "WScript.Network" )
            Computernm.value = objPC.ComputerName
            Username.value = objPC.UserName
                 
         End Sub
      
     </script>
    </head>
    
    <body>
    
        <label for="Computernm">Computer Name:<input type="text" id="Computernm" size="20"></label><br />
        <label for="Username">User Name:<input type="text" id="Username" size="20"></label><br />
    
    </body>
    </html>


    ¯\_(ツ)_/¯

    • Proposed as answer by jrv Tuesday, July 15, 2014 7:26 PM
    • Marked as answer by Just Karl Wednesday, July 23, 2014 8:25 PM
    Monday, May 12, 2014 5:17 PM
  • What is off-topic here?


    ¯\_(ツ)_/¯

    Tuesday, July 15, 2014 7:26 PM
  • What is off-topic here?


    ¯\_(ツ)_/¯

    That's a good question.

    I'm tempted to move it back to the Scriptiung Guys forum...

    Bill?


    When you see answers and helpful posts, please click Vote As Helpful, Propose As Answer, and/or Mark As Answer.
    My Blog: Unlock PowerShell
    My Book: Windows PowerShell 2.0 Bible
    My E-mail: -join ('6F6C646B61726C406F75746C6F6F6B2E636F6D'-split'(?<=\G.{2})'|%{if($_){[char][int]"0x$_"}})

    Wednesday, July 23, 2014 8:26 PM