Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Through traffic or no?
#5
Similar to just setting a flag but doing so with an event...

Code: (Select All)
' Main
Cls
Locate 10, 2: Print "Message";: Color 7 + 16: Print ":";: Color 7, 0
Do

    keyboard key$

    If Len(key$) Then
        If LCase$(key$) >= "a" And LCase$(key$) <= "z" Or key$ = " " Then

            message key$

            If key$ = Chr$(13) Then
                Locate 10, 11: Print Space$(_Width - Pos(0)); ' Message sent.
                Locate 10, 2: Print "Message";: Color 7 + 16: Print ":";: Color 7, 0 ' Ready for next message.
            End If
            If key$ = Chr$(27) Then Exit Do
        End If
    End If

    animate

Loop
End

Sub keyboard (key$) ' Flow-through sub-routine.
    _Limit 30
    key$ = InKey$
End Sub

Sub message (key$) ' Non-flow-through sub-routine.
    y = 10: x = 10
    Locate 10, 2: Print "Message:"; ' Stops colon from flashing.
    Do

        animate: Locate y, x + 1, 1 ' animation routine is called again here.

        If LCase$(key$) >= "a" And LCase$(key$) <= "z" Or key$ = " " Then
            If x < _Width Then x = x + 1: Locate y, x, 1: Print key$;: x = Pos(0) - 1
        End If
        If key$ = Chr$(8) And x > 10 Then Locate y, x: Print " ";: x = Pos(0) - 2

        keyboard key$

    Loop Until key$ = Chr$(13) Or key$ = Chr$(27)
End Sub

Sub animate ' Flow-through sub-routine.
    Static ii, z
    If Abs(Timer - z) > .25 Then
        z = Timer
        If ii Then Locate 15, ii, 0: Print " "; Else Locate 15, _Width: Print " ";
        ii = ii + 1
        Locate 15, ii, 0: Print Chr$(254);
        If ii = _Width Then ii = 0
    End If
End Sub

Okay, let's pretend that message routine was a full blown word processor of around 8000 lines of code. That would take some hefty planning to make it a flow through routine back to the animation in the main; so a solution is to do as in the code above, make it call the animate routine in both the main and the wp message routine. Of course if it was really just a small program, as above, I would have coded then message routine to flow through to the main. The reason is because a program is easier to understand and debug when the programmer can easily figure out which routine was the calling routine. One call to animate is better than two, in this case.

Pete
Reply


Messages In This Thread
Through traffic or no? - by Pete - 12-02-2024, 02:05 AM
RE: Through traffic or no? - by Petr - 12-02-2024, 01:45 PM
RE: Through traffic or no? - by Pete - 12-02-2024, 04:28 PM
RE: Through traffic or no? - by SMcNeill - 12-02-2024, 04:50 PM
RE: Through traffic or no? - by Pete - 12-02-2024, 06:17 PM
RE: Through traffic or no? - by JRace - 12-02-2024, 09:08 PM
RE: Through traffic or no? - by Pete - 12-02-2024, 10:39 PM
RE: Through traffic or no? - by JRace - 12-02-2024, 11:46 PM
RE: Through traffic or no? - by Pete - 12-03-2024, 12:17 AM



Users browsing this thread: 5 Guest(s)