Announcement

Collapse
No announcement yet.

Instr

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

    Instr

    Hi Guys,

    I am using a few scripts at the moment that use Instr to determine if there is a phrase in the string, and then to do something with that string, so e.g. If the String contains X and Y then do Z

    I am sure it is simple, but how can i do an instr where only one condition exists, e.g. the string contains X but not Y, then does Z.

    This is an example of one of my current script sections:

    If Instr(1,data,"ALERT",1) > 0 and Instr(1,data,"[BEUP]",1) > 0 then
    'do stuff
    End If

    How can I set it so that in this example, if the string contains [BEUP] but not ALERT then to 'do stuff

    Ideally id like to be able to have three conditions eventually,

    String contains both X + Y
    String Contains Only X
    String Contains Neither X or Y

    Thanks
    HS3 PRO, Win10, WeatherXML, HSTouch, Pushover, UltraGCIR, Heaps of Jon00 Plugins, Just sold and about to move so very slim system.

    Facebook | Twitter | Flickr | Google+ | Website | YouTube

    #2
    Originally posted by travisdh View Post
    This is an example of one of my current script sections:

    If Instr(1,data,"ALERT",1) > 0 and Instr(1,data,"[BEUP]",1) > 0 then
    'do stuff
    End If
    So this will execute 'stuff' if both strings are contained within data.

    How can I set it so that in this example, if the string contains [BEUP] but not ALERT then to 'do stuff
    If Instr(1,data,"ALERT",1) = 0 and Instr(1,data,"[BEUP]",1) > 0 then
    'do stuff
    End If

    Instr returns 0 when string2 is not found within string1, so this example would execute if [BEUP] was found but not ALERT.

    String Contains Neither X or Y is simply:
    If Instr(1,data,"ALERT",1) = 0 and Instr(1,data,"[BEUP]",1) = 0 then
    HS Pro 3.0 | Linux Ubuntu 16.04 x64 virtualized under Proxmox (KVM)
    Hardware: Z-NET - W800 Serial - Digi PortServer TS/8 and TS/16 serial to Ethernet - Insteon PLM - RFXCOM - X10 Wireless
    Plugins: HSTouch iOS and Android, RFXCOM, BlueIris, BLLock, BLDSC, BLRF, Insteon PLM (MNSandler), Device History, Ecobee, BLRing, Kodi, UltraWeatherWU3
    Second home: Zee S2 with Z-Wave, CT101 Z-Wave Thermostat, Aeotec Z-Wave microswitches, HSM200 occupancy sensor, Ecolink Z-Wave door sensors, STI Driveway Monitor interfaced to Zee S2 GPIO pins.

    Comment


      #3
      Thanks for the tips, most appreciated!
      HS3 PRO, Win10, WeatherXML, HSTouch, Pushover, UltraGCIR, Heaps of Jon00 Plugins, Just sold and about to move so very slim system.

      Facebook | Twitter | Flickr | Google+ | Website | YouTube

      Comment

      Working...
      X