Author Topic: is this a buig, am I blind or do I just not know something abiout the code?  (Read 1168 times)

0 Members and 1 Guest are viewing this topic.

Offline Jaze

  • Newbie
  • Posts: 86
Code: QB64: [Select]
  1.         PRINT "fileLine$ ="
  2.         PRINT "|          Joe             C-23:54-C                                       |"
  3.         IF INSTR(fileLine$, "C-") <> 0 AND INSTR(fileLine$, "-C") <> 0 THEN
  4.           ctS = INSTR(fileLine$, "C-") + 2
  5.           ctE = INSTR(fileLine$, "-C") - 1
  6.           possibleCallTime$ = MID$(fileLine$, ctS, ctE - ctS + 1)
  7.           IF IsCallTime(possibleCallTime$, collectingFigure) = TRUE THEN
  8.             CLS
  9.             PRINT "MID$(fileLine$, ctS, ctE - ctS + 1) = "
  10.             PRINT MID$(fileLine$, ctS, ctE - ctS + 1) 'the MID$ here prints the entire string of "23:54"
  11.             callTime$ = possibleCallTime$
  12.             callTimeTotalSeconds = callTimeTotalSeconds + NumberOfSecondsInCallTime(callTime$)
  13.             numberOfCalls = numberOfCalls + 1
  14.             PRINT
  15.  
  16.             PRINT "         1         2         3         4         5         6         7"
  17.             PRINT "1234567890123456789012345678901234567890123456789012345678901234567890123456:"
  18.             PRINT fileLine$
  19.             PRINT
  20.             PRINT "ctS (callTimeStart): " + LTRIM$(STR$(ctS))
  21.             PRINT "ctE (callTimeEnd): " + LTRIM$(STR$(ctE))
  22.             'the following line only prints out the seconds in the call time but otherwise acts properly=
  23.             PRINT "callTime$ = |" + callTime$ + "|     " 'here the minutes and colon are missing
  24.             PRINT
  25.             PRINT "NumberOfSecondsInCallTime(callTime$): " + S$(NumberOfSecondsInCallTime(callTime$))
  26.             PRINT
  27.             PRINT "callTimeTotalSeconds: " + S$(callTimeTotalSeconds)
  28.             PRINT
  29.             PRINT "numberOfCalls: " + S$(numberOfCalls)
  30.             gg$ = P$
  31.           END IF
  32.         END IF
IsCallTime checks the format of the string and returns true if it is in the form of H:MM:SS, MM:SS or M:SS
NumberOfSecondsInCallTime converts the call time to seconds
'callTime$ has only the seconds printed to the screen. it is passed properly to the function that changes it into seconds and it works properly in IsCallTime but it won't print out properly. why?

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Where you have S$ do you mean Str$?

Offline Jaze

  • Newbie
  • Posts: 86
yeah, sorry. s$(number) is just s short form ltrim$(str$(number)) -- I use it a lot

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Yeah I have a shortcut for that too.

Be nice if we had all the needed subs and functions but could get even more confusing...

Your variable naming is admirably descriptive, but I am having a hard time cutting to chase of problem stumbling over all those syllables.

Have you run this thing through Option _Explicit? so easy for typo and all...



Offline Jaze

  • Newbie
  • Posts: 86
no. I actually just passed the MID$ instead of putting it  in a variable first. I just would like to know wtf is happening

using the long variable names makes it easier to se typos as they occur. if the case  doesn't get set correctly after a moment I immediately know I have a typo

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • Steve’s QB64 Archive Forum
If I had to guess without seeing the subs, I'd think you're probably dealing with parameter corruption.  Remember -- subs can pass values BACK as well as receive them.


SUB foo (x$)
   x$ = "cheese"
END SUB

Doesn't matter what x$ was before the call to foo above -- it's cheese afterwards!

To preserve the variable without changing it:

SUB foo (passedX$)
   x$ = passedX$ 'local use, non-return variable
   x$ = "cheese"
END SUB

In the above, we assign our passed value to a local variable and work with that variable.  No matter how much it changes in SUB, it never affects the value of the original.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Everything seems to work when I plug in dummy functions so Steve may be correct.

Code: QB64: [Select]
  1. Const TRUE = -1
  2. Print "fileLine$ ="
  3. Print "|          Joe             C-23:54-C                                       |"
  4. fileLine$ = "|          Joe             C-23:54-C                                       |"
  5. If InStr(fileLine$, "C-") <> 0 And InStr(fileLine$, "-C") <> 0 Then
  6.     ctS = InStr(fileLine$, "C-") + 2
  7.     ctE = InStr(fileLine$, "-C") - 1
  8.     'Print ctS, ctE
  9.  
  10.     possibleCallTime$ = Mid$(fileLine$, ctS, ctE - ctS + 1)
  11.     'Print possibleCallTime$
  12.  
  13.     If IsCallTime(possibleCallTime$, collectingFigure) = TRUE Then
  14.         Cls
  15.         Print "MID$(fileLine$, ctS, ctE - ctS + 1) = "
  16.         Print Mid$(fileLine$, ctS, ctE - ctS + 1) 'the MID$ here prints the entire string of "23:54"
  17.         callTime$ = possibleCallTime$
  18.         callTimeTotalSeconds = callTimeTotalSeconds + NumberOfSecondsInCallTime(callTime$)
  19.         numberOfCalls = numberOfCalls + 1
  20.         Print
  21.  
  22.         Print "         1         2         3         4         5         6         7"
  23.         Print "1234567890123456789012345678901234567890123456789012345678901234567890123456:"
  24.         Print fileLine$
  25.         Print
  26.         Print "ctS (callTimeStart): " + LTrim$(Str$(ctS))
  27.         Print "ctE (callTimeEnd): " + LTrim$(Str$(ctE))
  28.         'the following line only prints out the seconds in the call time but otherwise acts properly=
  29.         Print "callTime$ = |" + callTime$ + "|     " 'here the minutes and colon are missing
  30.         Print
  31.         Print "NumberOfSecondsInCallTime(callTime$): " + S$(NumberOfSecondsInCallTime(callTime$))
  32.         Print
  33.         Print "callTimeTotalSeconds: " + S$(callTimeTotalSeconds)
  34.         Print
  35.         Print "numberOfCalls: " + S$(numberOfCalls)
  36.         gg$ = P$
  37.     End If
  38.  
  39. Function IsCallTime (t$, n)
  40.     IsCallTime = -1
  41.  
  42. Function NumberOfSecondsInCallTime (t$)
  43.     NumberOfSecondsInCallTime = 10
  44.  
  45. Function S$ (n)
  46.     S$ = _Trim$(Str$(n))
  47.  
  48.  
  49.