Announcement

Collapse
No announcement yet.

I need to truncate a string

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

  • mikee123
    replied
    Now I have a new 'problem'. I need to convert or retrieve the TotalHotWaterTime which is stored in the Jon00UptimeDataHS3.ini as a number (for a calculation, subtraction). It is stored as a string, so subtraction does not work. But can I either convert it to for example number of minutes, or is the total time stored somewhere as a number ?

    Leave a comment:


  • Uncle Michael
    replied
    Originally posted by mikee123 View Post
    I have a device (Jon00Uptime) which stores a elapsed time in the device string. Unfortunately there is a green dot before, which I would like to get rid of...
    How can I do that ?
    Although this particular problem has been resolved, I've encountered this problem with other device strings. To get around it I use a REGEX function to remove the extra characters in the string. My script is below for reference in case it is useful to others. It assumes there is a virtual device that will receive the cleaned up string.

    Code:
        Public Sub Main(ByVal Parms As Object)
    
        'Creates devices with "clean" device strings for HSTouch
    
        Imports System.Text.RegularExpressions
        Dim imgRegex As New Regex("<[^>]*>", RegexOptions.IgnoreCase)
    
        Dim strLine As String
        Dim dblNumber As Double
    
        'Outside Humidity
    
            strLine = imgRegex.Replace(hs.DeviceString(62), "")
            hs.SetDeviceString(150, strLine.Trim(), True)
            dblNumber = Val(strLine)
            hs.SetDeviceValueByRef(150, dblNumber, True)    
            'hs.WriteLog("Clean RH", strLine.Trim())        'debug
    
        'Outside Temperature
    
            strLine = imgRegex.Replace(hs.DeviceString(59), "")
            hs.SetDeviceString(146, strLine.Trim(), True)
            'hs.WriteLog("Clean Temp", strLine)        'debug
    
        'Daily Rain
    
            strLine = imgRegex.Replace(hs.DeviceString(64), "")
            hs.SetDeviceString(152, strLine.Trim(), True)
            dblNumber = Val(strLine)
            hs.SetDeviceValueByRef(152, dblNumber, True)
    
        'Yearly Rain
    
            strLine = imgRegex.Replace(hs.DeviceString(67), "")
            hs.SetDeviceString(149, strLine.Trim(), True)
    
        'Living Room Temperature
    
            strLine = imgRegex.Replace(hs.DeviceString(1098), "")
            hs.SetDeviceString(1238, strLine.Trim(), True)
            'hs.WriteLog("Clean Temp", strLine)        'debug
    
        End Sub

    Leave a comment:


  • mikee123
    replied
    Yes it is working now. Great

    Leave a comment:


  • jon00
    replied
    No....

    You defined your Hot Water uptime under a [DeviceX] heading in the main ini file (where X is a number). For example [Device6]

    Therefore to extract the uptime for [Device6] you would use:

    Code:
     
     Dim TotalHotWaterTime As String TotalHotWaterTime = hs.GetIniSetting("Device6","TotalUptime,"","Jon00UptimeDataHS3.ini")
    This has nothing to do with device reference numbers.

    Leave a comment:


  • mikee123
    replied
    I have tried it like this

    TotalHotWaterTime = hs.GetIniSetting(593,"TotalUptime","","Jon00UptimeDataHS3.in i")

    and like this

    TotalHotWaterTime = hs.GetIniSetting("593","TotalUptime","","Jon00UptimeDataHS3. ini")

    there are no errors in the log, but it does not show any value. Something is not quite right. #593 is the uptime device ref for Hot water

    Leave a comment:


  • mikee123
    replied
    Originally posted by jon00 View Post
    You can get the uptime from the Jon00UptimeDataHS3.ini file:
    Code:
    Dim TotalHotWaterTime As String
    TotalHotWaterTime = hs.GetIniSetting("Device1","TotalUptime,"","Jon00UptimeDataHS3.ini")
    Change "Device1" to the device number you are using for the Hot Water.
    Ok thats easier. But still have learnt something along the way which is good

    Leave a comment:


  • jon00
    replied
    You can get the uptime from the Jon00UptimeDataHS3.ini file:
    Code:
    Dim TotalHotWaterTime As String
    TotalHotWaterTime = hs.GetIniSetting("Device1","TotalUptime,"","Jon00UptimeDataHS3.ini")
    Change "Device1" to the device number you are using for the Hot Water.

    Leave a comment:


  • sparkman
    replied
    Take a look at the html for that page to see what the string is composed of as it will include some html code. Then your code would be something like this:

    Code:
    Dim x as Integer = Instr(TotalHotWaterTime,"text to find")
    TotalHotWaterTime = Right(TotalHotWaterTime,Len(TotalHotWaterTime)-x-1)

    Leave a comment:


  • mikee123
    replied
    I am not very good with vb... I am not sure how to find the unicode for the 'dot'. But what could work, if I can split the strine, I could try to separate it after character 1, then take the remaining string if thats possible ?

    Leave a comment:


  • sparkman
    replied
    Is the dot always the same? If so, I would use the vb.net replace method to replace the text associated with the dot with nothing: https://docs.microsoft.com/en-us/dot...ramework-4.7.2. If the text changes, then I would either find a character at the end of it using the Instr method (https://docs.microsoft.com/en-us/dot...ramework-4.7.2) and then taking all text to the right of it (https://docs.microsoft.com/en-us/dot...ramework-4.7.2) or use a regular expression to find the text that matches what you need.

    Leave a comment:


  • mikee123
    started a topic I need to truncate a string

    I need to truncate a string

    I have a device (Jon00Uptime) which stores a elapsed time in the device string. Unfortunately there is a green dot before, which I would like to get rid of...

    I am using this in the script to retrieve the string:

    Code:
    Dim TotalHotWaterTime As String
    
            TotalHotWaterTime = hs.DeviceString(593)
    I am using this to email the value (string) of that device. The result looks like this:

    accumulated 0 days 0 hrs 0 mins 32 secs

    I would like to just have


    0 days 0 hrs 0 mins 32 secs

    How can I do that ?

    Attached Files
Working...
X