Select... Case help (Limiting a variable from 1 to 12)
Zeus
Posts: 79
Hello,
I am looking for help using "Select Case" statements. I am building an alarm clock and I want to limit the hour input to a range of 1 - 12 hours. A portion of the code is below.
I am also wondering if there is a good reference for "Select Case" statements. The books that I have only cover the basics and my code frequently requires a slightly more complicated solution.
Thanks... Zeus
'Alarm Hour Buttons Block
IF (MenuNum = 0) THEN
SELECT INA & 3
CASE = 3
AlarmHour = 6
CASE = 2
AlarmHour = AlarmHour + 1 // 13
CASE = 1
AlarmHour = AlarmHour - 1 MAX 12
ENDSELECT
ENDIF
I am looking for help using "Select Case" statements. I am building an alarm clock and I want to limit the hour input to a range of 1 - 12 hours. A portion of the code is below.
I am also wondering if there is a good reference for "Select Case" statements. The books that I have only cover the basics and my code frequently requires a slightly more complicated solution.
Thanks... Zeus
'Alarm Hour Buttons Block
IF (MenuNum = 0) THEN
SELECT INA & 3
CASE = 3
AlarmHour = 6
CASE = 2
AlarmHour = AlarmHour + 1 // 13
CASE = 1
AlarmHour = AlarmHour - 1 MAX 12
ENDSELECT
ENDIF
Comments
Mike,
I'm afraid there is not much more to tell. I find myself stating this project by writing the button inputs portion first. This is my first program, so unfortunately I do not know where it is going yet. You are correct about the up/down user inputs. Basically I want to limit the logic so that the user is unable to enter a bad value. I have not worked out how this will be used within the rest of the program.
It seems to me that there must be a way to constrain the input with mathematical operators, but I have not had any success at this point with this approach.
Does this help?
Zeus
That logic will work if you consider the alarmhour as 0 to 11 instead of 1 to 12.
Later on when you compare alarmHour with a value you read from an RTC, do something like this to adjust to a 1 to 12 cycle:
IF Hour = AlarmHour +1 THEN ....
Thanks for helping me out yet again.
I do not fully understand your code but the logic seems to make sense. Perhaps I should have asked this question first... What would be the most efficient way (code size wise) to limit the cycle to 1 to 12?
Zeus
I will compare this to your previous code and see if I can make sense of that as well.
Thanks again... Zeus