none
Timer RRS feed

  • Question

  • The following subroutine is supposed to update a date/time display in the textwindow. Before the top 2 and bottom two lines were added, the sub would paste the date/time in odd places. The four lines were added in an attempt to stop that. They did not. So I commented them out ad reran the program and it still did the same oddly placed updates. Prior to this the sub was named UpdateClock, and instead of using the timer I had sub calls made after every other subroutine returned. This worked fine except that the date/time updates were not the ticking of the clock but rather an update based on the state of the clock at the time of the sub call. Is there a way to make the date/time updates look like the smooth ticking of a clock?

    Sub OnTimer
      'CurrentLeft = TextWindow.CursorLeft
      'CurrentTop = TextWindow.CursorTop
      TextWindowPlus.ForegroundColor = "white"
      TextWindowPlus.CursorLeft = 11
      TextWindowPlus.CursorTop = 3
      TextWindowPlus.Write(Clock.WeekDay)
      TextWindowPlus.CursorLeft = 11
      TextWindowPlus.CursorTop = 4
      TextWindowPlus.Write(Clock.Date)
      TextWindowPlus.CursorLeft = 11
      TextWindowPlus.CursorTop = 5
      TextWindowPlus.Write(Clock.Time)
      'TextWindow.CursorLeft = CurrentLeft
      'TextWindow.CursorTop = CurrentTop
    EndSub

    Sunday, January 20, 2013 8:52 PM

Answers

  • It works fine for me. Could we have the rest of your code so we can fully see what the problem is? Or maybe it's just because you're using an extension for TextWindowPlus. Extensions don't always work exactly as they say. I replaced all the TextWindowPlus lines with TextWindow and it works fine for me.

    I am an 11 year old that loves math, games, and computers. 'Binary is as easy as 1, 10, 11.'


    Sunday, January 20, 2013 9:36 PM
  • The same here. I haven't noticed any abnormally when not using any extension.

    Here's a tweaked version:

    Timer.Tick = OnTimer
    Timer.Interval = 1000
    
    TAB = Text.GetCharacter(9)
    
    Sub OnTimer
      
      TextWindow.CursorTop = 3
      
      TextWindow.WriteLine(TAB + Clock.WeekDay)
      TextWindow.WriteLine(TAB + Clock.Date)
      TextWindow.WriteLine(TAB + Clock.Time)
      
    EndSub

    Click on "Propose As Answer" if some post solves your problem or "Vote As Helpful" if some post has been useful to you! (^_^)

    Sunday, January 20, 2013 11:37 PM
    Answerer
  • TAB = Text.GetCharacter(9) was not meant to fix anything!
    Just to compact the code and avoid excessive use of TextWindow.CursorLeft & TextWindow.CursorTop!

    Now I ask, have you tested my example the way it is?
    Pay attention it's not using any extensions -> it's TextWindow category; not TextWindowPlus one!

    Also, TextWindow.WriteLine inserts a life-feed at the end of it, jumping a line!
    Again, it's just to avoid extra TextWindow.CursorTop(s) to the next row unnecessarily.  ;-)

    Double-check whether the extended TextWindowPlus category is working the way you expect.
    Laterz!!!

    Click on "Propose As Answer" if some post solves your problem or "Vote As Helpful" if some post has been useful to you! (^_^)

    Monday, January 21, 2013 7:56 AM
    Answerer

All replies

  • It works fine for me. Could we have the rest of your code so we can fully see what the problem is? Or maybe it's just because you're using an extension for TextWindowPlus. Extensions don't always work exactly as they say. I replaced all the TextWindowPlus lines with TextWindow and it works fine for me.

    I am an 11 year old that loves math, games, and computers. 'Binary is as easy as 1, 10, 11.'


    Sunday, January 20, 2013 9:36 PM
  • The same here. I haven't noticed any abnormally when not using any extension.

    Here's a tweaked version:

    Timer.Tick = OnTimer
    Timer.Interval = 1000
    
    TAB = Text.GetCharacter(9)
    
    Sub OnTimer
      
      TextWindow.CursorTop = 3
      
      TextWindow.WriteLine(TAB + Clock.WeekDay)
      TextWindow.WriteLine(TAB + Clock.Date)
      TextWindow.WriteLine(TAB + Clock.Time)
      
    EndSub

    Click on "Propose As Answer" if some post solves your problem or "Vote As Helpful" if some post has been useful to you! (^_^)

    Sunday, January 20, 2013 11:37 PM
    Answerer
  • here is the whole program code. The program is far from finished.


    '****************
    '***   Prelims   ***
    '****************
    DataFile = "Register-2013.dat"
    Folder = "e:\SmallBasic\Progs\"
    HelpFile = "CheckBookHelp.txt"
    FileName = ""
    ReportData = "Report-2013.dat
    CheckFlag = "false"
    ReportFlag = "false"

    '**********************
    '***  Main Program  ***
    '**********************
    TextWindow.Title = "CheckBook Manager"

    MakeLines()
    SetClockPane()
    Timer.Tick = OnTimer
    Timer.Interval = 1000
    Title = " Opening Screen "
    SetTitle()
    SetBalancePane()
    FileName = DataFile
    ArrayName = "CheckData"
    Path = Folder + DataFile
    GetFile()
    FileName = HelpFile
    ArrayName = "CheckHelp"
    Path = Folder + HelpFile
    GetFile()
    ArrayName = "Report"
    FileName = ReportData
    Path = Folder + ReportData
    GetFile()
    SetMenuPane()
    Title = " Main Screen "
    SetTitle()
    SetMainMenu()

    '**********************
    '***  Quit Program  ***
    '**********************
    Quit:
    MakeLines()
    Title = " Closing Screen"
    x = 1
    y = (167 - Text.GetLength(Msg)) / 2
    Fore = "darkblue"
    Back = "white"
    SetTitle()
    Msg = " Thank you for using out product. "
    Fore = "green"
    Back = "darkblue"
    x = 6
    y = (167 - Text.GetLength(Msg)) / 2
    SetMsg()
    Msg = "2013 Avdiel Data Solutions"
    Fore = "magenta"
    x = 51
    y = (167 - Text.GetLength(Msg)) / 2
    SetMsg()
    ProgramPlus.Delay(3000)
    ProgramPlus.End()
    If CheckFlag = "true" Then
      ArrayName = "CheckCata"
      FileName = "Register-2013.dat"
      SaveFile()
    EndIf
    If ReportFlag = "true" Then
      ArrayName = "Report"
      FileName = "Report-2013.dat"
      SaveFile()
    EndIf

    '***********************************
    '***  E N D    O F    P R O G R A M  ***
    '***********************************

    '********************
    '***  Subroutines  ***
    '********************
    Sub MakeLines
      TextWindowPlus.Clear()
      TextWindowPlus.ForegroundColor = "red"
      For i = 0 To 167
        TextWindowPlus.CursorTop = 2
        TextWindowPlus.CursorLeft = i
        TextWindowPlus.Write("*")
      EndFor
      For i = 0 To 167
        TextWindowPlus.CursorTop = 53
        TextWindowPlus.CursorLeft = i
        TextWindowPlus.Write("*")
      EndFor
      TextWindowPlus.ForegroundColor = "white"
    EndSub

    Sub SetTitle
      TextWindowPlus.ForegroundColor = "darkblue"
      For i = 1 to 167
        TextWindowPlus.CursorTop = 1
        TextWindowPlus.CursorLeft = i
        TextWindowPlus.Write(" ")
      EndFor
      TextWindowPlus.BackgroundColor = "white"
      TextWindowPlus.ForegroundColor = "darkblue"
      TextWindowPlus.CursorTop = 1
      TextWindowPlus.CursorLeft = (167-Text.GetLength(Title))/2
      TextWindowPlus.Write(Title)
      TextWindowPlus.BackgroundColor = "darkblue"
      TextWindowPlus.ForegroundColor = "white"
    EndSub

    Sub SetMsg
      TextWindowPlus.CursorTop = x
      TextWindowPlus.CursorLeft = y
      TextWindowPlus.ForegroundColor = Fore
      TextWindowPlus.BackgroundColor = Back
      TextWindowPlus.Write(Msg)
      TextWindowPlus.BackgroundColor = "darkblue"
      TextWindowPlus.ForegroundColor = "white"
    EndSub

    Sub GetFile
      Title = " Getting Data File "
      x = 1
      y = (167 - Text.GetLength(Title)) / 2
      SetTitle()
      TextWindowPlus.ForegroundColor = "white"
      Msg = "Searching for " + FileName
      if FilePlus.FileExists(Path) Then
        Msg = "Opening " + FileName
        x = 51
        y = 4
        Fore = "yellow""
        SetMsg()
        Program.Delay(500)
        ClearMsg()
        Msg = "Reading " + FileName
        Fore = "yellow"
        x = 51
        y = 4
        SetMsg()
        ProgramPlus.Delay(500)
        ClearMsg()
        NumLine = FilePlus.GetNumberOfLines(Path)
        ArrayName = FilePlus.ReadFileToArray(Path)
        RecNum = NumLine/5  
        Msg = "Finished"
        x = 51
        y = 4
        Fore = "yellow"
        SetMsg()
        ProgramPlus.Delay(500)
        ClearMsg()
      Else 
        Msg = FileName + " Not Found"
        x = 51
        y = 4
        Fore = "yellow"
        Back = "darkblue"
        SetMsg()
        ProgramPlus.Delay(500)
        ClearMsg()
    GetReply:
        Msg = "Create " + FileName + " now? (y/n)"
        x = 51
        y = 4
        Fore = "yellow"
        Back = "darkblue"
        SetMsg()
        TextWindow.CursorLeft = Text.GetLength(Msg)+5 'column position
        TextWindow.CursorTop = 4
        Reply = TextWindow.readkey()
        Text.ConvertToUpperCase(Reply)
        If Reply = "Y" Then
          x = 4
          y = 6
          Fore = "darkblue"
          ClearMsg()
          Msg = "Creeating " + FileName
          x = 51
          y = 6
          Fore = "yellow""
          SetMsg()
          Program.Delay(500)
          File.WriteLine(Path,1, "")
          Program.Delay(500)
          ClearMsg()
        ElseIf Reply = "N" then
          x = 51
          y = 6
          Fore = "darkblue"
          Back = "darkblue"
          ClearMsg()
          Goto Stop
        Else
          Goto GetReply
        EndIf
        Goto Quit
      EndIf
    Stop:
    EndSub

    Sub ClearMsg
      TextWindowPlus.ForegroundColor = "darkblue"
      For i = 4 To TextPlus.GetLength(Msg)+5
        TextWindowPlus.CursorTop = x
        TextWindowPlus.CursorLeft = i
        TextWindowPlus.Write(" ")
      EndFor
      TextWindowPlus.ForegroundColor = "white"
    EndSub

    Sub SaveFile
      Msg = "Saving " + FileName
      x = 4
      y = 4
      Fore = "yellow"
      SetMsg()
      For I = 1 To Array.GetItemCount(ArrayName)
        File.WriteLine(Path, i, ArrayName[i])
      EndFor
      Program.Delay(1000)
      ClearMsg()
    EndSub

    Sub SetClockPane
      TextWindowPlus.ForegroundColor= "red
      For i = 3 To 5
        TextWindowPlus.CursorLeft = 0
        TextWindowPlus.CursorTop = i
        TextWindowPlus.Write("*")
      EndFor
      For i = 3 To 5
        TextWindowPlus.CursorLeft = 21
        TextWindowPlus.CursorTop = i
        TextWindowPlus.Write("*")
      EndFor
      For i = 0 To 21
        TextWindowPlus.CursorLeft = i
        TextWindowPlus.CursorTop = 6
        TextWindowPlus.Write("*")
      EndFor
      TextWindowPlus.ForegroundColor = "magenta"
      TextWindowPlus.CursorLeft = 2
      TextWindowPlus.CursorTop = 3
      TextWindowPlus.Write("The Day :")
      TextWindowPlus.CursorLeft = 2
      TextWindowPlus.CursorTop = 4
      TextWindowPlus.Write("The Date:")
      TextWindowPlus.CursorLeft = 2
      TextWindowPlus.CursorTop = 5
      TextWindowPlus.Write("The Time:")
    EndSub

    Sub OnTimer
      'CurrentLeft = TextWindow.CursorLeft
      'CurrentTop = TextWindow.CursorTop
      TextWindowPlus.ForegroundColor = "white"
      TextWindowPlus.CursorLeft = 11
      TextWindowPlus.CursorTop = 3
      TextWindowPlus.Write(Clock.WeekDay)
      TextWindowPlus.CursorLeft = 11
      TextWindowPlus.CursorTop = 4
      TextWindowPlus.Write(Clock.Date)
      TextWindowPlus.CursorLeft = 11
      TextWindowPlus.CursorTop = 5
      TextWindowPlus.Write(Clock.Time)
      'TextWindow.CursorLeft = CurrentLeft
      'TextWindow.CursorTop = CurrentTop
    EndSub

    Sub SetBalancePane ''''draw asterisk fences
      TextWindowPlus.ForegroundColor = "red"
      For i = 3 To 6
        TextWindowPlus.CursorLeft = 22
        TextWindowPlus.CursorTop = i
        TextWindow.Write("*")
      EndFor
      For i = 3 To 6
        TextWindowPlus.CursorLeft = 51
        TextWindowPlus.CursorTop = i
        TextWindow.Write("*")
      EndFor
      For i = 23 To 51
        TextWindowPlus.CursorLeft = i
        TextWindowPlus.CursorTop = 6
        TextWindowPlus.Write("*")
      EndFor
      TextWindowPlus.ForegroundColor = "magenta"
      TextWindowPlus.CursorTop = 3
      TextWindowPlus.CursorLeft = 24
      TextWindowPlus.Write("  Total Credits: ")
      TextWindowPlus.CursorLeft = 24
      TextWindowPlus.CursorTop = 4
      TextWindowPlus.Write("   Total Debits: ")
      TextWindowPlus.CursorLeft = 24
      TextWindowPlus.CursorTop = 5
      TextWindowPlus.Write("Current Balance: ")
      TextWindowPlus.ForegroundColor = "white"
    EndSub

    Sub SetMenuPane
      TextWindowPlus.ForegroundColor = "cyan"
      For i = 7 To 50 'down left side
        TextWindowPlus.CursorLeft = 1
        TextWindowPlus.CursorTop = i
        TextWindowPlus.Write("*")
      EndFor
      For i = 1 To 51  'across bottom
        TextWindowPlus.CursorLeft = i
        TextWindowPlus.CursorTop = 50
        TextWindowPlus.Write("*")
      EndFor
      For i = 50 To 7 Step -1  'up right side
        TextWindowPlus.CursorLeft = 51
        TextWindowPlus.CursorTop = i
        TextWindowPlus.Write("*")
      EndFor
      For i = 51 To 1 Step -1  'across top right to left
        TextWindowPlus.CursorLeft = i
        TextWindowPlus.CursorTop = 7
        TextWindowPlus.Write("*")
      EndFor
      TextWindowPlus.CursorLeft = 1
      TextWindowPlus.CursorTop = 52
      TextWindowPlus.ForegroundColor = "white"
    EndSub

    Sub ClearMenuPane
      TextWindowPlus.ForegroundColor = "darkblue"
      For j = 8 To 49
        For i = 2 To 49
          TextWindowPlus.CursorLeft = i
          TextWindowPlus.CursorTop = j
          TextWindowPlus.Write(" ")
        EndFor
      EndFor
      TextWindowPlus.ForegroundColor = "white"
      TextWindowPlus.CursorLeft = 1
      TextWindowPlus.CursorTop = 52
    EndSub

    Sub NoModule
      ClearMenuPane()
      Msg = " Notice "
      y = (47-Text.GetLength(Msg))/2
      x = 10
      Back = "white"
      Fore = "darkblue"
      SetMsg()
      Back = "darkblue"
      Fore = "Yellow"
      Msg = "Thee MODULE selected is not implemented yet."
      y = 3
      x = 12
      SetMsg()
    EndSub

    Sub SetMainMenu 
      Msg = " Main Menu "
      Fore = "darkblue"
      Back = "white"
      x = 10
      y = (50-Text.GetLength(Msg))/2
      SetMsg()
      TextWindowPlus.BackgroundColor = "darkblue"
      TextWindowPlus.ForegroundColor = "yellow"
      Msg = "Select an option by letter:"
      x = 12
      y = 3
      Back = "darkblue"
      Fore = "magenta"
      SetMsg()
      Msg = "A.  Add New Data"
      x = 14
      y = 5
      Back = "dardblue"
      Fore = "yellow"
      SetMsg()
      Msg = "B.  View Data"
      x = 15
      y = 5
      Back = "dardblue"
      Fore = "yellow"
      SetMsg()
      Msg = "C.  Search Data"
      x = 16
      y = 5
      Back = "dardblue"
      Fore = "yellow"
      SetMsg()
      Msg = "D.  Help"
      x = 17
      y = 5
      Fore = "yellow"
      SetMsg()
      Msg = "E.  Exit"
      x = 18
      y = 5
      Fore = "yellow"
      SetMsg()
      Msg = "Selection -> "
      x = 52
      y = 1
      Back = "dardblue"
      Fore = "yellow"
      SetMsg()
      y = Text.GetLength(Msg)
    MainReply:
    Reply = TextWindow.readkey()
    TextWindowPlus.Write(Text.GetCharacter(10) + Reply)
    Reply = Text.ConvertToUpperCase(Reply)
    If Reply = "A" Then
      TextWindow.CursorLeft = 1
      TextWindow.CursorTop = 52
      TextWindow.Write("              ")
      NoModule()
      Program.Delay(500)
      ClearMenuPane()
      SetMainMenu()
    EndIf
    If Reply = "B" Then
      TextWindow.CursorLeft = 1
      TextWindow.CursorTop = 52
      TextWindow.Write("              ")
      NoModule()
      Program.Delay(500)
      ClearMenuPane()
      SetMainMenu()
    EndIf
    If Reply = "C" Then
      TextWindow.CursorLeft = 1
      TextWindow.CursorTop = 52
      TextWindow.Write("              ")
      NoModule()
      Program.Delay(500)
      ClearMenuPane()
      SetMainMenu()
    EndIf
    If Reply = "D" Then
      TextWindow.CursorLeft = 1
      TextWindow.CursorTop = 52
      TextWindow.Write("              ")
      NoModule()
      Program.Delay(500)
      ClearMenuPane()
      SetMainMenu()
    EndIf
    If Reply = "E" Then
      Goto MainStop
    EndIf
    Goto MainReply
    MainStop:
    EndSub

    Sub ClearBalancePane  '  sub to clear balance pane
      TextWindowPlus.CursorLeft = 25
      TextWindowPlus.CursorTop = 3
      TextWindowPlus.Write("          ")
      TextWindowPlus.CursorLeft = 25
      TextWindowPlus.CursorTop = 4
      TextWindowPlus.Write("          ")
      TextWindowPlus.CursorLeft = 25
      TextWindowPlus.CursorTop = 5
     TextWindowPlus.Write("          ")
    EndSub

    Sunday, January 20, 2013 11:43 PM
  • Adding the TAB character did not help. Changing the TextWindow.Write command to TextWindow.WriteLine likewise did not change anything. In both cases the date/time printings are still showing up all over the screen.

    Thanks....

    Sunday, January 20, 2013 11:58 PM
  • TAB = Text.GetCharacter(9) was not meant to fix anything!
    Just to compact the code and avoid excessive use of TextWindow.CursorLeft & TextWindow.CursorTop!

    Now I ask, have you tested my example the way it is?
    Pay attention it's not using any extensions -> it's TextWindow category; not TextWindowPlus one!

    Also, TextWindow.WriteLine inserts a life-feed at the end of it, jumping a line!
    Again, it's just to avoid extra TextWindow.CursorTop(s) to the next row unnecessarily.  ;-)

    Double-check whether the extended TextWindowPlus category is working the way you expect.
    Laterz!!!

    Click on "Propose As Answer" if some post solves your problem or "Vote As Helpful" if some post has been useful to you! (^_^)

    Monday, January 21, 2013 7:56 AM
    Answerer