Announcement

Collapse
No announcement yet.

Update value from text file

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

    Update value from text file

    Can anyone advice me how to create a vb script to read a text file with values.
    I have a text file that is generated from my climate system, I can control how to format the text file.
    At present the text file looks like this



    4.83;kW
    8.47;A
    6.57;A
    5.74;A









    There is about 14 values, i can create the virtual devices manualy.
    The plan is to run this script every 5 minutes to update device R1 to R14
    I can add the device code to the text file if this makes it simpler.



    Any help would be greatly appreciated

    #2
    Try the attached script. Save with a .vb extension in your scripts directory.

    You will need to create the 14 virtual devices manually R1 to R14

    Quick and in parts dirty code but should work.

    PHP Code:
    Imports System.IO

    Sub Main
    (byVal Parm As Object)
    Dim Filereader As Streamreader
    Dim Path 
    As String "<path of text file>"
    Dim Data As String
    Dim Value 
    As String
    Dim ct 
    As Integer 0
    Filereader 
    = New StreamReader(Path)
    Do While 
    FileReader.Peek >= 0
        ct 
    +=1
        
    If ct 14 then exit do
        
    Data=Filereader.ReadLine()
        
    Value=hs.stringitem (Data,1,";")
        
    hs.setdevicestring ("R" ct.ToString,Value)
    Loop
    Filereader
    .Close()

    End Sub 
    Jon

    Comment


      #3
      Thanks,

      it nearly perfekt.

      It imports value line 1 to R1
      Value line 2 to R3, value line 3 to R5

      so it's jumping 2 steps.

      The text file loos like this




      Attached Files

      Comment


        #4
        Hmmm... Your text file must have some blank lines in it.

        Try this one:

        PHP Code:
        Imports System.IO 

        Sub Main
        (byVal Parm As Object
        Dim Filereader As Streamreader 
        Dim Path 
        As String "<path of text file>" 
        Dim Data As String 
        Dim Value 
        As String 
        Dim ct 
        As Integer 
        Filereader 
        = New StreamReader(Path
        Do While 
        FileReader.Peek >= 0
            Data
        =Filereader.ReadLine()
            If 
        Data.Length 0 then 
                    ct 
        +=
                    
        If ct 14 then exit do 
                    
        Value=hs.stringitem (Data,1,";"
                    
        hs.setdevicestring ("R" ct.ToString,Value)
            
        end if
        Loop 
        Filereader
        .Close() 

        End Sub 
        Jon

        Comment


          #5
          Thanks,

          It is working now

          Comment

          Working...
          X