Right now I am watching Winnie the Pooh with my daughter and there is a character called Piglet. He is always saying "Oh D-D-D-Dear". Want to know how I feel right now about scripting? Oh D-D-D-Dear!!!!!!!!!!!
Here's what I have from Microsoft's website and some of your code:
You can put anything in your text file to test this, but it's not copying the line chosen on the list box. All I am trying to do is choose a line from the list box and copy it. Oh D-D-D Dear!
Of course maybe I can I aks you where do I go in a class environment to learn this stuff from the bottom up? Is there an ****'s guide to learning VBScripting?
Nevertheless, here's what I have:
<html> <head> <hta:application id = "pgtmpl" scroll = "no" singleinstance = "yes" windowstate = "normal" /> <title>Terrible Things Done to PG's file</title>
<SCRIPT Language="VBScript"> Sub Window_OnLoad ForReading = 1 Set objFSO = CreateObject("Scripting.FileSystemObject") Set objFile = objFSO.OpenTextFile _ ("C:\Documents and Settings\Pat\Desktop\ReadMe.txt", ForReading) Do Until objFile.AtEndOfStream strLine = objFile.ReadLine Set objOption = Document.createElement("OPTION") objOption.Text = strLine objOption.Value = strLine AvailableComputers.Add(objOption) Loop objFile.Close End Sub Sub ShowClipB() Dim sTxt : sTxt = Document.ParentWindow.ClipboardData.GetData( "text" ) MsgBox sTxt End Sub
</SCRIPT> <body> <select size="10" name="AvailableComputers" style="width:250"> </select> <input id = "bttClip" class = "StdBtt" type = "BUTTON" value = "Clip" onclick = "ShowClipB"/> </body>
if you select an item from AvailableComputers and click the bttClip, the text is red from the SELECT sTxt = AvailableComputers.Options( AvailableComputers.selectedIndex ).Text written to the clipboard Document.ParentWindow.ClipboardData.SetData "text", sTxt and fetched from the clipboard sTxt = Document.ParentWindow.ClipboardData.GetData( "text" )
if you change the Sub ShowClipB to
you can check that by pasting the selected item into the notepad document.
Thank you for your reply! I don't know what I would do without you!
OK! Things are starting to look good except I have a layout question.
Please paste this and create an .hta and tell me why my fields are at the bottom and NOT at the top to the right of the list box. The Clip Button is ok where it is, but why can I not move "Full Name and Address fields to the top to the right of the list box?
<html> <head> <hta:application id = "pgtmpl" scroll = "no" singleinstance = "yes" windowstate = "normal" /> <title>Terrible Things Done to PG's file</title> <SCRIPT Language="VBScript"> Sub Window_OnLoad ForReading = 1 Set objFSO = CreateObject("Scripting.FileSystemObject") Set objFile = objFSO.OpenTextFile _ ("C:\Documents and Settings\Pat\Desktop\ReadMe.txt", ForReading) Do Until objFile.AtEndOfStream strLine = objFile.ReadLine Set objOption = Document.createElement("OPTION") objOption.Text = strLine objOption.Value = strLine AvailableComputers.Add(objOption) Loop objFile.Close End Sub
Sub ShowClipB() Dim sTxt : sTxt = Document.ParentWindow.ClipboardData.GetData( "text" )
End Sub Sub ShowClipB() Dim sTxt If 0 <= AvailableComputers.selectedIndex Then sTxt = AvailableComputers.Options( AvailableComputers.selectedIndex ).Text Document.ParentWindow.ClipboardData.SetData "text", sTxt sTxt = Document.ParentWindow.ClipboardData.GetData( "text" ) CreateObject( "WScript.Shell" ).Run "notepad.exe" Else sTxt = "nothing selected in AvailableComputers" End If End Sub </SCRIPT> <body bgcolor="green"> <select size="38" name="AvailableComputers" style="width:220" backgroundcolor = "green"><option> </option></select> <input id = "bttClip" class = "StdBtt" type = "BUTTON" value = "Clip" onclick = "ShowClipB"/> Full Name <input type="text" name="FullName" size="15"> <br/>Address <input type="text" name="Address" size="15">
as you said: that is a layout problem. While learning, it never a good idea to mix different kind of problems. That's why my template just puts the elements needed for the code on the page with no attempt to make it look cool.
If you want to tackle layout problems, start with a minimal .html template like this:
If your editor doesn't allow you to check the validity of this, get and install Tidy
Having a template 'certified' by Tidy, you use it to create a file like this
If you look at this in your browser - after checking it with Tidy, of course - you'll see that all elements are put in one block in left to right order. That's because all the elements are inline elements (think of single words in a paragraph). By inserting block elements like DIV or HR:
you put (groups of) elements in different boxes (paragraphs). That explains why the "Full Name and Address fields" are not at "the top to the right of the list box".
There are two ways to position elements on a page: The oldfashioned using tables and the modern one using CSS. Rischip showed you how to use tables to get a nice layout for the inputs, let's integrate that:
After you got the layout ready (and checked!), you can copy the BODY of the .html to the .hta, add the link the elements to the VBScript code.
If you want to continue to work on the layout, you should get a good HTML book (in my book a good (computer) book comes from O'Reilly).
All of a sudden, when I open this HTA, it is completely blank and I don't know what happened. Can Someone help me????
<html> <head> <table Border=0 WIDTH 100%> <hta:application id = "pgtmpl" scroll = "no" singleinstance = "yes" windowstate = "normal" <HTA:APPLICATION NAVIGABLE = "yes" /> <title>Pat's Contact Database</title> <SCRIPT Language="VBScript"> Sub Window_OnLoad ForReading = 1 Set objFSO = CreateObject("Scripting.FileSystemObject") Set objFile = objFSO.OpenTextFile _ ("C:\Scripts\Test.tsv", ForReading) Do Until objFile.AtEndOfStream strLine = objFile.ReadLine Set objOption = Document.createElement("OPTION") objOption.Text = strLine objOption.Value = strLine AvailableComputers.Add(objOption) Loop objFile.Close End Sub Sub SaveData Set objFSO = CreateObject("Scripting.FileSystemObject") If objFSO.FileExists("C:\Scripts\Test.tsv") Then Set objFile = objFSO.OpenTextFile("C:\Scripts\Test.tsv", 8) strLine = FullName.Value & vbTab & Address.Value & vbTab & HomePhone.Value & vbTab & MobilePhone.Value objFile.WriteLine strLine objFile.Close CreateObject( "WScript.Shell" ).Run "notepad.exe" Else Set objFile = objFSO.CreateTextFile("C:\Scripts\Test.tsv") strLine = FullName.Value & vbTab & Address.Value & vbTab & HomePhone.Value & vbTab & MobilePhone.Value objFile.WriteLine strLine objFile.Close
End If End Sub
Sub ShowClipB() Dim sTxt : sTxt = Document.ParentWindow.ClipboardData.GetData( "text" )
End Sub Sub ShowClipB() Dim sTxt If 0 <= AvailableComputers.selectedIndex Then sTxt = AvailableComputers.Options( AvailableComputers.selectedIndex ).Text Document.ParentWindow.ClipboardData.SetData "text", sTxt sTxt = Document.ParentWindow.ClipboardData.GetData( "text" ) CreateObject( "WScript.Shell" ).Run "notepad.exe" Else sTxt = "nothing selected in AvailableComputers" End If End Sub <body bgcolor="black"> <table border="0" width="100%" cell padding="5"> <td width="20%" valign="top"> <select size="20" name="AvailableComputers" style="width:220"> </td>
<td width="15%" valign="top"> <input id = "bttClip" class = "StdBtt" type = "BUTTON" value = "AutoFill Fields" onclick = "ShowClipB"/></td>
<td width="50%" valign="top"> Full Name       <input type="text" name="FullName" size="15"><p> Address          <input type="text" name="Address" size="15"><p> Home Phone   <input type="text" name="HomePhone" size="15"><p> Mobile Phone  <input type="text" name="MobilePhone" size="15"><p><input type="button" value="Save Data" onClick="SaveData"> </td>
Thank you for the answer. I will check in a few seconds. Without knowing, you are probably 100% correct.
I do have a question for you. If you can create my hta and give me some clues, I would appreciate it.
Instead of that auto-fill "button", is there a way of clicking on a singluar item in the listbox and have it autofill in the fields? I think it might have to do with pasting to clipboard(after the item is clicked), matching the word with the text line and filling it back in by using the clipboard to bring it back into the hta.
I know there is a step in between that's missing because if the "save data" button puts it into a text file, I would have to create another text file with only the first names so the listbox only shows the full names. Then when the listbox is clicked, 'poof' go to the text file with ALL the info, match name to name, copy to clipboard, and then use some sort of span technique(I think?) to get the data back.
Ok, no more jokes or hints, but blunt red tape: A .hta/.html is like zoo, where all those strange beasts have to be put in their proper cages:
<html> <head> <hta:application id = "pgtmpl" .... /> <title>Terrible Things Done to PG's file</title> <meta http-equiv = "content-type" content="text/html; charset=iso-8859-1"/> <meta http-equiv = "content-script-type" content = "text/vbscript"/> <style type = "text/css"> .stdBtt { width: 80; } ... css for layout .... </style> <script language = "VBScript" type = "text/vbscript" > '<![CDATA[
.... script (dragons) ....
''= refreshes the HTA page, which includes re-running any Windows_Onload code ' ============================================================================ Sub reloadHTA() location.reload True End Sub
']]> </script> </head> <body onload = "initWhenLoaded" onunload = "exitWhenClosed"> <TABLE id = "tblEntry"> <!-- stolen from Rischip to have a base for SaveData ... </TABLE> <hr /> <input class = "StdBtt Meta" type = "BUTTON" value = "reload" onclick = "reloadHTA"/> </body> </html>
[it would really be easier to start with a template (roll your own, if you don't like mine) and fill in the parts of different types (layout, script, elements/controls) step by step]