Announcement

Collapse
No announcement yet.

Select case logic question

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

    Select case logic question

    I have a problem with the following throwing errors:

    Code:
    Select Case TempHall
      
     Case > 19.5
                    
                  If Temp < 6
                    hs.TriggerEvent("Load Heating mild")
                    hs.SaveINISetting("MyVariables", "HeatingSchedule","Mild", IniFile)
                     Else If Temp > 6 and < 13
                     hs.TriggerEvent("Load Heating mornings only")
                    hs.SaveINISetting("MyVariables", "HeatingSchedule","Morning", IniFile)
     
                    Else If Temp > 13
     
                    hs.TriggerEvent("Load Heating off")
                    hs.SaveINISetting("MyVariables", "HeatingSchedule","OFF", IniFile)
                  End If

    So if Temp is < 6 I want 'mild' to load, if its between 6 and 13 'mornings only' other wise 'off'

    #2
    What are the errors you are getting?

    Comment


      #3
      Originally posted by mikee123 View Post
      I have a problem with the following throwing errors:
      Try adding a 'Then' to the 'If' and 'Else If' statements.

      Code:
      Select Case TempHall
        
       Case > 19.5 
                      
                    If Temp < 6 [B]Then[/B]
                      hs.TriggerEvent("Load Heating mild")
                      hs.SaveINISetting("MyVariables", "HeatingSchedule","Mild", IniFile)
      
                       Else If Temp > 6 and < 13 [B]Then[/B]
                       hs.TriggerEvent("Load Heating mornings only")
                      hs.SaveINISetting("MyVariables", "HeatingSchedule","Morning", IniFile)
       
                      Else If Temp > 13 [B]Then[/B]
       
                      hs.TriggerEvent("Load Heating off")
                      hs.SaveINISetting("MyVariables", "HeatingSchedule","OFF", IniFile)
                    End If
      Mike____________________________________________________________ __________________
      HS3 Pro Edition 3.0.0.548, NUC i3

      HW: Stargate | NX8e | CAV6.6 | Squeezebox | PCS | WGL 800RF | RFXCOM | Vantage Pro | Green-Eye | Edgeport/8 | Way2Call | Ecobee3 | EtherRain | Ubiquiti

      Comment


        #4
        I tried it with then as you suggested. I get these errors:

        Nov-17 21:14:53 Error Compiling script C:\Program Files (x86)\HomeSeer HS3\scripts\HeatScheduleLogic.vb: '=' expected.
        Nov-17 21:14:53 Error Compiling script C:\Program Files (x86)\HomeSeer HS3\scripts\HeatScheduleLogic.vb: Element is missing an end tag.
        Nov-17 21:14:53 Error Compiling script C:\Program Files (x86)\HomeSeer HS3\scripts\HeatScheduleLogic.vb: Character '1' (0x31) is not allowed at the beginning of an XML name.
        Nov-17 21:14:53 Error Compiling script C:\Program Files (x86)\HomeSeer HS3\scripts\HeatScheduleLogic.vb: White space cannot appear here.
        Nov-17 21:14:53 Error Compiling script C:\Program Files (x86)\HomeSeer HS3\scripts\HeatScheduleLogic.vb: Operator 'And' is not defined for types 'Boolean' and 'System.Xml.Linq.XElement'.
        Nov-17 21:14:53 Error Compiling script C:\Program Files (x86)\HomeSeer HS3\scripts\HeatScheduleLogic.vb: Namespace or type specified in the Imports 'System.Core' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases.

        Comment


          #5
          This does not give any errors, but I'm not sure it would do what I want

          Code:
                      Case > 19.5
                          
          
                        If Temp > 13 Then
                          hs.TriggerEvent("Load Heating off")
                          hs.SaveINISetting("MyVariables", "HeatingSchedule","OFF", IniFile)
          
                           Else If Temp > 6 Then
                           hs.TriggerEvent("Load Heating mornings only")
                          hs.SaveINISetting("MyVariables", "HeatingSchedule","Morning", IniFile)
           
                          Else If Temp < 6 Then
           
                          hs.TriggerEvent("Load Heating mild")
                          hs.SaveINISetting("MyVariables", "HeatingSchedule","Mild", IniFile)
                        End If

          Comment


            #6
            Originally posted by mikee123 View Post
            I tried it with then as you suggested. I get these errors:

            Nov-17 21:14:53 Error Compiling script C:\Program Files (x86)\HomeSeer HS3\scripts\HeatScheduleLogic.vb: '=' expected.
            Nov-17 21:14:53 Error Compiling script C:\Program Files (x86)\HomeSeer HS3\scripts\HeatScheduleLogic.vb: Element is missing an end tag.
            Nov-17 21:14:53 Error Compiling script C:\Program Files (x86)\HomeSeer HS3\scripts\HeatScheduleLogic.vb: Character '1' (0x31) is not allowed at the beginning of an XML name.
            Nov-17 21:14:53 Error Compiling script C:\Program Files (x86)\HomeSeer HS3\scripts\HeatScheduleLogic.vb: White space cannot appear here.
            Nov-17 21:14:53 Error Compiling script C:\Program Files (x86)\HomeSeer HS3\scripts\HeatScheduleLogic.vb: Operator 'And' is not defined for types 'Boolean' and 'System.Xml.Linq.XElement'.
            Nov-17 21:14:53 Error Compiling script C:\Program Files (x86)\HomeSeer HS3\scripts\HeatScheduleLogic.vb: Namespace or type specified in the Imports 'System.Core' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases.
            I'm not an expert but it looks like you need to look at the following:
            You've got no End Select statement.
            The first Else If statement doesn't specify the variable after the And.
            Also what happens if the value is exactly 6 or 13?
            Is this an excerpt from the Case statement or is 19.5 the only value in it?

            Code:
            Select Case TempHall
              
             Case Is > 19.5 
                            
                          If Temp < 6 Then
                            hs.TriggerEvent("Load Heating mild")
                            hs.SaveINISetting("MyVariables", "HeatingSchedule","Mild", IniFile)
            
                             Else If Temp >= 6 and Temp < 13 Then
                            hs.TriggerEvent("Load Heating mornings only")
                            hs.SaveINISetting("MyVariables", "HeatingSchedule","Morning", IniFile)
             
             	          Else If Temp >= 13 Then
             
                            hs.TriggerEvent("Load Heating off")
                            hs.SaveINISetting("MyVariables", "HeatingSchedule","OFF", IniFile)
                          End If
            
            End Select

            Comment


              #7
              its an excerpt there are other cases, and there is an end select. I did not want to list the whole script as its all working, I only changed this part so that is where the problem is/was. I had the same thought, what if it is exactly 6 or 13. I could change it to 6.1 as my temperature gets rounded to 1 decimal. But I might have a similar issue with my cases. the next case is case 19.2 to 19.5, so what happens when it is 19.5 ? which case will be selected ?

              Comment


                #8
                Originally posted by mikee123 View Post
                I had the same thought, what if it is exactly 6 or 13. . . .my temperature gets rounded to 1 decimal.
                If your values are always integers, you can also do your selection this way.

                Code:
                Select Case TempHall     Case Is > 19.5                                 
                
                  If Temp < 6 Then                 
                    hs.TriggerEvent("Load Heating mild")                 
                    hs.SaveINISetting("MyVariables", "HeatingSchedule","Mild", IniFile) 
                
                  Else If Temp > 5 and Temp < 13 Then                 
                    hs.TriggerEvent("Load Heating mornings only")
                                    hs.SaveINISetting("MyVariables", "HeatingSchedule","Morning", IniFile)
                
                 Else If Temp > 12 Then                   
                    hs.TriggerEvent("Load Heating off") 
                    hs.SaveINISetting("MyVariables", "HeatingSchedule","OFF", IniFile)               
                  End If 
                
                 End Select
                Mike____________________________________________________________ __________________
                HS3 Pro Edition 3.0.0.548, NUC i3

                HW: Stargate | NX8e | CAV6.6 | Squeezebox | PCS | WGL 800RF | RFXCOM | Vantage Pro | Green-Eye | Edgeport/8 | Way2Call | Ecobee3 | EtherRain | Ubiquiti

                Comment


                  #9
                  Originally posted by mikee123 View Post
                  its an excerpt there are other cases, and there is an end select. I did not want to list the whole script as its all working, I only changed this part so that is where the problem is/was. I had the same thought, what if it is exactly 6 or 13. I could change it to 6.1 as my temperature gets rounded to 1 decimal. But I might have a similar issue with my cases. the next case is case 19.2 to 19.5, so what happens when it is 19.5 ? which case will be selected ?
                  Can you not just use Greater than or Equal to >= as I changed it to in the code above for the Temp selection? You should be able to use this for your case select too.

                  Comment

                  Working...
                  X