Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


RE: Dynamic List Box Question

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,55402
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> RE: Dynamic List Box Question
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: <<   < prev  1 [2]
Login
Message << Older Topic   Newer Topic >>
 RE: Dynamic List Box Question - 1/16/2008 4:58:36 AM   
  ehvbs

 

Posts: 2077
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi patgenn123,

Dim sTxt : sTxt = document.parentwindow.clipboardData.GetData("text")

To run an external program use the .Run or the .Exec methods of the WScript.Shell
object (you get one with CreateObject( "WScript.Shell" ).

(in reply to patgenn123)
 
 
Post #: 21
 
 RE: Dynamic List Box Question - 1/16/2008 5:17:11 AM   
  ehvbs

 

Posts: 2077
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi patgenn123,

this .hta - based on my tmplate.hta and the first lines of your experimental
script will show you

  (1) a structured .hta file (scripts in head etc)

  (b) how to save data from inputs to a file

  (c) clipboard access and a simple example for .Run


      

(in reply to ehvbs)
 
 
Post #: 22
 
 RE: Dynamic List Box Question - 1/16/2008 5:38:23 AM   
  patgenn123

 

Posts: 37
Score: 0
Joined: 1/14/2008
Status: offline
ehvbs,

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>

(in reply to ehvbs)
 
 
Post #: 23
 
 RE: Dynamic List Box Question - 1/16/2008 6:03:38 AM   
  ehvbs

 

Posts: 2077
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi patgenn12 (and Piglet),

try this:


      

I inserted minimal structure, removed the dependency on a file, and completed my quick "read from the
clipboard" sample: now writing is handled too.

ehvbs

(in reply to patgenn123)
 
 
Post #: 24
 
 RE: Dynamic List Box Question - 1/16/2008 7:38:53 AM   
  patgenn123

 

Posts: 37
Score: 0
Joined: 1/14/2008
Status: offline
Bravo!

Thank you ehvbs!

One other alternative question though.

What if I click on "John" or "Doe" or any other text in the list box and "one click copy" it to the clipboard?

How does that work?

Also, where would I put that run command to have it run another program? I need it to run everytime I click on anything in that listbox.

After that,  I might be done bothering anyone until next time.

I need some education on this stuff.  Oh D-D-D-Dear!

ehvbs,  you have been a a real help!  I can't thank you enough!

Pat

(in reply to ehvbs)
 
 
Post #: 25
 
 RE: Dynamic List Box Question - 1/16/2008 7:14:30 PM   
  ehvbs

 

Posts: 2077
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi patgenn123,

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.


 

(in reply to patgenn123)
 
 
Post #: 26
 
 RE: Dynamic List Box Question - 1/16/2008 7:25:45 PM   
  patgenn123

 

Posts: 37
Score: 0
Joined: 1/14/2008
Status: offline
ehvbs,

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">
 
 
</body>
</html>

Your reply would be appreciated!!

Thanks!

Pat

(in reply to ehvbs)
 
 
Post #: 27
 
 RE: Dynamic List Box Question - 1/16/2008 8:41:01 PM   
  ehvbs

 

Posts: 2077
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi patgenn123,

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

   http://www.w3.org/People/Raggett/tidy/
   http://tidy.sourceforge.net/

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).

Regards

ehvbs

(in reply to patgenn123)
 
 
Post #: 28
 
 RE: Dynamic List Box Question - 1/20/2008 8:31:24 PM   
  patgenn123

 

Posts: 37
Score: 0
Joined: 1/14/2008
Status: offline
I was wondering if I could get some help here.

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 &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp<input type="text" name="FullName" size="15"><p>
            Address &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp<input type="text" name="Address" size="15"><p>
            Home Phone &nbsp&nbsp<input type="text" name="HomePhone" size="15"><p>
            Mobile Phone&nbsp&nbsp<input type="text" name="MobilePhone" size="15"><p><input type="button" value="Save Data" onClick="SaveData"> </td>
   
<td width="15%" valign="top">             
           <a href ="scared.hta">Contact List</a>

</td>
</table>

 

</body>
</html>

Thank You!

Pat

(in reply to patgenn123)
 
 
Post #: 29
 
 RE: Dynamic List Box Question - 1/21/2008 4:36:23 AM   
  ehvbs

 

Posts: 2077
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi patgenn123,

what did you want to write between those two lines:

  End Sub 
  <body bgcolor="black">

??

Wondering

ehvbs

(in reply to patgenn123)
 
 
Post #: 30
 
 RE: Dynamic List Box Question - 1/21/2008 5:14:44 AM   
  patgenn123

 

Posts: 37
Score: 0
Joined: 1/14/2008
Status: offline
Hey ehvbs!!!!!!!!!!!! 

How's it going today?  Well, I hope!

Actually, since that's the beginning of the body, there should have been a space to denote the beginning of the body.

Is that the reason for the blank hta?

Pat

(in reply to ehvbs)
 
 
Post #: 31
 
 RE: Dynamic List Box Question - 1/21/2008 5:18:56 AM   
  Rischip


Posts: 468
Score: 2
Joined: 3/26/2007
Status: offline
There is also a table in the head section that doesn't belong there.

_____________________________

Rischip
Author of - The Grim Linker

(in reply to patgenn123)
 
 
Post #: 32
 
 RE: Dynamic List Box Question - 1/21/2008 5:37:35 AM   
  patgenn123

 

Posts: 37
Score: 0
Joined: 1/14/2008
Status: offline
Hello  Rischip!

How is it going today with you?  I hope well! 

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.

Am I thinking of this logically?

Pat

(in reply to Rischip)
 
 
Post #: 33
 
 RE: Dynamic List Box Question - 1/21/2008 5:42:02 AM   
  ehvbs

 

Posts: 2077
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
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]

(in reply to Rischip)
 
 
Post #: 34
 
 
Page:  <<   < prev  1 [2]
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> RE: Dynamic List Box Question Page: <<   < prev  1 [2]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts