Discussion:
CSV To Marquee HTA App /w File Selection...
(too old to reply)
tbader01
2007-08-06 19:06:03 UTC
Permalink
Hello Everyone,
A while back someone helped me write an HTA app that takes a CSV file and
makes all of the contents into a marquee across the top of the screen. I have
worked on some additional features such as figure out a way to determine the
current directory since WScript.ScriptFullName isn't available in HTA (took
me forever to figure that out!), dynamically adjusting for various # of
columns, adjusting for different screen resolutions, and I also converted the
code to VBS as well.
Well, what I would like to be able to do now is to list the CSV's in the
HTA's directory, click one of them, run my CSV2MrqXXX script, and clear the
CSV selection dialog box.
I have been messing around with this for quite a while, and would just like
to see my vision come true! Below are my CSVList1.hta code, CSV2MrqJS1.hta,
and CSV2MrqVBS1.hta code, which hopefully someone might be able to put the
two together. The CSV2Mrq's will work if you change "server.csv" to any CSV
file (/w a header) in the same dir as the hta.
Here are my 3 hta's (Thanks for any assistance you can give!):

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

<SCRIPT LANGUAGE="VBScript">

window.resizeTo 640,480

Sub Window_Onload
const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
'WScript.ScriptFullName not valid in HTA. Use document.location.pathname
instead...
URL_Path_With_ScriptName = document.location.pathname
'Stringip off Scriptname and only leave Drive Letter and Path...
URL_Path_Only =
Left(URL_Path_With_ScriptName,InStrRev(URL_Path_With_ScriptName,"\"))
'If path has spaces in it (Ex. C:\Program%20Files), DeCode to standard
Windows format...
Non_URL_Path = URLDecode(URL_Path_Only)
ListFile(No_URL_Path & "*.csv")
End Sub

Sub MessageBox
MsgBox CSVFile.value
End Sub

Function URLDecode(String)
String = Replace(String, "+", " ")
For i = 1 To Len(String)
sT = Mid(String, i, 1)
If sT = "%" Then
If i+2 < Len(String) Then
sR = sR & _
Chr(CLng("&H" & Mid(String, i + 1, 2)))
i = i+2
End If
Else
sR = sR & sT
End If
Next
URLDecode = sR
End Function

' Changes:
' 2006-01-19 Extended to handle the special case of filter masks
' ending with a ".". Thanks to Dave Casey for the hint.
Function ListFile(Path)
Dim a: a = ListDir(Path)
If UBound(a) = -1 then
MsgBox "No files found."
Exit Function
End If
Dim Filename, PutList
For Each Filename In a
Set objOption = Document.createElement("OPTION")
objOption.Text = Filename
objOption.value = Filename
CSVFile.add(objOption)
Next
End Function

' Returns an array with the file names that match Path.
' The Path string may contain the wildcard characters "*"
' and "?" in the file name component. The same rules apply
' as with the MSDOS DIR command.
' If Path is a directory, the contents of this directory is listed.
' If Path is empty, the current directory is listed.
' Author: Christian d'Heureuse (www.source-code.biz)
Public Function ListDir (ByVal Path)
Dim fso: Set fso = CreateObject("Scripting.FileSystemObject")
If Path = "" then Path = "*.*"
Dim Parent, Filter
if fso.FolderExists(Path) then ' Path is a directory
Parent = Path
Filter = "*"
Else
Parent = fso.GetParentFolderName(Path)
If Parent = "" Then If Right(Path,1) = ":" Then Parent = Path: Else
Parent = "."
Filter = fso.GetFileName(Path)
If Filter = "" Then Filter = "*"
End If
ReDim a(10)
Dim n: n = 0
Dim Folder: Set Folder = fso.GetFolder(Parent)
Dim Files: Set Files = Folder.Files
Dim File
For Each File In Files
If CompareFileName(File.Name,Filter) Then
If n > UBound(a) Then ReDim Preserve a(n*2)
a(n) = File.Path
n = n + 1
End If
Next
ReDim Preserve a(n-1)
ListDir = a
End Function

Private Function CompareFileName (ByVal Name, ByVal Filter) ' (recursive)
CompareFileName = False
Dim np, fp: np = 1: fp = 1
Do
If fp > Len(Filter) Then CompareFileName = np > len(name): Exit Function
If Mid(Filter,fp) = ".*" Then ' special case: ".*" at end of filter
If np > Len(Name) Then CompareFileName = True: Exit Function
End If
If Mid(Filter,fp) = "." Then ' special case: "." at end of filter
CompareFileName = np > Len(Name): Exit Function
End If
Dim fc: fc = Mid(Filter,fp,1): fp = fp + 1
Select Case fc
Case "*"
CompareFileName = CompareFileName2(name,np,filter,fp)
Exit Function
Case "?"
If np <= Len(Name) And Mid(Name,np,1) <> "." Then np = np + 1
Case Else
If np > Len(Name) Then Exit Function
Dim nc: nc = Mid(Name,np,1): np = np + 1
If Strcomp(fc,nc,vbTextCompare)<>0 Then Exit Function
End Select
Loop
End Function

Private Function CompareFileName2 (ByVal Name, ByVal np0, ByVal Filter,
ByVal fp0)
Dim fp: fp = fp0
Dim fc2
Do ' skip over "*" and "?" characters in
filter
If fp > Len(Filter) Then CompareFileName2 = True: Exit Function
fc2 = Mid(Filter,fp,1): fp = fp + 1
If fc2 <> "*" And fc2 <> "?" Then Exit Do
Loop
If fc2 = "." Then
If Mid(Filter,fp) = "*" Then ' special case: ".*" at end of filter
CompareFileName2 = True: Exit Function
End If
If fp > Len(Filter) Then ' special case: "." at end of filter
CompareFileName2 = InStr(np0,Name,".") = 0: Exit Function
End If
End If
Dim np
For np = np0 To Len(Name)
Dim nc: nc = Mid(Name,np,1)
If StrComp(fc2,nc,vbTextCompare)=0 Then
If CompareFileName(Mid(Name,np+1),Mid(Filter,fp)) Then
CompareFileName2 = True: Exit Function
End If
End If
Next
CompareFileName2 = False
End Function

</SCRIPT>
<body>
<select size="10" name="CSVFile" onChange="MessageBox">
</select>
<p>
<span id = "DataArea"></SPAN>
</body>


<html>
<head>
<!--This text is a comment-->
<title>CSV2MrqVBS1</title>

<STYLE>BODY {font-size: 8pt; font-family: Comic Sans MS;}</STYLE>

<!-- Hypertext Application Properties:
http://msdn2.microsoft.com/en-us/library/ms536481.aspx -->
<HTA:Application
ApplicationName="CSV2MrqVBS1"
Border="none"
Caption="yes"
ID="CSV2MrqVBS1"
SCROLL="no"
SingleInstance="yes"
ShowInTaskBar="no"
/>

<SCRIPT LANGUAGE="VBScript">

window.resizeTo 1,1

LeftMargin = 20
TopMargin = 0
WindowWidth = screen.width - 110
WindowHeight = 22

Sub CsvMarquee()
window.setinterval "oPopUp.show
LeftMargin,TopMargin,WindowWidth,WindowHeight",1
End Sub

const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
'WScript.ScriptFullName not valid in HTA. Use document.location.pathname
instead...
URL_Path_With_ScriptName = document.location.pathname
'Strip off Scriptname and only leave Drive Letter and Path...
URL_Path_Only =
Left(URL_Path_With_ScriptName,InStrRev(URL_Path_With_ScriptName,"\"))
'If path has spaces in it (Ex. C:\Program%20Files), DeCode to standard
Windows format...
Non_URL_Path = URLDecode(URL_Path_Only)
Set objFile = objFSO.OpenTextFile(Non_URL_Path & "server.csv", ForReading)
sHeader = objFile.ReadLine
arrHeader = Split(sHeader,",")
sAllTogether = ""
Do Until objFile.AtEndOfStream
counter = (objFile.Line - 1)
StringLine = objFile.ReadLine
arrLine = Split(StringLine, ",")
'For loop to allow for dynamic/variable number of columns
For i = 0 to Ubound(arrLine)
sAddTokens = sAddTokens & arrHeader(i) & ":" & arrLine(i) &
" "
Next
'Separate each row with extra spaces
sAllTogether = sAllTogether & counter & ": " & sAddTokens & " "
Loop
objFile.Close
Set oPopUp = Window.createPopup()
Set PopUpBody = oPopUp.document.body
PopUpBody.InnerHTML = "<marquee>" & sAllTogether & "</marquee>"


Function URLDecode(String)
String = Replace(String, "+", " ")
For i = 1 To Len(String)
sT = Mid(String, i, 1)
If sT = "%" Then
If i+2 < Len(String) Then
sR = sR & _
Chr(CLng("&H" & Mid(String, i + 1, 2)))
i = i+2
End If
Else
sR = sR & sT
End If
Next
URLDecode = sR
End Function

</SCRIPT>

</head>
<body onload="CsvMarquee()">
</body>
</html>


<html>
<head>
<!--This text is a comment-->
<title>CSV2MrqJS1</title>

<STYLE>BODY {font-size: 8pt; font-family: Comic Sans MS;}</STYLE>

<!-- Hypertext Application Properties:
http://msdn2.microsoft.com/en-us/library/ms536481.aspx -->
<HTA:Application
ApplicationName="CSV2MrqJS1"
Border="none"
Caption="no"
ID="CSV2MrqJS1"
SCROLL="no"
SingleInstance="yes"
ShowInTaskBar="no"
/>

<SCRIPT LANGUAGE="JScript">

window.resizeTo(1,1)

<!-- Positions PopUp at top of screen with room for windows controls at both
sides and adjusts to screen width -->
LeftMargin = 20
TopMargin = 0
WindowWidth = screen.width - 110
WindowHeight = 22

function CsvMarquee(){
var forreading = 1;
fso = new ActiveXObject("Scripting.FileSystemObject");
//WScript.ScriptFullName not valid in HTA. Use
document.location.pathname instead...
var URL_Path_With_Scriptname = document.location.pathname
//Strip off Scriptname and only leave Drive Letter and Path...
URL_Path_Only = URL_Path_With_Scriptname.substr(0,
URL_Path_With_Scriptname.lastIndexOf("\\") + 1);
//If path has spaces in it (Ex. C:\Program%20Files), DeCode to standard
Windows format...
Non_URL_Path = unescape(URL_Path_Only.replace(new RegExp("\\+","g")," "));
objFile = fso.OpenTextFile(Non_URL_Path + "server.csv", forreading);
arrHeader = objFile.ReadLine().split(",");
var sAllTogether="";
var sAddTokens="";
while(!objFile.AtEndOfStream){
counter = (objFile.Line - 1)
arrLine = objFile.Readline().split(",");
var i=0;
//For loop to allow for dynamic/variable number of columns
for(var i in arrHeader){
sAddTokens += arrHeader[i] + ":" + arrLine[i] + " "
}
sAllTogether += counter + ": " + sAddTokens + " "
}
objFile.Close()
xxCr = window.createPopup();
xxCr.document.body.innerHTML = '<marquee>' + sAllTogether + '</marquee>';

window.setInterval("xxCr.show(LeftMargin,TopMargin,WindowWidth,WindowHeight)",1)
}
</SCRIPT>

</head>

<body onload="CsvMarquee()">
</body>

</html>
unknown
2007-08-06 23:42:33 UTC
Permalink
Post by tbader01
Hello Everyone,
A while back someone helped me write an HTA app that takes a CSV file and
makes all of the contents into a marquee across the top of the screen.
This one ? :
http://groups.google.com/group/microsoft.public.scripting.jscript/browse_frm/thread/bf89643b52b03763/4b6e8dca608ae0b8
Post by tbader01
and I also converted the
code to VBS as well.
Why ? JScript is better for this.
Please attach the HTA files.

Good Luck, Ayush.
--
Scripting- your first steps :
http://www.microsoft.com/technet/scriptcenter/topics/beginner/firststeps.mspx
tbader01
2007-08-07 02:32:00 UTC
Permalink
Hello Ayush,
1. Yeah, that was my original post. I was trying to use "chromeless IE" and
VBS to do what I wanted, until I was first introduced to HTA's. I had never
heard of them before!
2. I converted it to VBS because I am more familiar and experienced with it,
plus it was a good way to reverse engineer it to understand HTA's and what
exactly is going on in a language that I understand a bit better. It also
helped me understand JS a little better too actually, but I still trouble
getting around in JS!
3. I copied and pasted the three HTA's code in my original post. I've had
the same problem before where I couldn't see what someone else had posted. I
used the web based news reader to read these threads, if that makes any
difference. I have pasted the code again in this msg and will separate each
HTA with a ------ Line.
4. I actually found some bug in my updated scripts where if there are more
than 5 or so lines, it doesn't seem to get past that number. It also seems to
bog down and eat up a good bit of CPU too /w more lines. I need to step
through the code to see why this is happening. You might be able to spot the
problem right away faster than I can!

-----------------------------------------------------------------------------------------------------

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

<SCRIPT LANGUAGE="VBScript">

window.resizeTo 640,480

Sub Window_Onload
const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
'WScript.ScriptFullName not valid in HTA. Use document.location.pathname
instead...
URL_Path_With_ScriptName = document.location.pathname
'Stringip off Scriptname and only leave Drive Letter and Path...
URL_Path_Only =
Left(URL_Path_With_ScriptName,InStrRev(URL_Path_With_ScriptName,"\"))
'If path has spaces in it (Ex. C:\Program%20Files), DeCode to standard
Windows format...
Non_URL_Path = URLDecode(URL_Path_Only)
ListFile(No_URL_Path & "*.csv")
End Sub

Sub MessageBox
MsgBox CSVFile.value
End Sub

Function URLDecode(String)
String = Replace(String, "+", " ")
For i = 1 To Len(String)
sT = Mid(String, i, 1)
If sT = "%" Then
If i+2 < Len(String) Then
sR = sR & _
Chr(CLng("&H" & Mid(String, i + 1, 2)))
i = i+2
End If
Else
sR = sR & sT
End If
Next
URLDecode = sR
End Function

' Changes:
' 2006-01-19 Extended to handle the special case of filter masks
' ending with a ".". Thanks to Dave Casey for the hint.
Function ListFile(Path)
Dim a: a = ListDir(Path)
If UBound(a) = -1 then
MsgBox "No files found."
Exit Function
End If
Dim Filename, PutList
For Each Filename In a
Set objOption = Document.createElement("OPTION")
objOption.Text = Filename
objOption.value = Filename
CSVFile.add(objOption)
Next
End Function

' Returns an array with the file names that match Path.
' The Path string may contain the wildcard characters "*"
' and "?" in the file name component. The same rules apply
' as with the MSDOS DIR command.
' If Path is a directory, the contents of this directory is listed.
' If Path is empty, the current directory is listed.
' Author: Christian d'Heureuse (www.source-code.biz)
Public Function ListDir (ByVal Path)
Dim fso: Set fso = CreateObject("Scripting.FileSystemObject")
If Path = "" then Path = "*.*"
Dim Parent, Filter
if fso.FolderExists(Path) then ' Path is a directory
Parent = Path
Filter = "*"
Else
Parent = fso.GetParentFolderName(Path)
If Parent = "" Then If Right(Path,1) = ":" Then Parent = Path: Else
Parent = "."
Filter = fso.GetFileName(Path)
If Filter = "" Then Filter = "*"
End If
ReDim a(10)
Dim n: n = 0
Dim Folder: Set Folder = fso.GetFolder(Parent)
Dim Files: Set Files = Folder.Files
Dim File
For Each File In Files
If CompareFileName(File.Name,Filter) Then
If n > UBound(a) Then ReDim Preserve a(n*2)
a(n) = File.Path
n = n + 1
End If
Next
ReDim Preserve a(n-1)
ListDir = a
End Function

Private Function CompareFileName (ByVal Name, ByVal Filter) ' (recursive)
CompareFileName = False
Dim np, fp: np = 1: fp = 1
Do
If fp > Len(Filter) Then CompareFileName = np > len(name): Exit Function
If Mid(Filter,fp) = ".*" Then ' special case: ".*" at end of filter
If np > Len(Name) Then CompareFileName = True: Exit Function
End If
If Mid(Filter,fp) = "." Then ' special case: "." at end of filter
CompareFileName = np > Len(Name): Exit Function
End If
Dim fc: fc = Mid(Filter,fp,1): fp = fp + 1
Select Case fc
Case "*"
CompareFileName = CompareFileName2(name,np,filter,fp)
Exit Function
Case "?"
If np <= Len(Name) And Mid(Name,np,1) <> "." Then np = np + 1
Case Else
If np > Len(Name) Then Exit Function
Dim nc: nc = Mid(Name,np,1): np = np + 1
If Strcomp(fc,nc,vbTextCompare)<>0 Then Exit Function
End Select
Loop
End Function

Private Function CompareFileName2 (ByVal Name, ByVal np0, ByVal Filter,
ByVal fp0)
Dim fp: fp = fp0
Dim fc2
Do ' skip over "*" and "?" characters in
filter
If fp > Len(Filter) Then CompareFileName2 = True: Exit Function
fc2 = Mid(Filter,fp,1): fp = fp + 1
If fc2 <> "*" And fc2 <> "?" Then Exit Do
Loop
If fc2 = "." Then
If Mid(Filter,fp) = "*" Then ' special case: ".*" at end of filter
CompareFileName2 = True: Exit Function
End If
If fp > Len(Filter) Then ' special case: "." at end of filter
CompareFileName2 = InStr(np0,Name,".") = 0: Exit Function
End If
End If
Dim np
For np = np0 To Len(Name)
Dim nc: nc = Mid(Name,np,1)
If StrComp(fc2,nc,vbTextCompare)=0 Then
If CompareFileName(Mid(Name,np+1),Mid(Filter,fp)) Then
CompareFileName2 = True: Exit Function
End If
End If
Next
CompareFileName2 = False
End Function

</SCRIPT>
<body>
<select size="10" name="CSVFile" onChange="MessageBox">
</select>
<p>
<span id = "DataArea"></SPAN>
</body>

-----------------------------------------------------------------------------------------------------

<html>
<head>
<!--This text is a comment-->
<title>CSV2MrqVBS1</title>

<STYLE>BODY {font-size: 8pt; font-family: Comic Sans MS;}</STYLE>

<!-- Hypertext Application Properties:
http://msdn2.microsoft.com/en-us/library/ms536481.aspx -->
<HTA:Application
ApplicationName="CSV2MrqVBS1"
Border="none"
Caption="yes"
ID="CSV2MrqVBS1"
SCROLL="no"
SingleInstance="yes"
ShowInTaskBar="no"
/>

<SCRIPT LANGUAGE="VBScript">

window.resizeTo 1,1

LeftMargin = 20
TopMargin = 0
WindowWidth = screen.width - 110
WindowHeight = 22

Sub CsvMarquee()
window.setinterval "oPopUp.show
LeftMargin,TopMargin,WindowWidth,WindowHeight",1
End Sub

const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
'WScript.ScriptFullName not valid in HTA. Use document.location.pathname
instead...
URL_Path_With_ScriptName = document.location.pathname
'Strip off Scriptname and only leave Drive Letter and Path...
URL_Path_Only =
Left(URL_Path_With_ScriptName,InStrRev(URL_Path_With_ScriptName,"\"))
'If path has spaces in it (Ex. C:\Program%20Files), DeCode to standard
Windows format...
Non_URL_Path = URLDecode(URL_Path_Only)
Set objFile = objFSO.OpenTextFile(Non_URL_Path & "server.csv", ForReading)
sHeader = objFile.ReadLine
arrHeader = Split(sHeader,",")
sAllTogether = ""
Do Until objFile.AtEndOfStream
counter = (objFile.Line - 1)
StringLine = objFile.ReadLine
arrLine = Split(StringLine, ",")
'For loop to allow for dynamic/variable number of columns
For i = 0 to Ubound(arrLine)
sAddTokens = sAddTokens & arrHeader(i) & ":" & arrLine(i) &
" "
Next
'Separate each row with extra spaces
sAllTogether = sAllTogether & counter & ": " & sAddTokens & " "
Loop
objFile.Close
Set oPopUp = Window.createPopup()
Set PopUpBody = oPopUp.document.body
PopUpBody.InnerHTML = "<marquee>" & sAllTogether & "</marquee>"


Function URLDecode(String)
String = Replace(String, "+", " ")
For i = 1 To Len(String)
sT = Mid(String, i, 1)
If sT = "%" Then
If i+2 < Len(String) Then
sR = sR & _
Chr(CLng("&H" & Mid(String, i + 1, 2)))
i = i+2
End If
Else
sR = sR & sT
End If
Next
URLDecode = sR
End Function

</SCRIPT>

</head>
<body onload="CsvMarquee()">
</body>
</html>

-----------------------------------------------------------------------------------------------------

<html>
<head>
<!--This text is a comment-->
<title>CSV2MrqJS1</title>

<STYLE>BODY {font-size: 8pt; font-family: Comic Sans MS;}</STYLE>

<!-- Hypertext Application Properties:
http://msdn2.microsoft.com/en-us/library/ms536481.aspx -->
<HTA:Application
ApplicationName="CSV2MrqJS1"
Border="none"
Caption="no"
ID="CSV2MrqJS1"
SCROLL="no"
SingleInstance="yes"
ShowInTaskBar="no"
/>

<SCRIPT LANGUAGE="JScript">

window.resizeTo(1,1)

<!-- Positions PopUp at top of screen with room for windows controls at both
sides and adjusts to screen width -->
LeftMargin = 20
TopMargin = 0
WindowWidth = screen.width - 110
WindowHeight = 22

function CsvMarquee(){
var forreading = 1;
fso = new ActiveXObject("Scripting.FileSystemObject");
//WScript.ScriptFullName not valid in HTA. Use
document.location.pathname instead...
var URL_Path_With_Scriptname = document.location.pathname
//Strip off Scriptname and only leave Drive Letter and Path...
URL_Path_Only = URL_Path_With_Scriptname.substr(0,
URL_Path_With_Scriptname.lastIndexOf("\\") + 1);
//If path has spaces in it (Ex. C:\Program%20Files), DeCode to standard
Windows format...
Non_URL_Path = unescape(URL_Path_Only.replace(new RegExp("\\+","g")," "));
objFile = fso.OpenTextFile(Non_URL_Path + "server.csv", forreading);
arrHeader = objFile.ReadLine().split(",");
var sAllTogether="";
var sAddTokens="";
while(!objFile.AtEndOfStream){
counter = (objFile.Line - 1)
arrLine = objFile.Readline().split(",");
var i=0;
//For loop to allow for dynamic/variable number of columns
for(var i in arrHeader){
sAddTokens += arrHeader[i] + ":" + arrLine[i] + " "
}
sAllTogether += counter + ": " + sAddTokens + " "
}
objFile.Close()
xxCr = window.createPopup();
xxCr.document.body.innerHTML = '<marquee>' + sAllTogether + '</marquee>';

window.setInterval("xxCr.show(LeftMargin,TopMargin,WindowWidth,WindowHeight)",1)
}
</SCRIPT>

</head>

<body onload="CsvMarquee()">
</body>

</html>
J.Williams
2007-08-11 08:45:41 UTC
Permalink
Post by tbader01
Hello Everyone,
A while back someone helped me write an HTA app that takes a CSV file and
makes all of the contents into a marquee across the top of the screen.
Well, what I would like to be able to do now is to list the CSV's in the
HTA's directory, click one of them, run my CSV2MrqXXX script, and clear the
CSV selection dialog box.
This does everything above, plus a bit more.

---- Code: Marquee_VBS.hta ----
<!-- Hypertext Application Properties:
http://msdn2.microsoft.com/en-us/library/ms536481.aspx -->
<HTA:Application
ApplicationName="CSV2MrqVBS1"
Border="none"
ID="CSV2MrqVBS1"
Scroll="no"
SingleInstance="yes"
ShowInTaskBar="no"
/>

<html>
<head>
<style type="text/css">
<!--
body, select, input {
font-family: Arial, Helvetica, sans-serif;
font-size: 10px; }
-->
</style>
</head>

<script language="VBScript">
Option Explicit

'Maximum size of CSV file selection element
Const cSelectMaxSize = 5

'Popup window timer in milliseconds
Const cTimerInterval = 100

'Global variables
Dim goFso, goPopup

Set goFso = CreateObject ("Scripting.FileSystemObject")
window.resizeTo 300, 260

Sub Initialise ()
Dim sHTAfolderpath

sHTAfolderpath = goFso.GetParentFolderName (document.location.pathname)
populateDocument (sHTAfolderpath)
End Sub

Sub startMarquee ()
'Create marquee string from text in selected CSV file and
'start the marquee in a popup window

Dim iIndex, sCSVfile, sMarquee

iIndex = document.optionsForm.CSVoptions.SelectedIndex
sCSVfile = document.optionsForm.CSVoptions.Options(iIndex).Value

sMarquee = createMarqueeString (sCSVfile)

Set goPopup = window.createPopup()
goPopup.document.body.innerHTML = "<marquee onclick='window.resizeTo (300,
260)'>" & sMarquee & "</marquee>"

window.setInterval "popupTimer", cTimerInterval
window.resizeTo 0,0
End Sub


Sub populateDocument (sHTAfolder)
'Add HTA folder path to <p id="HTAfolder"> tag and
'add an <option> element to <select> tag for each .CSV file in HTA folder

Dim oPara, oFolder, oFiles, oFile, oCSVoptions, oCSVoption, i

Set oPara = document.getElementById ("HTAfolder")
oPara.InnerText = sHTAfolder

Set oCSVoptions = document.getElementById ("CSVoptions")

Set oFolder = goFso.GetFolder (sHTAfolder)
Set oFiles = oFolder.Files
i = 0
For Each oFile In oFiles
If Instr (oFile.Name, ".csv") Then
i = i + 1
Set oCSVoption = document.createElement ("option")
oCSVoption.Text = oFile.Name
oCSVoption.Value = goFso.BuildPath (sHTAfolder, oFile.Name)
If i = 1 Then oCSVoption.Selected = True '1st file is selected by default
oCSVoptions.Add (oCSVoption)
End If
Next

'Set size attribute of <select> tag
If i > cSelectMaxSize Then
oCSVoptions.size = cSelectMaxSize
Else
oCSVoptions.size = i
End If
End Sub

Function createMarqueeString (sCSVfile)
'Create marquee string from text in specified CSV file

Dim oFile, sLine
Const ForReading = 1

createMarqueeString = ""
Set oFile = goFso.OpenTextFile (sCSVfile, ForReading)
Do Until oFile.AtEndOfStream
sLine = oFile.ReadLine
createMarqueeString = createMarqueeString & sLine & _
" &nbsp; &nbsp; &nbsp; &nbsp; "
Loop
oFile.Close
End Function

Sub popupTimer ()
'Function called periodically to ensure popup window is always on top

Dim iLeftMargin, iTopMargin, iWindowWidth, iWindowHeight

iLeftMargin = 20
iTopMargin = 0
iWindowWidth = screen.width - 110
iWindowHeight = 22

goPopup.show iLeftMargin, iTopMargin, iWindowWidth, iWindowHeight
End Sub

</script>

<body onload="Initialise()">
<p>List of .csv files in</p>
<p id="HTAfolder"></p>
<form id="form1" name="optionsForm">
<select id="CSVoptions">
</select>
<p>Select a file and click Start</p>
<input type="button" value="Start" onclick="startMarquee"/>
<input type="button" value="Quit" onclick="window.close()"/>
</form>
</body>
</html>
----- End code -----
tbader01
2007-08-11 15:08:00 UTC
Permalink
Kool, thanks J.Williams!

Now I can use this for any of the following by having separate CSV files for
each!:
affirmations
memorizing definitions to words
reminder of tasks I need to do
learning phrases in a foreign language(?)
Changing behavior
?

Here are some recent ideas/concepts I have learned that may be of use to
someone:
Perurbation Theory,Framework for simplifying a difficult problem by finding
an approximate solution that is subsequently refined as more
details-initially ignored-are systematically included.
Practice,Repetition is the mother of perfection.
Practice,Amatures don't quit until they get it right-professionals don't
quit until they can't get it wrong.
Sublimation,The refocusing of energy to more positive and constructive
efforts.

Thanks again!
Post by J.Williams
Post by tbader01
Hello Everyone,
A while back someone helped me write an HTA app that takes a CSV file and
makes all of the contents into a marquee across the top of the screen.
Well, what I would like to be able to do now is to list the CSV's in the
HTA's directory, click one of them, run my CSV2MrqXXX script, and clear the
CSV selection dialog box.
This does everything above, plus a bit more.
---- Code: Marquee_VBS.hta ----
http://msdn2.microsoft.com/en-us/library/ms536481.aspx -->
<HTA:Application
ApplicationName="CSV2MrqVBS1"
Border="none"
ID="CSV2MrqVBS1"
Scroll="no"
SingleInstance="yes"
ShowInTaskBar="no"
/>
<html>
<head>
<style type="text/css">
<!--
body, select, input {
font-family: Arial, Helvetica, sans-serif;
font-size: 10px; }
-->
</style>
</head>
<script language="VBScript">
Option Explicit
'Maximum size of CSV file selection element
Const cSelectMaxSize = 5
'Popup window timer in milliseconds
Const cTimerInterval = 100
'Global variables
Dim goFso, goPopup
Set goFso = CreateObject ("Scripting.FileSystemObject")
window.resizeTo 300, 260
Sub Initialise ()
Dim sHTAfolderpath
sHTAfolderpath = goFso.GetParentFolderName (document.location.pathname)
populateDocument (sHTAfolderpath)
End Sub
Sub startMarquee ()
'Create marquee string from text in selected CSV file and
'start the marquee in a popup window
Dim iIndex, sCSVfile, sMarquee
iIndex = document.optionsForm.CSVoptions.SelectedIndex
sCSVfile = document.optionsForm.CSVoptions.Options(iIndex).Value
sMarquee = createMarqueeString (sCSVfile)
Set goPopup = window.createPopup()
goPopup.document.body.innerHTML = "<marquee onclick='window.resizeTo (300,
260)'>" & sMarquee & "</marquee>"
window.setInterval "popupTimer", cTimerInterval
window.resizeTo 0,0
End Sub
Sub populateDocument (sHTAfolder)
'Add HTA folder path to <p id="HTAfolder"> tag and
'add an <option> element to <select> tag for each .CSV file in HTA folder
Dim oPara, oFolder, oFiles, oFile, oCSVoptions, oCSVoption, i
Set oPara = document.getElementById ("HTAfolder")
oPara.InnerText = sHTAfolder
Set oCSVoptions = document.getElementById ("CSVoptions")
Set oFolder = goFso.GetFolder (sHTAfolder)
Set oFiles = oFolder.Files
i = 0
For Each oFile In oFiles
If Instr (oFile.Name, ".csv") Then
i = i + 1
Set oCSVoption = document.createElement ("option")
oCSVoption.Text = oFile.Name
oCSVoption.Value = goFso.BuildPath (sHTAfolder, oFile.Name)
If i = 1 Then oCSVoption.Selected = True '1st file is selected by default
oCSVoptions.Add (oCSVoption)
End If
Next
'Set size attribute of <select> tag
If i > cSelectMaxSize Then
oCSVoptions.size = cSelectMaxSize
Else
oCSVoptions.size = i
End If
End Sub
Function createMarqueeString (sCSVfile)
'Create marquee string from text in specified CSV file
Dim oFile, sLine
Const ForReading = 1
createMarqueeString = ""
Set oFile = goFso.OpenTextFile (sCSVfile, ForReading)
Do Until oFile.AtEndOfStream
sLine = oFile.ReadLine
createMarqueeString = createMarqueeString & sLine & _
" "
Loop
oFile.Close
End Function
Sub popupTimer ()
'Function called periodically to ensure popup window is always on top
Dim iLeftMargin, iTopMargin, iWindowWidth, iWindowHeight
iLeftMargin = 20
iTopMargin = 0
iWindowWidth = screen.width - 110
iWindowHeight = 22
goPopup.show iLeftMargin, iTopMargin, iWindowWidth, iWindowHeight
End Sub
</script>
<body onload="Initialise()">
<p>List of .csv files in</p>
<p id="HTAfolder"></p>
<form id="form1" name="optionsForm">
<select id="CSVoptions">
</select>
<p>Select a file and click Start</p>
<input type="button" value="Start" onclick="startMarquee"/>
<input type="button" value="Quit" onclick="window.close()"/>
</form>
</body>
</html>
----- End code -----
Loading...