Building Tables...

Batch, ASP, JScript, Kixtart, etc.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Locked
User avatar
rasimmer
Posts: 182
Joined: Fri Jan 30, 2009 12:37 am

Building Tables...

Post by rasimmer » Fri Apr 03, 2009 4:29 am

There are 2 basic ways to create tables in a HTA (or any web-based code), and that is string concantenation (which I normally use):

Code: Select all

VbScript:
 
strTable = "<table><thead><tr><td>Name</td><td>Salary</td></tr></thead>"
strTable = strTable & "<tbody><tr><td>Frank</td><td>$52,362.54</td></tr>"
strTable = strTable & "<tr><td>Julie</td><td>$54,368.22</td></tr>"
strTable = strTable & "</tbody></table>"
 
spn_Data.InnerHTML = strTable
 
HTML:
 
<span id="spn_Data"></span>

OR

Utilize DOM (typically used in JavaScript)

Code: Select all

VBScript:
    Set objRow = objTableBody.InsertRow()
    objRow.Style.fontWeight = "bold"
    
    Set objCell = objRow.InsertCell()
    objCell.InnerText = "Name"
    
    Set objCell = objRow.InsertCell()
    objCell.InnerText = "Salary"
 
    Set objRow = objTableBody.InsertRow()
 
    Set objCell = objRow.InsertCell()
    objCell.InnerText = "Frank"
    
    Set objCell = objRow.InsertCell()
    objCell.InnerText = "$52,362.54"
 
HTML:

            <TABLE ID = "objTable" border = "1" >
                <TBODY ID = "objTableBody">
                </TBODY>
            </TABLE>
 

The above works all fine and dandy, but when you start adding attributes to the DOM method, like an image, then I start having issues. Specifically the "onclick" attribute. I have tried numerous ways to get it to work and it's not playing nice. Does anyone have a way in invoke this utilizing VBScript?

Code: Select all

            Set img = document.createElement("img")
            img.src="file:////server/share/picture.bmp"
            img.alt = "I want to double-click this image and run something"
            img.setAttribute "onClick", "vbScript:Test()" 'doesn't work
            img.setAttribute "onClick", "Test()"  'doesn't work
            img.setAttribute "onClick", Test  'doesn't work
            img.onClick "vbScript:Test()"  'doesn't work
            img.onClick "Test()"  'doesn't work
            img.onClick "Test"  'doesn't work
            img.onClick Test()  'doesn't work
            img.style.width="25"
            img.style.height="25"
            objcell.appendChild(img)
rasimmer2009-04-03 11:30:25

User avatar
jvierra
Posts: 13793
Joined: Tue May 22, 2007 9:57 am
Contact:

Building Tables...

Post by jvierra » Fri Apr 03, 2009 5:30 am

The problem, it seems, is what to call it.

You are tryiong to use an "attribute" to set an "event". TIy need to use the event system to define this. This requires a wireup of teh function to the event. The is done with teh "attachEvent" methgod of teh object.

Here is a simple example:

Code: Select all

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>My HTML Application</title>
<script language="vbscript">
Sub window_onload()
    Set img = document.createElement("img")            
    img.src="http://tbn3.google.com/images?q=tbn:59BjliqWWqr1eM:http://teacupyorkies.files.wordpress"            
    img.alt = "I want to double-click this image and run something"            
    set fptest = getRef("test")
    img.attachEvent "onclick", fptest   
    bdy.appendChild( img)
End Sub
Sub Test()
    MsgBox "clicked"
End Sub
</script>
<hta:application
 applicationname="MyHTA" 
 border="dialog"
 borderstyle="normal"
 caption="My HTML Application"
 contextmenu="no"
 icon="myicon.ico"
 maximizebutton="no"
 minimizebutton="yes"
 navigable="no"
 scroll="no"
 selection="no"
 showintaskbar="yes"
 singleinstance="yes"
 sysmenu="yes"
 version="1.0"
 windowstate="normal"
>
</head>
<body >
<div id="bdy"></div>
<!-- HTML goes here -->
</body>
</html>

Shorthand for this:
set fptest = getRef("test") img.attachEvent "onclick", fptest is this: img.attachEvent "onclick", getRef("test")
<object>.detachAEvent "onclick"

will remove teh event.

The function pointer can point to either a "Sub" or a "function" but function must take no arguments.

One other note:

The events "onattachevent" and "ondetachevent" are fired.

jvierra2009-04-03 12:34:25

User avatar
rasimmer
Posts: 182
Joined: Fri Jan 30, 2009 12:37 am

Building Tables...

Post by rasimmer » Fri Apr 03, 2009 6:22 am

But see, that's the thing about being able to find something on the web, you have to know what to search for. I searched atleast 20 times with .createElement("img") + VBS + VBscript and only found a plethora of articles on JScript, which I don't use very often. I was about to start developing again in ASP.NET, so I know who to shoot ? to...

User avatar
jvierra
Posts: 13793
Joined: Tue May 22, 2007 9:57 am
Contact:

Building Tables...

Post by jvierra » Fri Apr 03, 2009 6:58 am

Here - on a system with NET 3.5 and Silverlight installed. Copy and paste this into a file and give it an XAML extension then double click the file. Be sure it has the correct extrension an and no TXT after it.

Story.XAML (for ease put it on your desktop)

Code: Select all

<Page 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Page1"
    >
<Canvas>
    <Canvas.Triggers>
        <EventTrigger RoutedEvent="Canvas.Loaded">
            <BeginStoryboard>
                <Storyboard>
          <DoubleAnimation AutoReverse="True" From="80" To="200" 
                       Duration="0:0:3" 
         Storyboard.TargetName="tbHello"
         Storyboard.TargetProperty="(Canvas.Left)" RepeatBehavior="Forever"/>
         </Storyboard>
             </BeginStoryboard>
        </EventTrigger>
    </Canvas.Triggers>
    <Canvas Canvas.Left="10" Canvas.Top="10" Height="300" Width="300" Background="#efefef">
        <Rectangle Canvas.Top="25" Canvas.Left="25" 
            Width="200" Height="150" Fill="Yellow" />
        <TextBlock Name="tbHello"
             Canvas.Left="36" Canvas.Top="80"
             Foreground="Maroon" FontFamily="Verdana" 
             FontSize="24" FontWeight="Bold"
             Text="Hello From Silverlight!">
        </TextBlock>
    </Canvas>
</Canvas>
</Page>

This will demo how powerful teh next generration of page language is and can be. It will be able to be used to build forms in PowerShell V2 (requires delegates/events). It is much easier to work with than DHTML and can create both dektop WinForms and Web pages. Scripts will be written using a "code-behind" page in the language of your choice.

Consider this an HTA on steroids. The next versions of this technology is ready for release shortly. It promises to be more flexible and powerful than any page languge preceeding it.

The concept will, most likely, drive a number of other vendors to create similar page languages that may become industry specific. The idea of moving to an XML descripbed object model for both the creation of teh object and teh sorage and editing of that object is not new. PowerShell already does this with it's object format to CLIXML.

Many service architecture have been saving objects using this method. Now we will have it fo r Windows/Web Forms.





jvierra2009-04-03 14:03:28

User avatar
rasimmer
Posts: 182
Joined: Fri Jan 30, 2009 12:37 am

Building Tables...

Post by rasimmer » Sun Apr 05, 2009 11:18 pm

I have already played with Silverlight in an HTA, the "Scripting Guys" had an article on it. I haven't really delved into PowerShell yet because I really like the GUI interface that HTA's provide and I can do most things in VBScript. In PS, are you utilizing InternetExplorer.Application and just writing to it dynamically? HTA's just give you the ablility to subvert all of the ActiveX security which is obviously convenient for client-side scripting.

User avatar
jvierra
Posts: 13793
Joined: Tue May 22, 2007 9:57 am
Contact:

Building Tables...

Post by jvierra » Mon Apr 06, 2009 2:20 am

In PowerShell yuo can either use InternetExplorer.application, WebClient or Windows Forms.

With V2 of PoSH we should be able to use XAML forms.

Locked