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

12,613 views 11 replies
Reply #1 Top

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.

 

Code: vbscript
  1. Option Explicit
  2. Dim timeInterval : timeInterval = <time interval for reading the file contents>
  3. Dim path : path = <path to your txt file>
  4. Dim objectName : objectName = <the text object name>
  5. Dim fso : Set fso = CreateObject("Scripting.FileSystemObject")
  6.  
  7. Sub Object_OnScriptEnter
  8.      ' Setup a timer to run every X minutes (value is in milliseconds)
  9.     Object.SetTimer 1000, timeInterval * 60 * 1000
  10. End Sub
  11.  
  12. Sub Object_OnScriptExit
  13.     Object.KillTimer 1000
  14. End Sub
  15.  
  16. ' Timer callback (1000 is the timer ID)
  17. Sub Object_OnTimer1000
  18.     Dim contents : contents = ""
  19.  
  20.     ' Read from the file
  21.     If fso.FileExists(path) Then
  22.         Dim txtFile: Set txtFile = fso.OpenTextFile(path)
  23.         contents = txtFile.ReadAll()
  24.         txtFile.Close()
  25.         Set txtFile = Nothing
  26.     Else
  27.         ' TODO handle error if file is not present
  28.     End If
  29.  
  30.     If contents = "" Then
  31.         ' TODO handle error if file is empty
  32.     End If
  33.  
  34.     ' Set the object text
  35.     DesktopX.Object(objectName).Text = contents
  36. End Sub

Reply #2 Top

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

 

Reply #3 Top

Phoon: Can you map a drive to that server?  Does that help?

Reply #4 Top
made no difference Zubaz..
Reply #5 Top

There you go.

Reply #6 Top

Quoting Zubaz, reply 5
There you go

Huh.. There I go.... what??

Reply #7 Top

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.

Reply #8 Top

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!

Reply #9 Top

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.

 

Reply #10 Top

:thumbsup:  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")

 

 

 

Reply #11 Top

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.