Announcement

Collapse
No announcement yet.

WD HS script error HELP!!!

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    WD HS script error HELP!!!

    Can some one help me with this script PLEASE!!!

    When running this script I get an error: "Script error in file: CustmSensorScript.txt: 13: Type mismatch:'hs.setdevicevalue' in line 24". I modified this script off of one of Skibum's old WD scripts and I can't see any syntax error so it must be something in script programming I don't know.

    The file below= CustmSesorScript.txt

    sub main ()
    'Get Data from WDisplay customtextout for use with Homeseer
    dim f, fs
    dim data1, day,month,year,hour,minute,windspeed,humidity,basetemp,libra rytemp,fishtank
    Set fs=CreateObject("Scripting.FileSystemObject")
    set f=fs.OpenTextFile("C:\customtextout.txt")
    Do While NOT f.AtEndOfStream
    data1 = f.ReadLine
    Loop
    f.close

    day=hs.StringItem(data1,1,",")
    month=hs.StringItem(data1,2,",")
    year=hs.StringItem(data1,3,",")
    hour=hs.StringItem(data1,4,",")
    minute=hs.StringItem(data1,5,",")
    windspeed=hs.StringItem(data1,6,",")
    humidity=hs.StringItem(data1,7,",")
    basetemp=hs.StringItem(data1,8,",")
    librarytemp=hs.StringItem(data1,9,",")
    fishtank=hs.StringItem(data1,10,",")

    hs.setdevicestring "y1",windspeed & " ",true
    hs.setdevicevalue "y1",windspeed
    hs.setdevicestring "y2",humidity & " %",true
    hs.setdevicevalue "y2",humidity
    hs.setdevicestring "y3",basetemp & " Degrees F",true
    hs.setdevicevalue "y3",basetemp
    hs.setdevicestring "y4",librarytemp & " Degrees F",true
    hs.setdevicevalue "y4",librarytemp
    hs.setdevicestring "y5",fishtank & " Degrees F",true
    hs.setdevicevalue "y5",fishtank

    end sub


    and the 'customtextout.txt' file is this:
    11,06,2004,23,33,2.6 mph,43,-4.0,70.5,76.7

    The customtext.txt is this:
    %date-day%,%date-month%,%date-year%,%time-hour%,%time-minute%,%avgspd%,%dallasextrahum2%,%dallasextratemp1%,%extra temp3%,%extratemp2%

    The "y1" (windspeed)displays OK in the HS device page for "y1", but the script will not update the "y2 thru y5". I'm a newby at scripting and would really appreciate some help. My previous programming was limited to "Basic" on an apple lle in the late 80's and that was pretty limited.
    Appreciate any help you can give, thanks, Mick

    #2
    hs.SetDeviceValue is expecting to receive an integer input. You "2.6 mph" is not an integer. If you want to store the integer part of this then use the following

    hs.SetDeviceValue "y1",val(windspeed)

    Comment


      #3
      Exactly....
      ______________________________
      Skibumsplace - Locate Me

      Comment


        #4
        hs.setdevicevalue "y1",val(windspeed)

        I tried ..."y1",val(windspeed) and got "Script error in file: CustmSensorScript.txt:13:Type mismatch:'val' in line 24. I tried "value" and got the same error.

        So I tried "y1",val"windspeed" and got: ...tx.:1025:Expected end of statement error

        I really need to get a VBScript for Dummies, but it's out of print...

        Comment


          #5
          It looks as if Val is usable as ASP and VB, but not as Scripting VBScript. For this specific problem the following will do it for you.

          hs.setdevicevalue "y1",Clng(Replace(windspeed," mph", ""))

          A good reference is Microsoft VB Script

          You can also protect yourself with the isNumeric function. For example
          <pre class="ip-ubbcode-code-pre">

          sWindspeed = Replace(windspeed," mph","")
          if isNumeric(sWindspeed) Then
          hs.setDeviceValue "y1",Clng(sWindspeed)
          end if
          </pre>


          The general solution would be something like the following


          <pre class="ip-ubbcode-code-pre">

          hs.setDeviceValue "y1,MakeNumber(windspeed)

          Function MakeNumber(data)
          i = Len(data)
          j = 1
          Do While j &lt;= i
          If IsNumeric(Mid(data, j, 1)) Then
          Exit Do
          Else
          If Mid(data, j, 1) = "-" Then
          If j &lt; i Then
          If IsNumeric(Mid(data, j + 1, 1)) Then
          Exit Do
          End If
          End If
          End If
          End If
          j = j + 1
          Loop
          If j &gt; i Then
          MakeNumber = "0"
          Else
          If Mid(data, j, 1) = "-" Then
          Prefix = "-"
          sData = Mid(data, j + 1)
          Else
          sData = Mid(data, j)
          Prefix = ""
          End If
          i = Len(sData)
          Do While i &gt; 0
          If IsNumeric(Left(sData, i)) Then
          j = i
          Exit Do
          End If
          i = i - 1
          Loop
          If i &gt; 0 Then
          MakeNumber = Prefix & Trim(Left(sData, j))
          Else
          MakeNumber = "0"
          End If
          End If

          End Function

          </pre>

          Comment


            #6
            Ah!!! Thanks Michael!!!! Worked GREAT!! I've been dinking with this script for too long. I really appreciate your help and especially the script you sent. I'll have to look it over and see if I can figure it out (and get the book). Also thanks Skibum for the orginal script. I have read both of your guys' posts for quite awhile and really appreciate your help and the help you give other people. STRONG WORK GUYS!!

            Comment

            Working...
            X