Help creating a DX Script
Here is what I'm trying to do.
I have a txt file that is auto generated and changed every 15 mins or so.
I want to display the contents of the txt file in a dx object.
Any ideas? Please..
Here is what I'm trying to do.
I have a txt file that is auto generated and changed every 15 mins or so.
I want to display the contents of the txt file in a dx object.
Any ideas? Please..
This is very crude (and typed without testing, so it might need some adjustement).
If you want to do some formatting/parsing of the contents and present it in a better way, you will have to create several objects and adjust their text/font values of course.
Thanks LB!
This is what I have now, no errors generated but it isn't displaying anything either...
I have to Objects. 1 that contains the script and another that is a txt object named "time".
Option Explicit
Dim timeInterval : timeInterval = 60000
Dim path : path = "\\kch-files\public\"
Dim objectName : objectName = "test.txt"
Dim fso : Set fso = CreateObject("Scripting.FileSystemObject")
Sub Object_OnScriptEnter
' Setup a timer to run every X minutes (value is in milliseconds)
Object.SetTimer 1000, 6000
End Sub
Sub Object_OnScriptExit
Object.KillTimer 1000
End Sub
' Timer callback (1000 is the timer ID)
Sub Object_OnTimer1000
Dim contents : contents = ""
' Read from the file
If fso.FileExists(path) Then
Dim txtFile: Set txtFile = fso.OpenTextFile(path)
contents = txtFile.ReadAll()
txtFile.Close()
Set txtFile = Nothing
Else
' TODO handle error if file is not present
End If
If contents = "" Then
' TODO handle error if file is empty
End If
' Set the object text
DesktopX.Object("time").Text = contents
End Sub
Phoon: Can you map a drive to that server? Does that help?
There you go.
Huh.. There I go.... what??
Phoon, try correcting these three lines in your code:
Dim path : path = \\kch-files\public\test.txt
Dim objectName : objectName = "time"
.
.
.
DesktopX.Object(objectName).Text = contents
'path' should include the text file name
'objectName' should be your text object
And the last one should remain the variable 'objectName', which contains the name of the text object.
thanks sViz!
I did work it out with a modification of a vb script I found yesterday. After looking at what LB posted and doing some comparisons I reached a better understanding and was able to modify it to a DX solution. I'm going to look at this one now and see which works best!
Just put it in place and I like this option much better.
THANKS FOR THE HELP!!!
In case you are interested in what I am doing with this.
I work in a hospital. This object will be used to display wait times for various areas. ( will require a separate exe for each dept ).
There is a txt file with just a number value in it that someone on the back end can keep updated ( or it can be auto populated with another process or feed ).
This will be a small exe that can be ran and sit neatly on the desktop so staff can keep an eye on times and/or inform patients of the wait time without having to make a phone call to someone else.
Great idea, Phoon. Just the kind of thing DX is good for.
For the lines marked TODO, you could display a message box with en error report and further instructions, if necessary. Example syntax below:
x = MsgBox("Error: file not found",48,"YOUR TITLE HERE")
you could easily make 1 exe for all areas, and an INI or config file for each area.
I have been working on a backup script for our systems and by using the ini (and a VERY complicated preference window - that was built from objects) i can easily change the directories used, as well as pointing to \\machine\share or \\machine\c$\folder. The code for the bulk of this has been posted on here in my tutorials.
if you look here: http://romanda.wincustomize.com/articles.aspx
Thats where the INI functions are. Hope that helps.
Good Luck.
Welcome Guest! Please take the time to register with us.