Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


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 >> Dynamic List Box Question
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1] 2   next >   >>
Login
Message << Older Topic   Newer Topic >>
 Dynamic List Box Question - 1/14/2008 8:43:12 PM   
  patgenn123

 

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

I am very new to HTML/HTA etc.  Very new and don't understand it that much yet. It will take me some time.

I am interested in a dynamic list box that pulls info from a text file. After it does that,  I would like to be able to "click on an item from the list and then search the text box for a matching item.  The text file is tab delimited and has name, address, city state, zip, and phone number and is constantly being added to via the same hta.

I would like to:

a) click on the list box.  (The list box only has the person's name)
b) search for the line in the text file
c) Fill in the fields corresponding to the clicked name in the list box

I found this on Microsoft's website and want to know how to modify this and make it work:

   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
</SCRIPT>
<body>
   <select size="20" name="AvailableComputers" style="width:250"></select>
</body>

Keep in mind,  I have absolutely no idea what a lot of these things mean.  I am starting to get some things,  but it will take a while.  Also, remember, this is HTA.

Thank You!

Pat
 
 
Post #: 1
 
 RE: Dynamic List Box Question - 1/14/2008 9:12:08 PM   
  ehvbs

 

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

could you post

(a) a short sample of your .txt file

(b) complete code or link to the sample

(c) your .hta (to see the "fields corresponding to" the data from the file)

Thanks

ehvbs

(in reply to patgenn123)
 
 
Post #: 2
 
 RE: Dynamic List Box Question - 1/14/2008 9:34:53 PM   
  patgenn123

 

Posts: 37
Score: 0
Joined: 1/14/2008
Status: offline
Actaully,  the text file name is test.tsv.

Thank you for responding ehvbs!

Here is what I gathered from another site. 

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 = UserName.Value & vbTab & Email.Value & vbTab & _
               Title.Value & vbTab & Country.Value & vbTab & Product.Value & vbTab & DropDown1.Value & vbTab & BasicTextBox.Value & vbTab & BasicTextArea.Value
           objFile.WriteLine strLine
           objFile.Close
       Else
           Set objFile = objFSO.CreateTextFile("C:\Scripts\Test.tsv")
           strLine = UserName.Value & vbTab & Email.Value & vbTab & _
               Title.Value & vbTab & Country.Value & vbTab & Product.Value &vbTab & DropDown1.Value & vbTab & BasicTextBox.Value & vbTab & BasicTextBox.Value
           objFile.WriteLine strLine
           objFile.Close
       End If
   End Sub


In the <body>,  I have:


<input type="text" name="Name" size="15"><input type="text" name="Addressl" size="15" ><input type="text" name="City" size="15"><input type="text" name="State" size="15"><input type="text" name="Zip" size="15">
   <input type="button" value="Run Button" onClick="SaveData">

Using a button, clicking the button saves all the imputed field information into a tab delimited file and appends it.

Just need to find out how to click on the list box (of names) and focus on that contact in the text box, "pull" the info from the text box(maybe put into clipboard?) and bring it into the fields.  I guess I'm slowly learning....????

Oh yeah!  I certainly wouldn't mind having a timer "refresh" the data every 2-5 minutes or so so the list is always updated!

Thanks!

Pat

(in reply to ehvbs)
 
 
Post #: 3
 
 RE: Dynamic List Box Question - 1/14/2008 9:36:38 PM   
  patgenn123

 

Posts: 37
Score: 0
Joined: 1/14/2008
Status: offline
Short sample is like this:

John Doe 121 Anywhere Street Austin Texas 75709

Tab delimited..

Pat

(in reply to patgenn123)
 
 
Post #: 4
 
 RE: Dynamic List Box Question - 1/14/2008 9:39:01 PM   
  patgenn123

 

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

I don't know if I want to post the .hta code.  It's my very first one and it has a lot of "experimental things in it.  Yet, if you do want it, here it is:

<title>HTA Test</title>
<HTA:APPLICATION
    APPLICATIONNAME="HTA Test"
    SCROLL="no"
    SINGLEINSTANCE="yes"
    WINDOWSTATE="normal"
    <HTA:APPLICATION NAVIGABLE = "yes" />
>
</head>
<script language="VBScript">
  
  
   Sub Window_Onload
       strComputer = "."
       Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
       Set colItems = objWMIService.ExecQuery("Select * From Win32_DesktopMonitor")
       For Each objItem in colItems
           intHorizontal = objItem.ScreenWidth
           intVertical = objItem.ScreenHeight
       Next
       intLeft = (intHorizontal - 700) / 2
       intTop = (intVertical - 600) / 2
       window.resizeTo 800,600
       window.moveTo intLeft, intTop
   End Sub
Sub SaveData
//////////////////Deletes what is in the text file FIRST before adding new information to the tabbed text values////////////////////////
       Const ForWriting = 2
       Set objFSO = CreateObject("Scripting.FileSystemObject")
      Set objFile = objFSO.OpenTextFile("C:\Scripts\Test.tsv", ForWriting)
      objFile.Write ""
      objFile.Close
////////////// ends/////////////////
       Set objFSO = CreateObject("Scripting.FileSystemObject")
       If objFSO.FileExists("C:\Scripts\Test.tsv") Then
          Set objFile = objFSO.OpenTextFile("C:\Scripts\Test.tsv", 8)
           strLine = UserName.Value & vbTab & Email.Value & vbTab & _
               Title.Value & vbTab & Country.Value & vbTab & Product.Value & vbTab & DropDown1.Value & vbTab & BasicTextBox.Value & vbTab & BasicTextArea.Value
           objFile.WriteLine strLine
           objFile.Close
       Else
           Set objFile = objFSO.CreateTextFile("C:\Scripts\Test.tsv")
           strLine = UserName.Value & vbTab & Email.Value & vbTab & _
               Title.Value & vbTab & Country.Value & vbTab & Product.Value &vbTab & DropDown1.Value & vbTab & BasicTextBox.Value & vbTab & BasicTextBox.Value
           objFile.WriteLine strLine
           objFile.Close
       End If
   End Sub

Sub SetFullName
       CombinedName.Value = FirstName.Value & " " & LastName.Value
    End Sub

   Sub TestSub
       Msgbox "Testing 1-2-3."
   End Sub
   Sub Window_onLoad
       window.resizeTo 700,600
   End Sub
Sub Runone
        strCopy = DropDown1.Value
        document.parentwindow.clipboardData.SetData "text", strCopy
   End Sub
Sub RunScript
   strCopy = BasicTextArea.Value
   document.parentwindow.clipboardData.SetData "text", strCopy
End Sub
Sub DateDiff
   Set objShell = CreateObject("Wscript.Shell")
   objShell.Run "DateDiff.mxe"
End Sub
Sub RunScript1
   strAnswer = window.prompt("Please enter the domain name.", "fabrikam.com")
   If IsNull(strAnswer) Then
       Msgbox "You clicked the Cancel button"
   Else
       Msgbox "You entered: " & strAnswer
   End If
End Sub
</script>
<body>
<button onclick="DateDiff">Run Date Difference</button> <p>
<a href ="scared.hta">Go to Scared</a>
<body bgcolor="IndianRed">
<textarea name="BasicTextArea" rows="7" cols="45"></textarea>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="button" value="Copy to Clipboard" name="run_button" onClick="RunScript"><p>
<input type="button" value="Run Script" name="run_button"  onClick="TestSub">
<input type="button" value="Run Script" name="run_button"  onClick="RunScript1">
   <input type="text" name="BasicTextBox" size="50"><p>
<br>Copy to Clipboard</br>
     <select size="3" name="DropDown1" onChange="Runone">
         <option value="1">Option 1</option>
         <option value="2">Option 2</option>
         <option value="3">Option 3</option>
         <option value="4">Option 4</option>
</select>

<h2>First Name Last Name, Full Name </h2>
<input type="text" name="FirstName" size="15" onChange="SetFullName">
   <input type="text" name="LastName" size="15" onChange="SetFullName">
   <input type="text" name="CombinedName" size="25" readOnly=True> <h1> User name, Text etc.</h1>
<input type="text" name="UserName" size="15"><input type="text" name="Email" size="15" ><input type="text" name="Title" size="15"><input type="text" name="Country" size="15"><input type="text" name="Product" size="15">
   <input type="button" value="Run Button" onClick="SaveData">
   <input type="button" value="Run Button" onClick="DateDiff">
<A HREF="Microsoft'>http://www.microsoft.com/ie/ie40/demos">Microsoft </A> has some wonderful stuff!
</body>
</html>

(in reply to patgenn123)
 
 
Post #: 5
 
 RE: Dynamic List Box Question - 1/15/2008 3:55:19 AM   
  patgenn123

 

Posts: 37
Score: 0
Joined: 1/14/2008
Status: offline
As one can see,  I do not know a lot of code.  The first part is a separate HTA than the full code and a lot of this is all jumbled and makes not 100% sense.

Is there a simple way to click a contact on the list box and send it to the clipboard?

I think I can figure it out from there..

Thanks!

Pat

(in reply to patgenn123)
 
 
Post #: 6
 
 RE: Dynamic List Box Question - 1/15/2008 5:12:43 AM   
  Rischip


Posts: 468
Score: 2
Joined: 3/26/2007
Status: offline
It's just my opinion, but I think this would be much shorter code if you look at the file like a database.
Open the text file using ADODB and treat each entry like a recordset.
You could still do a dynamic listbox to jump to an individual record and begin editing it.

< Message edited by Rischip -- 1/15/2008 5:14:28 AM >


_____________________________

Rischip
Author of - The Grim Linker

(in reply to patgenn123)
 
 
Post #: 7
 
 RE: Dynamic List Box Question - 1/15/2008 5:17:24 AM   
  ehvbs

 

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

as you are a bit impatient - I can understand that - let's experiment a bit:

given this schema.ini:


      

this addresslist.txt:


      

Caution: Field separators are vbTabs!

this .hta:


      

will fill the SELECT from the file and display the names in TEXTs when you select a name
from the SELECT.

I'd have liked to add some explanations, but perhaps that can be done later.

Good luck!

ehvbs

(in reply to patgenn123)
 
 
Post #: 8
 
 RE: Dynamic List Box Question - 1/15/2008 5:46:31 AM   
  patgenn123

 

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

Well I am thankful!  Please don't get the impression I am in a hurry to get the answer.  It was about 4AM when I first posted and I pieced your initial request together in 3-4 separate posts.  Kind of dumb, but I wasn't thinking straight at the time coming back from work.

If I gave you that impression, I am sorry.

At the same time,

THANK YOU BOTH!

Pat

Rischip,  what is ADODB?  As you can see,  I am really undereducated on this stuff!

(in reply to ehvbs)
 
 
Post #: 9
 
 RE: Dynamic List Box Question - 1/15/2008 7:36:13 AM   
  ehvbs

 

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

ADO (Active Data Object(s)) is a COM technology to access data from different sources
(Database Management Systems like MS SQLServer Or files based Data Storage engines
(Access, SQLite) Or even simple text files) using (variations of) SQL.

Check whether there is an ado28.chm help file on your computer or use it online;
starting here

   http://support.microsoft.com/kb/183606
   http://msdn2.microsoft.com/en-us/library/ms810811.aspx

To see it in action, add this .hta


      

to the files I posted a little while ago. It will do the same as the array/dictionary based .hta.
The interesting point is to compare those .hta to see the common structure.

[Hi Rischip - if you are minded to do this - would you still say that database code will
be shorter?]

Both .HTAs are grown out of this template:


      

You (patgenn123) should start your code review with this file; the others are easier to analyse
if you start simple).

I know, I should publish my explanations, but they aren't ready yet - shame on me!

See you (with a bit of luck: soon)

ehvbs

(in reply to patgenn123)
 
 
Post #: 10
 
 RE: Dynamic List Box Question - 1/15/2008 8:18:08 AM   
  Rischip


Posts: 468
Score: 2
Joined: 3/26/2007
Status: offline
Are the headers in the text file?
i.e.

FirstName    LastName    Street    City
John    Doe    121 Anywhere Street    Austin Texas 75709

or is it just the data?

i.e.

John    Doe    121 Anywhere Street    Austin Texas 75709

_____________________________

Rischip
Author of - The Grim Linker

(in reply to patgenn123)
 
 
Post #: 11
 
 RE: Dynamic List Box Question - 1/15/2008 8:21:39 AM   
  ehvbs

 

Posts: 2077
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
The whole shebang is designed for

  ColNameHeader=True

(as posted)

(in reply to Rischip)
 
 
Post #: 12
 
 RE: Dynamic List Box Question - 1/15/2008 5:41:53 PM   
  Rischip


Posts: 468
Score: 2
Joined: 3/26/2007
Status: offline
Here is an option it uses an activex control Microsotft Tabular Data Control.
The only problem with using this method is when updates  are saved the whole file is overwritten.
Also there is no list box as of yet, but this is a Work In Progress.
So it should only be used by one person at a time.
This problem can be overcome with some additional code, but this version is exclusive use only. All changes are done in memory until the Save To File button is pressed.
Total Code = 98 lines including empty lines



      

test.txt [data file used for the example tab delimited]

      

< Message edited by Rischip -- 1/15/2008 5:49:51 PM >


_____________________________

Rischip
Author of - The Grim Linker

(in reply to ehvbs)
 
 
Post #: 13
 
 RE: Dynamic List Box Question - 1/16/2008 2:05:00 AM   
  ehvbs

 

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

I did some terrible things to your code:

What I did to Rischips Script
=============================================================================
( 1) Explicit .HTA
( 2) layout/look and feel => CSS
( 3) deleted the secret/hidden Javascript (Pfui!) code
( 4) corrected some typos like cmdNew instead of cmdDelete or oTSTemp
    instead of TSTemp
( 5) some cosmetic changes (">>" ==> ">|")
( 6) moved all script code to header
( 7) started to make SaveToFile reusable (parameter/no reliance on globals)
    and fit for the lazy programmer who likes others to roll his loops
    for him
( 8) Implemented just goTop and goNext as samples; too stressed to do all
    or make the button status change good
( 9) add a listbox to please patgenn123; I copied HTML/VBScript code from
    my sample(s). But what I did is a hack - to do it properly you have
    to use the Tabular Data Control

and came up with this:


      

I know, I should have worked on my explanations, but this was more fun.

Thank you for the inspiring script. There is more than one way to do it as there is more than
one middle road between "so much red tape and rules that no work ist done" on the left
and "utter chaos but working" on the right. I hope you'll agree that going left of you or
right of me is ok in both cases.

Regards

ehvbs

(in reply to Rischip)
 
 
Post #: 14
 
 RE: Dynamic List Box Question - 1/16/2008 2:51:05 AM   
  Rischip


Posts: 468
Score: 2
Joined: 3/26/2007
Status: offline
I'm fine with any changes I adapted this code from Microsoft's website.
I will reference the page once I find it again.

_____________________________

Rischip