How Can I display the contents of a .txt file in a SWremote

Simple advice that you may find useful. Feel free to discuss or add your own.
Post Reply
edgar
Member
Posts: 95
Joined: Tue Mar 24, 2009 11:14 pm
Location: Springfield, VA

How Can I display the contents of a .txt file in a SWremote

Post by edgar »

Hello,

I am new to HB and not a huge programmer. Is there anyway to have the text within a text file present, and even change automatically on a specified interval, on a SWRemote?

Thanks much,

Kevin
Richard Naninck
HouseBot Guru Extraordinaire
Posts: 1121
Joined: Tue Sep 28, 2004 7:49 am
Location: The Netherlands

Re: How Can I display the contents of a .txt file in a SWremote

Post by Richard Naninck »

Yes and yes.
I display rss news feeds in an alphalist in my theme and change the subject every 20 seconds.
You need an alphalist (alphanumeric list) in your theme which is actually a property in the server and fill that property with your text. Filling it with changing text can be done using a script. Whenever you use TABs in an alphalist, you will be surprised by its function. Any text before the first TAB isn't visible and used for other purposes (which is a little too advanced to get into right now). So if plain text is what you need, make sure you strip it from TAB's and put it in the alphalist property. Then create an alphalist in your theme and point it to the property and your text will be visible.
You can also use a standard alphanumeric property to display text. Pro's are that you don't have to create your own line lengths etc depending on the size of the theme control since this is handled by HB but Con's are that you don't get scroll bars to scroll through the text if the text is larger than your display area.

Hope that helps a bit.


EDIT: This thread should be in the general section I guess...
edgar
Member
Posts: 95
Joined: Tue Mar 24, 2009 11:14 pm
Location: Springfield, VA

Re: How Can I display the contents of a .txt file in a SWremote

Post by edgar »

Thanks for the reply.

I understand what you mean about the alphalist now. My problem is the property. I want to have a text file displayed. I think this is the right way of doing this: 1) I create a null device 2) I add a property to it 3) this is where I get lost...I don't know how to set up the properties to point to a .txt file that I want to put into the alpha list in my theme. There are many to select from and most I use, only display the path as the text. I think I am close to getting this just a little stuck.

Thanks in advance for help!

Kevin
Osler
HouseBot Guru
Posts: 742
Joined: Fri Feb 03, 2006 11:18 pm

Re: How Can I display the contents of a .txt file in a SWremote

Post by Osler »

Instead of a null device, create a script device and add your property (alphanumeric for now) to it. Edit the script below in notepad.exe to conform to your device and property name as well as text file name and then save it with a .vbs extension to C:\Program Files\HouseBot\Config\Scripts:

Code: Select all

Option Explicit

Dim objFSO
Dim objFile
Dim objReadFile
Dim strPath
Dim strContents
Dim strDeviceName
Dim strDeviceProperty

strPath = "C:<PATH TO TEXT FILE HERE>"
strDeviceName = "<DEVICE NAME HERE>"
strDeviceProperty = "<DEVICE PROPERTY NAME HERE>"

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.GetFile(strPath)

If objFile.Size > 0 Then
    Set objReadFile = objFSO.OpenTextFile(strPath, 1)
    strContents = objReadFile.ReadAll
    objReadFile.Close
End If

Set objReadFile = Nothing
Set objFile = Nothing
Set objFSO = Nothing

Call SetPropertyValue(strDeviceName & "." & strDeviceProperty, strContents)

Point the script device to this script in the HB script folder and set it to run.

Osler

Note: script is untested so there could be bugs or typos....but this will get you started.
edgar
Member
Posts: 95
Joined: Tue Mar 24, 2009 11:14 pm
Location: Springfield, VA

Re: How Can I display the contents of a .txt file in a SWremote

Post by edgar »

Osler and Richard,

Thank you very much for your assistance. The script works great and I actually understand most of what it is doing, which was the momentum I needed to go ahead and purchase HB! (about 2 mins ago)

Looking forward to using HB to get EDGAR back online and providing increased HA capability!

-Kevin

edgar (Electronic Data Gathering and Automation Resource)
Post Reply