Active Forums => QB64 Discussion => Topic started by: Jaze on March 17, 2022, 08:12:41 pm
Title: There is definitely an error but for the life of me I can't see it
Post by: Jaze on March 17, 2022, 08:12:41 pm
I'm trying to test whether a given string is in the format of a call time. Call times are either H:MM:SS or MM:SS or M:SS I keep getting a result of TRUE for "Cheese" and other seemingly random strings. I just don't know what the error is
OK I didn't finish flipping < to >= and > to <= in the last case and switch ing Or with and like I did in other 2 cases. OK I think I have em all now?
I don't think you need the add values test.
Title: Re: There is definitely an error but for the life of me I can't see it
Post by: SMcNeill on March 17, 2022, 08:19:26 pm
The reason is really very simple -- "cheese" is 6 letters. Your sub only checks to invalidate 4, 5, and 7 letter words that aren't in your associated time format.
You start out assuming the format is TRUE, and then never prove that it's not with anything outside of those 3 possible combinations.
n4$ = Mid$(pCt$, 5, 1) If Asc(n4$) < 48 Or Asc(n4$) > 57 Then rtn = FALSE
Your 5th character isn't a number from 0 to 9... It's FALSE.
I did try it and it came back true, I am testing my code fix. Need to add test for val(secs) <= 59 and val(mins) <= 59 or test the tens spot for mins and secs < asc("6"), the later is same amount of checks so go with that.
Title: Re: There is definitely an error but for the life of me I can't see it
Post by: bplus on March 17, 2022, 10:05:25 pm
[ This attachment cannot be displayed inline in 'Print Page' view ]
Still can get rid of testing all digits sum <> 0 for True return.
Title: Re: There is definitely an error but for the life of me I can't see it
Post by: Jaze on March 18, 2022, 01:21:26 pm
Thank you everyone. taking care of the lengths I didn't account for fixed it. And thank you for reminding me that I need to code for some of the digits between 0 and 6, not 0 to 9. Thanks again