Home NetLinx Studio

Question about compare strings

ondrovicondrovic Junior MemberPosts: 217
is there a way to compare multiple strings?
If(char => Compare_String(char1,Char2) && var <= Compare_String(char3,char4)
{
    do something
} 
Else
{
   do something
}


I guess what i am saying is if char is between char1 & char 2 do something if no do something else

Or is there a better way

Comments

  • viningvining X Member Posts: 4,364
    Never mind!
  • mpullinmpullin Obvious Troll Account, Marked for Deletion Posts: 949
    Your example is kind of confusing and inconsistent with your question, so I'll just answer your question.
    I'd compare the strings with the typical comparison operators < > == <>. Compare_String seems useless unless you want to use the ? wildcard, in which case it would be helpful. Highlight compare_string in your code and hit F1 for details.

    What you want is
    If((char >= char1 && char <= char2) || (char >= char2 && char <= char1)) // I'm not going to assume char1<char2
    {
        //do something (in between)
    } 
    Else
    {
       //do something (not in between)
    }
    
    
    I haven't actually tried to do this in NetLinx but it should work. If it doesn't then TYPE_CAST all these chars to INTEGER and it will definitely work.
  • ondrovicondrovic Junior Member Posts: 217
    mpullin wrote: »
    Your example is kind of confusing and inconsistent with your question, so I'll just answer your question.
    I'd compare the strings with the typical comparison operators < > == <>. Compare_String seems useless unless you want to use the ? wildcard, in which case it would be helpful. Highlight compare_string in your code and hit F1 for details.

    What you want is
    If((char >= char1 && char <= char2) || (char >= char2 && char <= char1)) // I'm not going to assume char1<char2
    {
        //do something (in between)
    } 
    Else
    {
       //do something (not in between)
    }
    
    
    I haven't actually tried to do this in NetLinx but it should work. If it doesn't then TYPE_CAST all these chars to INTEGER and it will definitely work.

    Thanks Matt I will give that a try
  • ondrovicondrovic Junior Member Posts: 217
    so here is what I have but it doesn't seem to be working correctly
    If((sWeather.Time > sWeather.Sunset) && (sWeather.Time < sWeather.Sunrise))
    	{
    	    sWeather.Icon = "sWork,'n.png'"
    	}
    	Else
    	{
    	    sWeather.Icon = "sWork,'d.png'"
    	}
    
    sWeather.Time = 8:45 PM
    
    sWeather.Sunset = 8:34 PM
    
    

    Any ideas why the file isn't updating correctly?
  • viningvining X Member Posts: 4,364
    If your going to do < or > comparisons of time I would make a function that first converts time to seconds based on 24 hour time. Then just compare the interger values or long values. Or you could do seperate atoi(hour) and atoi(minutes) comparisons.
  • AMXJeffAMXJeff Senior Member Posts: 450
    vining wrote: »
    If your going to do < or > comparisons of time I would make a function that first converts time to seconds based on 24 hour time. Then just compare the interger values or long values. Or you could do seperate atoi(hour) and atoi(minutes) comparisons.


    Actually > and < work just fine this way. No need to do anything else. I do agree the time should be adjusted to 24 hour time.


    IF (TIME > '01:00:00' and TIME < '13:00:00')
    {

    }
  • viningvining X Member Posts: 4,364
    AMXJeff wrote:
    Actually > and < work just fine this way. No need to do anything else.
    
    Ya know, that would never had occurred to me that the decimal or binary equivent of ascii time would be sequentally greater too. I don't think I could do it that way though since the concept hurts my brain but maybe in time I can adapt and think more like a programmer who views everything as numbers.
  • ericmedleyericmedley Senior Member - 4000+ posts Posts: 4,177
    vining wrote: »
    AMXJeff wrote:
    Actually > and < work just fine this way. No need to do anything else.
    
    Ya know, that would never had occurred to me that the decimal or binary equivent of ascii time would be sequentally greater too. I don't think I could do it that way though since the concept hurts my brain but maybe in time I can adapt and think more like a programmer who views everything as numbers.

    That's been an old programmers trick for some time. It just so happens that using a comparison like this is actually comparing the hex ascii value of the character which happens to work.

    Somehow, I still don't like to do it. My main code always contains a little routine that converts the current time into decimal integer (seconds of the day. ex: 10,800= 3:00 AM)
    I also convert the calendar day to Julian. It just makes creating and managing anything that schedules a lot more reliable and far fewer logic statements.
  • mpullinmpullin Obvious Troll Account, Marked for Deletion Posts: 949
    vining wrote: »
    AMXJeff wrote:
    Actually > and < work just fine this way. No need to do anything else.
    
    Ya know, that would never had occurred to me that the decimal or binary equivent of ascii time would be sequentally greater too. I don't think I could do it that way though since the concept hurts my brain but maybe in time I can adapt and think more like a programmer who views everything as numbers.

    One should note, the reason this works is because the format returned by TIME has leading zeros. Otherwise, 2:00:00 > 11:00:00, etc.
Sign In or Register to comment.