Author Topic: Fickle Increment variable  (Read 1115 times)

0 Members and 1 Guest are viewing this topic.

Offline Jaze

  • Newbie
  • Posts: 86
Fickle Increment variable
« on: April 05, 2022, 01:07:22 pm »
I have a variable from 0 to 9,999. You change it by some increment with the up and down arrow keys. I'm using INKEY$ with a SELECT CASE to check when the arrow keys are hit. I tried using _KEYDOWN for that but the values changed very fast and I got a rather strange error. Instead I'm using the _KEYDOWN to detect how long the key has been down and change the increment accordingly. This method isn't working to well. Sometime the increment changes, sometimes it does not. Any suggestions?
Code: QB64: [Select]
  1. FUNCTION GetOneTimeAmount$ (title$)
  2.   DIM minOption, maxOption, haltAndDisplay, xPos, yPos, highlightedOption AS INTEGER
  3.   DIM years1, days1, hours1, minutes1, seconds1, keyWasPressed, timerStarted AS INTEGER
  4.   DIM isLessThan, notZero AS INTEGER
  5.  
  6.   differentTime1:
  7.  
  8.   highlightedOption = 4: haltAndDisplay = TRUE: keyWasPressed = FALSE
  9.   isLessThan = FALSE: notZero = TRUE: Increment = 1
  10.   minOption = 4: maxOption = 8
  11.   DO
  12.     userCommand$ = INKEY$
  13.     IF haltAndDisplay = TRUE THEN
  14.  
  15.       COLOR 14, 1: CLS: yPos = 25: xPos = 15
  16.       a$ = title$: LOCATE 5, Center(a$): PRINT a$
  17.  
  18.       LOCATE yPos, xPos - 3
  19.       IF highlightedOption >= 4 AND highlightedOption <= 8 THEN
  20.       COLOR 10, 0: ELSE COLOR 14, 1: END IF
  21.       PRINT "Time:"
  22.       xPos = xPos + 18
  23.  
  24.       LOCATE yPos - 5, xPos - 10
  25.       IF highlightedOption = 4 THEN
  26.       COLOR 10, 0: ELSE COLOR 14, 1: END IF: PRINT "Years"
  27.       LOCATE yPos - 2, xPos - 10: COLOR 14, 1:
  28.       IF years1 - 1 >= 0 THEN
  29.       PRINT USING "#,###"; (years1 - 1): ELSE PRINT "9,999": END IF
  30.       LOCATE yPos: COLOR 10, 0: IF years1 >= 0 AND years1 < 10 THEN
  31.         LOCATE , xPos - 6: PRINT S$(years1)
  32.       ELSEIF years1 >= 10 AND years1 < 100 THEN LOCATE , xPos - 7: PRINT S$(years1)
  33.       ELSEIF years1 >= 100 AND years1 < 1000 THEN LOCATE , xPos - 8: PRINT S$(years1)
  34.       ELSEIF years1 >= 1000 AND years1 < 10000 THEN LOCATE , xPos - 10: PRINT USING "#,###"; years1
  35.       ELSE PRINT "I hope I don't see this error": END IF
  36.       LOCATE yPos + 2, xPos - 10: COLOR 14, 1: IF years1 + 1 < 10000 THEN
  37.       PRINT USING "#,###"; years1 + 1: ELSE PRINT USING "#,###"; 0: END IF
  38.  
  39.       LOCATE yPos - 5, xPos
  40.       IF highlightedOption = 5 THEN
  41.       COLOR 10, 0: ELSE COLOR 14, 1: END IF: PRINT "Days"
  42.       COLOR 14, 1: LOCATE yPos - 2, xPos: IF days1 - 1 = -1 THEN
  43.       PRINT "365": ELSE PRINT USING "###"; days1 - 1: END IF
  44.       COLOR 10, 0: LOCATE yPos ', ' xPos + 9:
  45.       IF days1 >= 0 AND days1 < 10 THEN
  46.         LOCATE , xPos + 2: PRINT S$(days1)
  47.       ELSEIF days1 >= 10 AND days1 < 100 THEN LOCATE , xPos + 1: PRINT S$(days1)
  48.       ELSEIF days1 >= 100 AND days1 <= 365 THEN LOCATE , xPos + 0: PRINT S$(days1)
  49.       END IF
  50.       COLOR 14, 1: LOCATE yPos + 2, xPos + 0: PRINT USING "###"; days1 + 1 ': IF days1 + 1 >= 0 AND days1 + 1 < 10 THEN
  51.  
  52.       LOCATE yPos - 5, xPos + 9
  53.       IF highlightedOption = 6 THEN
  54.       COLOR 10, 0: ELSE COLOR 14, 1: END IF: PRINT "Hours"
  55.       COLOR 14, 1: LOCATE yPos - 2, xPos + 11: IF hours1 - 1 >= 0 THEN
  56.       PRINT S$(hours1 - 1): ELSE PRINT "23": END IF
  57.       LOCATE yPos, xPos + 11: COLOR 10, 0: PRINT S$(hours1)
  58.       LOCATE yPos + 2, xPos + 11: COLOR 14, 1: IF hours1 + 1 <= 23 THEN
  59.       PRINT S$(hours1 + 1): ELSE PRINT "0": END IF
  60.  
  61.       LOCATE yPos - 5, xPos + 18
  62.       IF highlightedOption = 7 THEN
  63.       COLOR 10, 0: ELSE COLOR 14, 1: END IF: PRINT "Minutes"
  64.       COLOR 14, 1: LOCATE yPos - 2, xPos + 20: IF minutes1 - 1 >= 0 THEN
  65.       PRINT S$(minutes1 - 1): ELSE PRINT "59": END IF
  66.       LOCATE yPos, xPos + 20: COLOR 10, 0: PRINT S$(minutes1)
  67.       LOCATE yPos + 2, xPos + 20: COLOR 14, 1: IF minutes1 + 1 < 60 THEN
  68.       PRINT S$(minutes1 + 1): ELSE PRINT "0": END IF
  69.  
  70.       LOCATE yPos - 5, xPos + 29
  71.       IF highlightedOption = 8 THEN
  72.       COLOR 10, 0: ELSE COLOR 14, 1: END IF: PRINT "Seconds"
  73.       COLOR 14, 1: LOCATE yPos - 2, xPos + 32: IF seconds1 - 1 >= 0 THEN
  74.       PRINT S$(seconds1 - 1): ELSE PRINT "59": END IF
  75.       LOCATE yPos, xPos + 32: COLOR 10, 0: PRINT S$(seconds1)
  76.       LOCATE yPos + 2, xPos + 32: COLOR 14, 1: IF seconds1 + 1 <= 59 THEN
  77.       PRINT S$(seconds1 + 1): ELSE PRINT "0": END IF
  78.  
  79.       b1$ = "YYYY DDD HH MM SS"
  80.       a1$ = ""
  81.       IF years1 = 0 THEN
  82.         a1$ = "0000"
  83.       ELSEIF years1 > 0 AND years1 < 10 THEN
  84.         a1$ = "000" + S$(years1)
  85.       ELSEIF years1 >= 10 AND years1 < 100 THEN
  86.         a1$ = "00" + S$(years1)
  87.       ELSEIF years1 >= 100 AND years1 < 1000 THEN
  88.         a1$ = a1$ + "0" + S$(years1)
  89.       ELSEIF years1 >= 1000 AND years1 < 10000 THEN
  90.         a1$ = a1$ + S$(years1)
  91.       END IF
  92.       a1$ = a1$ + ":"
  93.       IF days1 = 0 THEN
  94.         a1$ = a1$ + "000"
  95.       ELSEIF days1 > 0 AND days1 < 10 THEN
  96.         a1$ = a1$ + "00" + S$(days1)
  97.       ELSEIF days1 >= 10 AND days1 < 100 THEN
  98.         a1$ = a1$ + "0" + S$(days1)
  99.       ELSE
  100.         a1$ = a1$ + S$(days1)
  101.       END IF
  102.       a1$ = a1$ + ":"
  103.       IF hours1 = 0 THEN
  104.         a1$ = a1$ + "00"
  105.       ELSEIF hours1 > 0 AND hours1 < 10 THEN
  106.         a1$ = a1$ + "0" + S$(hours1)
  107.       ELSE
  108.         a1$ = a1$ + S$(hours1)
  109.       END IF
  110.       a1$ = a1$ + ":"
  111.       IF minutes1 = 0 THEN
  112.         a1$ = a1$ + "00"
  113.       ELSEIF minutes1 > 0 AND minutes1 < 10 THEN
  114.         a1$ = a1$ + "0" + S$(minutes1)
  115.       ELSE
  116.         a1$ = a1$ + S$(minutes1)
  117.       END IF
  118.       a1$ = a1$ + ":"
  119.       IF seconds1 = 0 THEN
  120.         a1$ = a1$ + "00"
  121.       ELSEIF seconds1 > 0 AND seconds1 < 10 THEN
  122.         a1$ = a1$ + "0" + S$(seconds1)
  123.       ELSE
  124.         a1$ = a1$ + S$(seconds1)
  125.       END IF
  126.       haltAndDisplay = FALSE
  127.       '      LOCATE 48, 1: PRINT a1$
  128.     END IF
  129.  
  130.     IF _KEYDOWN(upKeydownCode) <> 0 OR _KEYDOWN(downKeydownCode) <> 0 THEN
  131.       IF keyWasPressed = FALSE THEN
  132.         timerStarted = TIMER
  133.         keyWasPressed = TRUE
  134.       END IF
  135.       IF INT(TIMER - timerStarted) = 2 THEN
  136.         Increment = 10
  137.       ELSEIF INT(TIMER - timerStarted) = 3 THEN Increment = 20
  138.       ELSEIF INT(TIMER - timerStarted) = 5 THEN Increment = 50
  139.       ELSEIF INT(TIMER - timerStarted) = 7 THEN Increment = 100
  140.       END IF
  141.     ELSE
  142.       keyWasPressed = FALSE
  143.       Increment = 1
  144.     END IF
  145.  
  146.     SELECT CASE userCommand$
  147.       CASE upArrowKey$
  148.         IF highlightedOption = 4 THEN
  149.           years1 = years1 - Increment
  150.           IF years1 <= -1 THEN years1 = 9999
  151.         ELSEIF highlightedOption = 5 THEN
  152.           days1 = days1 - Increment
  153.           IF days1 <= -1 THEN days1 = 365
  154.         ELSEIF highlightedOption = 6 THEN
  155.           hours1 = hours1 - Increment: IF hours1 <= -1 THEN hours1 = 23
  156.         ELSEIF highlightedOption = 7 THEN
  157.           minutes1 = minutes1 - Increment: IF minutes1 <= -1 THEN minutes1 = 59
  158.         ELSEIF highlightedOption = 8 THEN
  159.           seconds1 = seconds1 - Increment: IF seconds1 <= -1 THEN seconds1 = 59
  160.         END IF
  161.         haltAndDisplay = TRUE
  162.       CASE downArrowKey$
  163.         IF highlightedOption = 4 THEN
  164.           years1 = years1 + Increment
  165.           IF years1 >= 10000 THEN years1 = 0
  166.         ELSEIF highlightedOption = 5 THEN
  167.           days1 = days1 + Increment: IF days1 >= 366 THEN days1 = 0
  168.         ELSEIF highlightedOption = 6 THEN
  169.           hours1 = hours1 + Increment: IF hours1 >= 24 THEN hours1 = 0
  170.         ELSEIF highlightedOption = 7 THEN
  171.           minutes1 = minutes1 + Increment: IF minutes1 >= 60 THEN minutes1 = 0
  172.         ELSEIF highlightedOption = 8 THEN
  173.           seconds1 = seconds1 + Increment: IF seconds1 >= 60 THEN seconds1 = 0
  174.         END IF
  175.         haltAndDisplay = TRUE
  176.       CASE rightArrowKey$
  177.         highlightedOption = highlightedOption + 1
  178.         IF highlightedOption > maxOption THEN highlightedOption = minOption
  179.         haltAndDisplay = TRUE
  180.       CASE leftArrowKey$
  181.         highlightedOption = highlightedOption - 1
  182.         IF highlightedOption < minOption THEN highlightedOption = maxOption
  183.         haltAndDisplay = TRUE
  184.       CASE CHR$(13), CHR$(32)
  185.         notZero = TRUE
  186.         IF years1 = 0 AND days1 = 0 AND hours1 = 0 AND minutes1 = 0 AND seconds1 = 0 THEN
  187.           notZero = FALSE
  188.         END IF
  189.         '        isLessThan = FALSE
  190.         '        IF years1 < years2 THEN isLessThan = TRUE
  191.         '        IF years1 = years2 AND days1 < days2 THEN isLessThan = TRUE
  192.         '        IF days1 = days2 AND hours1 < hours2 THEN isLessThan = TRUE
  193.         '        IF days1 = days2 AND hours1 = hours2 AND minutes1 < minutes2 THEN isLessThan = TRUE
  194.         '        IF days1 = days2 AND hours1 = hours2 AND minutes1 = minutes2 AND seconds1 < seconds2 THEN isLessThan = TRUE
  195.         '        IF isLessThan = TRUE THEN
  196.         '          userCommand$ = ""
  197.         '          a$ = "Time 1 cannot be less than Time 2": LOCATE yPos - 8, Center(a$): COLOR 12, 0: PRINT a$
  198.         '          _DELAY (2.5)
  199.         '          a$ = "                                 ": LOCATE yPos - 8, Center(a$): COLOR 14, 1: PRINT a$
  200.         '        END IF
  201.         IF notZero = TRUE THEN 'AND isLessThan = FALSE THEN
  202.           '          LOCATE yPos + 10, 1 'xPos - 10
  203.           '          PRINT "here": ll$ = P$
  204.           this$ = "You have selected "
  205.           IF years1 <> 0 THEN
  206.             IF years1 >= 1000 THEN
  207.               lftNum = INT(years1 / 1000)
  208.               this$ = this$ + S$(lftNum) + ","
  209.               rtNum = years1 - (lftNum * 1000)
  210.               this$ = this$ + S$(rtNum)
  211.             ELSE
  212.               this$ = this$ + S$(years1)
  213.             END IF
  214.             this$ = this$ + " year"
  215.             IF years1 <> 1 THEN this$ = this$ + "s"
  216.             IF (days1 <> 0 AND (minutes1 <> 0 OR hours1 <> 0 OR seconds1 <> 0)) OR (hours1 <> 0 AND (minutes1 <> 0 OR seconds1 <> 0)) OR (minutes1 <> 0 AND seconds1 <> 0) THEN
  217.               this$ = this$ + ", "
  218.             ELSEIF days1 <> 0 OR minutes1 <> 0 OR hours1 <> 0 OR seconds1 <> 0 THEN
  219.               this$ = this$ + " and "
  220.             END IF
  221.           END IF
  222.           IF days1 <> 0 THEN
  223.             this$ = this$ + S$(days1) + " day"
  224.             IF days1 <> 1 THEN this$ = this$ + "s"
  225.             IF (hours1 <> 0 AND (minutes1 <> 0 OR seconds1 <> 0)) OR (minutes1 <> 0 AND seconds1 <> 0) THEN
  226.               this$ = this$ + ", "
  227.             ELSEIF minutes1 <> 0 AND seconds1 <> 0 THEN
  228.               this$ = this$ + " and "
  229.             END IF
  230.           END IF
  231.           IF hours1 <> 0 THEN
  232.             this$ = this$ + S$(hours1) + " hour"
  233.             IF hours1 <> 1 THEN this$ = this$ + "s"
  234.             IF minutes1 <> 0 AND seconds1 <> 0 THEN
  235.               this$ = this$ + ", "
  236.             ELSEIF minutes1 <> 0 OR seconds1 <> 0 THEN
  237.               this$ = this$ + " and "
  238.             END IF
  239.           END IF
  240.           IF minutes1 <> 0 THEN
  241.             this$ = this$ + S$(minutes1) + " minute"
  242.             IF minutes1 <> 1 THEN this$ = this$ + "s"
  243.             IF seconds1 <> 0 THEN this$ = this$ + " and "
  244.           END IF
  245.           IF seconds1 <> 0 THEN
  246.             this$ = this$ + S$(seconds1) + " second"
  247.             IF seconds1 <> 1 THEN this$ = this$ + "s"
  248.           END IF
  249.           LOCATE yPos + 10, Center(this$): PRINT this$
  250.           a$ = "Is this correct?": LOCATE yPos + 12, Center(a$): PRINT a$
  251.           yn$ = UCASE$(P$)
  252.           IF yn$ = "N" THEN GOTO differentTime1
  253.         ELSE
  254.           a$ = "You have selected 0. Is this correct?"
  255.           yn$ = UCASE$(P$)
  256.           IF yn$ = "N" THEN GOTO differentTime1
  257.         END IF
  258.       CASE CHR$(27)
  259.         montH = 1: daY = 1: year = 2022
  260.         years1 = 0: days1 = 0: hours1 = 0: minutes1 = 0: seconds1 = 0
  261.         '        years2 = 0: days2 = 0: hours2 = 0: minutes2 = 0: seconds2 = 0
  262.         haltAndDisplay = TRUE
  263.       CASE "X"
  264.         END
  265.     END SELECT
  266.   LOOP UNTIL userCommand$ = CHR$(13) OR userCommand$ = CHR$(32)
  267.  
  268.   GetOneTimeAmount$ = a1$
  269.  

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: Fickle Increment variable
« Reply #1 on: April 05, 2022, 01:26:28 pm »
You have this one giant function?

Should you not separate the demo part with the feature function part? Maybe I misunderstand?

Also looks like you have Center() function missing line 16. It's Red lining in IDE.

Offline Jaze

  • Newbie
  • Posts: 86
Re: Fickle Increment variable
« Reply #2 on: April 05, 2022, 01:26:43 pm »
oh yeah
Code: QB64: [Select]
  1. FUNCTION Center (text$): Center = INT((80 - LEN(text$))) / 2: END FUNCTION
  2. FUNCTION S$ (number): S$ = LTRIM$(STR$(number)): END FUNCTION
  3. FUNCTION P$: pause$ = INPUT$(1): IF pause$ = CHR$(27) THEN END
  4. P$ = pause$: END FUNCTION
  5.  

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: Fickle Increment variable
« Reply #3 on: April 05, 2022, 01:32:08 pm »
Is this thing for a user to select a time?

Run is not liking line 132 one bit!
Code: QB64: [Select]
  1. got$ = GetOneTimeAmount$("Test")
  2.  
  3. Function GetOneTimeAmount$ (title$)
  4.     Dim minOption, maxOption, haltAndDisplay, xPos, yPos, highlightedOption As Integer
  5.     Dim years1, days1, hours1, minutes1, seconds1, keyWasPressed, timerStarted As Integer
  6.     Dim isLessThan, notZero As Integer
  7.  
  8.     differentTime1:
  9.  
  10.     highlightedOption = 4: haltAndDisplay = TRUE: keyWasPressed = FALSE
  11.     isLessThan = FALSE: notZero = TRUE: Increment = 1
  12.     minOption = 4: maxOption = 8
  13.     Do
  14.         userCommand$ = InKey$
  15.         If haltAndDisplay = TRUE Then
  16.  
  17.             Color 14, 1: Cls: yPos = 25: xPos = 15
  18.             a$ = title$: Locate 5, Center(a$): Print a$
  19.  
  20.             Locate yPos, xPos - 3
  21.             If highlightedOption >= 4 And highlightedOption <= 8 Then
  22.             Color 10, 0: Else Color 14, 1: End If
  23.             Print "Time:"
  24.             xPos = xPos + 18
  25.  
  26.             Locate yPos - 5, xPos - 10
  27.             If highlightedOption = 4 Then
  28.             Color 10, 0: Else Color 14, 1: End If: Print "Years"
  29.             Locate yPos - 2, xPos - 10: Color 14, 1:
  30.             If years1 - 1 >= 0 Then
  31.             Print Using "#,###"; (years1 - 1): Else Print "9,999": End If
  32.             Locate yPos: Color 10, 0: If years1 >= 0 And years1 < 10 Then
  33.                 Locate , xPos - 6: Print S$(years1)
  34.             ElseIf years1 >= 10 And years1 < 100 Then Locate , xPos - 7: Print S$(years1)
  35.             ElseIf years1 >= 100 And years1 < 1000 Then Locate , xPos - 8: Print S$(years1)
  36.             ElseIf years1 >= 1000 And years1 < 10000 Then Locate , xPos - 10: Print Using "#,###"; years1
  37.             Else Print "I hope I don't see this error": End If
  38.             Locate yPos + 2, xPos - 10: Color 14, 1: If years1 + 1 < 10000 Then
  39.             Print Using "#,###"; years1 + 1: Else Print Using "#,###"; 0: End If
  40.  
  41.             Locate yPos - 5, xPos
  42.             If highlightedOption = 5 Then
  43.             Color 10, 0: Else Color 14, 1: End If: Print "Days"
  44.             Color 14, 1: Locate yPos - 2, xPos: If days1 - 1 = -1 Then
  45.             Print "365": Else Print Using "###"; days1 - 1: End If
  46.             Color 10, 0: Locate yPos ', ' xPos + 9:
  47.             If days1 >= 0 And days1 < 10 Then
  48.                 Locate , xPos + 2: Print S$(days1)
  49.             ElseIf days1 >= 10 And days1 < 100 Then Locate , xPos + 1: Print S$(days1)
  50.             ElseIf days1 >= 100 And days1 <= 365 Then Locate , xPos + 0: Print S$(days1)
  51.             End If
  52.             Color 14, 1: Locate yPos + 2, xPos + 0: Print Using "###"; days1 + 1 ': IF days1 + 1 >= 0 AND days1 + 1 < 10 THEN
  53.  
  54.             Locate yPos - 5, xPos + 9
  55.             If highlightedOption = 6 Then
  56.             Color 10, 0: Else Color 14, 1: End If: Print "Hours"
  57.             Color 14, 1: Locate yPos - 2, xPos + 11: If hours1 - 1 >= 0 Then
  58.             Print S$(hours1 - 1): Else Print "23": End If
  59.             Locate yPos, xPos + 11: Color 10, 0: Print S$(hours1)
  60.             Locate yPos + 2, xPos + 11: Color 14, 1: If hours1 + 1 <= 23 Then
  61.             Print S$(hours1 + 1): Else Print "0": End If
  62.  
  63.             Locate yPos - 5, xPos + 18
  64.             If highlightedOption = 7 Then
  65.             Color 10, 0: Else Color 14, 1: End If: Print "Minutes"
  66.             Color 14, 1: Locate yPos - 2, xPos + 20: If minutes1 - 1 >= 0 Then
  67.             Print S$(minutes1 - 1): Else Print "59": End If
  68.             Locate yPos, xPos + 20: Color 10, 0: Print S$(minutes1)
  69.             Locate yPos + 2, xPos + 20: Color 14, 1: If minutes1 + 1 < 60 Then
  70.             Print S$(minutes1 + 1): Else Print "0": End If
  71.  
  72.             Locate yPos - 5, xPos + 29
  73.             If highlightedOption = 8 Then
  74.             Color 10, 0: Else Color 14, 1: End If: Print "Seconds"
  75.             Color 14, 1: Locate yPos - 2, xPos + 32: If seconds1 - 1 >= 0 Then
  76.             Print S$(seconds1 - 1): Else Print "59": End If
  77.             Locate yPos, xPos + 32: Color 10, 0: Print S$(seconds1)
  78.             Locate yPos + 2, xPos + 32: Color 14, 1: If seconds1 + 1 <= 59 Then
  79.             Print S$(seconds1 + 1): Else Print "0": End If
  80.  
  81.             b1$ = "YYYY DDD HH MM SS"
  82.             a1$ = ""
  83.             If years1 = 0 Then
  84.                 a1$ = "0000"
  85.             ElseIf years1 > 0 And years1 < 10 Then
  86.                 a1$ = "000" + S$(years1)
  87.             ElseIf years1 >= 10 And years1 < 100 Then
  88.                 a1$ = "00" + S$(years1)
  89.             ElseIf years1 >= 100 And years1 < 1000 Then
  90.                 a1$ = a1$ + "0" + S$(years1)
  91.             ElseIf years1 >= 1000 And years1 < 10000 Then
  92.                 a1$ = a1$ + S$(years1)
  93.             End If
  94.             a1$ = a1$ + ":"
  95.             If days1 = 0 Then
  96.                 a1$ = a1$ + "000"
  97.             ElseIf days1 > 0 And days1 < 10 Then
  98.                 a1$ = a1$ + "00" + S$(days1)
  99.             ElseIf days1 >= 10 And days1 < 100 Then
  100.                 a1$ = a1$ + "0" + S$(days1)
  101.             Else
  102.                 a1$ = a1$ + S$(days1)
  103.             End If
  104.             a1$ = a1$ + ":"
  105.             If hours1 = 0 Then
  106.                 a1$ = a1$ + "00"
  107.             ElseIf hours1 > 0 And hours1 < 10 Then
  108.                 a1$ = a1$ + "0" + S$(hours1)
  109.             Else
  110.                 a1$ = a1$ + S$(hours1)
  111.             End If
  112.             a1$ = a1$ + ":"
  113.             If minutes1 = 0 Then
  114.                 a1$ = a1$ + "00"
  115.             ElseIf minutes1 > 0 And minutes1 < 10 Then
  116.                 a1$ = a1$ + "0" + S$(minutes1)
  117.             Else
  118.                 a1$ = a1$ + S$(minutes1)
  119.             End If
  120.             a1$ = a1$ + ":"
  121.             If seconds1 = 0 Then
  122.                 a1$ = a1$ + "00"
  123.             ElseIf seconds1 > 0 And seconds1 < 10 Then
  124.                 a1$ = a1$ + "0" + S$(seconds1)
  125.             Else
  126.                 a1$ = a1$ + S$(seconds1)
  127.             End If
  128.             haltAndDisplay = FALSE
  129.             '      LOCATE 48, 1: PRINT a1$
  130.         End If
  131.  
  132.         If _KeyDown(upKeydownCode) <> 0 Or _KeyDown(downKeydownCode) <> 0 Then
  133.             If keyWasPressed = FALSE Then
  134.                 timerStarted = Timer
  135.                 keyWasPressed = TRUE
  136.             End If
  137.             If Int(Timer - timerStarted) = 2 Then
  138.                 Increment = 10
  139.             ElseIf Int(Timer - timerStarted) = 3 Then Increment = 20
  140.             ElseIf Int(Timer - timerStarted) = 5 Then Increment = 50
  141.             ElseIf Int(Timer - timerStarted) = 7 Then Increment = 100
  142.             End If
  143.         Else
  144.             keyWasPressed = FALSE
  145.             Increment = 1
  146.         End If
  147.  
  148.         Select Case userCommand$
  149.             Case upArrowKey$
  150.                 If highlightedOption = 4 Then
  151.                     years1 = years1 - Increment
  152.                     If years1 <= -1 Then years1 = 9999
  153.                 ElseIf highlightedOption = 5 Then
  154.                     days1 = days1 - Increment
  155.                     If days1 <= -1 Then days1 = 365
  156.                 ElseIf highlightedOption = 6 Then
  157.                     hours1 = hours1 - Increment: If hours1 <= -1 Then hours1 = 23
  158.                 ElseIf highlightedOption = 7 Then
  159.                     minutes1 = minutes1 - Increment: If minutes1 <= -1 Then minutes1 = 59
  160.                 ElseIf highlightedOption = 8 Then
  161.                     seconds1 = seconds1 - Increment: If seconds1 <= -1 Then seconds1 = 59
  162.                 End If
  163.                 haltAndDisplay = TRUE
  164.             Case downArrowKey$
  165.                 If highlightedOption = 4 Then
  166.                     years1 = years1 + Increment
  167.                     If years1 >= 10000 Then years1 = 0
  168.                 ElseIf highlightedOption = 5 Then
  169.                     days1 = days1 + Increment: If days1 >= 366 Then days1 = 0
  170.                 ElseIf highlightedOption = 6 Then
  171.                     hours1 = hours1 + Increment: If hours1 >= 24 Then hours1 = 0
  172.                 ElseIf highlightedOption = 7 Then
  173.                     minutes1 = minutes1 + Increment: If minutes1 >= 60 Then minutes1 = 0
  174.                 ElseIf highlightedOption = 8 Then
  175.                     seconds1 = seconds1 + Increment: If seconds1 >= 60 Then seconds1 = 0
  176.                 End If
  177.                 haltAndDisplay = TRUE
  178.             Case rightArrowKey$
  179.                 highlightedOption = highlightedOption + 1
  180.                 If highlightedOption > maxOption Then highlightedOption = minOption
  181.                 haltAndDisplay = TRUE
  182.             Case leftArrowKey$
  183.                 highlightedOption = highlightedOption - 1
  184.                 If highlightedOption < minOption Then highlightedOption = maxOption
  185.                 haltAndDisplay = TRUE
  186.             Case Chr$(13), Chr$(32)
  187.                 notZero = TRUE
  188.                 If years1 = 0 And days1 = 0 And hours1 = 0 And minutes1 = 0 And seconds1 = 0 Then
  189.                     notZero = FALSE
  190.                 End If
  191.                 '        isLessThan = FALSE
  192.                 '        IF years1 < years2 THEN isLessThan = TRUE
  193.                 '        IF years1 = years2 AND days1 < days2 THEN isLessThan = TRUE
  194.                 '        IF days1 = days2 AND hours1 < hours2 THEN isLessThan = TRUE
  195.                 '        IF days1 = days2 AND hours1 = hours2 AND minutes1 < minutes2 THEN isLessThan = TRUE
  196.                 '        IF days1 = days2 AND hours1 = hours2 AND minutes1 = minutes2 AND seconds1 < seconds2 THEN isLessThan = TRUE
  197.                 '        IF isLessThan = TRUE THEN
  198.                 '          userCommand$ = ""
  199.                 '          a$ = "Time 1 cannot be less than Time 2": LOCATE yPos - 8, Center(a$): COLOR 12, 0: PRINT a$
  200.                 '          _DELAY (2.5)
  201.                 '          a$ = "                                 ": LOCATE yPos - 8, Center(a$): COLOR 14, 1: PRINT a$
  202.                 '        END IF
  203.                 If notZero = TRUE Then 'AND isLessThan = FALSE THEN
  204.                     '          LOCATE yPos + 10, 1 'xPos - 10
  205.                     '          PRINT "here": ll$ = P$
  206.                     this$ = "You have selected "
  207.                     If years1 <> 0 Then
  208.                         If years1 >= 1000 Then
  209.                             lftNum = Int(years1 / 1000)
  210.                             this$ = this$ + S$(lftNum) + ","
  211.                             rtNum = years1 - (lftNum * 1000)
  212.                             this$ = this$ + S$(rtNum)
  213.                         Else
  214.                             this$ = this$ + S$(years1)
  215.                         End If
  216.                         this$ = this$ + " year"
  217.                         If years1 <> 1 Then this$ = this$ + "s"
  218.                         If (days1 <> 0 And (minutes1 <> 0 Or hours1 <> 0 Or seconds1 <> 0)) Or (hours1 <> 0 And (minutes1 <> 0 Or seconds1 <> 0)) Or (minutes1 <> 0 And seconds1 <> 0) Then
  219.                             this$ = this$ + ", "
  220.                         ElseIf days1 <> 0 Or minutes1 <> 0 Or hours1 <> 0 Or seconds1 <> 0 Then
  221.                             this$ = this$ + " and "
  222.                         End If
  223.                     End If
  224.                     If days1 <> 0 Then
  225.                         this$ = this$ + S$(days1) + " day"
  226.                         If days1 <> 1 Then this$ = this$ + "s"
  227.                         If (hours1 <> 0 And (minutes1 <> 0 Or seconds1 <> 0)) Or (minutes1 <> 0 And seconds1 <> 0) Then
  228.                             this$ = this$ + ", "
  229.                         ElseIf minutes1 <> 0 And seconds1 <> 0 Then
  230.                             this$ = this$ + " and "
  231.                         End If
  232.                     End If
  233.                     If hours1 <> 0 Then
  234.                         this$ = this$ + S$(hours1) + " hour"
  235.                         If hours1 <> 1 Then this$ = this$ + "s"
  236.                         If minutes1 <> 0 And seconds1 <> 0 Then
  237.                             this$ = this$ + ", "
  238.                         ElseIf minutes1 <> 0 Or seconds1 <> 0 Then
  239.                             this$ = this$ + " and "
  240.                         End If
  241.                     End If
  242.                     If minutes1 <> 0 Then
  243.                         this$ = this$ + S$(minutes1) + " minute"
  244.                         If minutes1 <> 1 Then this$ = this$ + "s"
  245.                         If seconds1 <> 0 Then this$ = this$ + " and "
  246.                     End If
  247.                     If seconds1 <> 0 Then
  248.                         this$ = this$ + S$(seconds1) + " second"
  249.                         If seconds1 <> 1 Then this$ = this$ + "s"
  250.                     End If
  251.                     Locate yPos + 10, Center(this$): Print this$
  252.                     a$ = "Is this correct?": Locate yPos + 12, Center(a$): Print a$
  253.                     yn$ = UCase$(P$)
  254.                     If yn$ = "N" Then GoTo differentTime1
  255.                 Else
  256.                     a$ = "You have selected 0. Is this correct?"
  257.                     yn$ = UCase$(P$)
  258.                     If yn$ = "N" Then GoTo differentTime1
  259.                 End If
  260.             Case Chr$(27)
  261.                 montH = 1: daY = 1: year = 2022
  262.                 years1 = 0: days1 = 0: hours1 = 0: minutes1 = 0: seconds1 = 0
  263.                 '        years2 = 0: days2 = 0: hours2 = 0: minutes2 = 0: seconds2 = 0
  264.                 haltAndDisplay = TRUE
  265.             Case "X"
  266.                 End
  267.         End Select
  268.     Loop Until userCommand$ = Chr$(13) Or userCommand$ = Chr$(32)
  269.  
  270.     GetOneTimeAmount$ = a1$
  271.  
  272.  
  273. Function Center (text$): Center = Int((80 - Len(text$))) / 2: End Function
  274. Function S$ (number): S$ = LTrim$(Str$(number)): End Function
  275. Function P$: pause$ = Input$(1): If pause$ = Chr$(27) Then End
  276. P$ = pause$: End Function
  277.  
  278.  

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • Steve’s QB64 Archive Forum
Re: Fickle Increment variable
« Reply #4 on: April 05, 2022, 01:44:57 pm »
Why _KEYDOWN?  Why not use the _KEYHIT buffer instead?
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: Fickle Increment variable
« Reply #5 on: April 05, 2022, 01:49:08 pm »
Line 132 doesn't have the Const's or variables defined.

BTW to add to what Steve said, yeah I think _Keyhit is neg when holding it down and positive when release. Might be able to time that.

Offline mdijkens

  • Newbie
  • Posts: 34
Re: Fickle Increment variable
« Reply #6 on: April 05, 2022, 02:25:22 pm »
If you don't need the timings and sepate up/down events, the regular Inkey$ works easier.
I always do it like this:

Code: QB64: [Select]
  1. Const K_ESC = 27, K_SPACE = 32, K_ENTER = 13, K_BACKSPACE = 8, K_TAB = 9, K_DEL = 339
  2. Const K_UP = 328, K_LEFT = 331, K_RIGHT = 333, K_DOWN = 336
  3. Const K_HOME = 327, K_END = 335, K_PGUP = 329, K_PGDN = 337
  4.  
  5. Do While k% <> K_ESC
  6.   k% = testKey
  7.   Select Case k%
  8.     Case K_SPACE
  9.       x = 0: y = 0
  10.     Case K_UP
  11.       y = y - 1
  12.     Case K_DOWN
  13.       y = y + 1
  14.     Case K_LEFT
  15.       x = x - 1
  16.     Case K_RIGHT
  17.       x = x + 1
  18.     Case K_HOME
  19.       x = -100
  20.     Case K_END
  21.       x = 100
  22.     Case K_PGUP
  23.       y = y - 10
  24.     Case K_PGDN
  25.       y = y + 10
  26.     Case Else
  27.  
  28.  
  29. Function testKey%
  30.   ink$ = Chr$(0) + InKey$
  31.   testKey% = Asc(Right$(ink$, 1)) - 256 * (Len(ink$) = 3)

I also have a variant with added mouse inputs (testKey <0)
~ 2 million lines of BASIC

Offline Jaze

  • Newbie
  • Posts: 86
Re: Fickle Increment variable
« Reply #7 on: April 05, 2022, 02:27:22 pm »
thanks. didn't know of keyhit. I'll see if I can make it work

and I had the keyDown constants at the beginning of the code. Sorry I forgot them. They are
Code: QB64: [Select]
  1. CONST upKeydownCode = 18432
  2. CONST leftKeydownCode = 19200
  3. CONST rightKeydownCode = 19712
  4. CONST downKeydownCode = 20480