none
In this code is there anything else I need to know or change? RRS feed

  • Question

  • Hi,

    I am just practicing using Sub statements, Timer.Interval and Timer.tick statements to change to another Sub statement

    CODE:

    Start()
    Sub Start
      TextWindow.Clear()
      TextWindow.WriteLine("Type (Skip) to skip")
      user = TextWindow.Read()
      
      If Text.ConvertToLowerCase(user) = "skip" Then
        name()
      ElseIf Text.ConvertToLowerCase(user) = "" Then
        retry1()    
      Else
        retry()
      EndIf
    EndSub
    
    Sub name
      TextWindow.Clear()
      TextWindow.Writeline("Skipped")
      TextWindow.WriteLine("Wait")
      TextWindow.WriteLine("5")
      TextWindow.WriteLine(" ")
      Timer.Resume()
      Timer.Interval = 1000
      Timer.Tick = n1
    EndSub
    Sub n1 
      TextWindow.Clear()
      TextWindow.Writeline("Skipped")
      TextWindow.WriteLine("Wait")
      TextWindow.WriteLine("4")
      Timer.Tick = n2
    EndSub
    Sub n2
      TextWindow.Clear()
      TextWindow.Writeline("Skipped")
      TextWindow.WriteLine("Wait")
      TextWindow.WriteLine("3")
      Timer.Tick = n3
    EndSub
    Sub n3
      TextWindow.Clear()
      TextWindow.Writeline("Skipped")
      TextWindow.WriteLine("Wait")
      TextWindow.WriteLine("2")
      Timer.Tick = n4
    EndSub
    Sub n4
      TextWindow.Clear()
      TextWindow.Writeline("Skipped")
      TextWindow.WriteLine("Wait")
      TextWindow.WriteLine("1")
      Timer.Tick = n5
    EndSub
    Sub n5
      Timer.Pause()
      TextWindow.Clear()
      Start()
    EndSub  
    Sub retry
      Start()
    EndSub
    Sub retry1
      TextWindow.Clear()
      TextWindow.WriteLine("No Input Detected")
      TextWindow.WriteLine("Next Time Type Something")
      TextWindow.WriteLine(" ")
      TextWindow.WriteLine("Wait 8 seconds for screen to change")
      TextWindow.WriteLine("Press enter or typing will be forwarded to next screen")
      TextWindow.WriteLine(" ")
      Timer.Interval = 8000
      Timer.Tick = retry1t
    EndSub
    Sub retry1t
      Start()
      EndSub


    I love coding. This is signature is 100% Original. :)

    Saturday, February 11, 2017 8:40 PM

Answers

  • Hi Forbidden Duck

    Since those 3 lines repeat 5 times :

      TextWindow.Clear()
      TextWindow.Writeline("Skipped")
      TextWindow.WriteLine("Wait")

    why not put in a SUB.

    SUBs in a SUBs !!

    like this: see the new SUB wait at the end of the listing.

    _________________________________________________________________________________________

    Start()
    Sub Start
      TextWindow.Clear()
      TextWindow.WriteLine("Type (Skip) to skip")
      user = TextWindow.Read()
     
      If Text.ConvertToLowerCase(user) = "skip" Then
        name()
      ElseIf Text.ConvertToLowerCase(user) = "" Then
        retry1()   
      Else
        retry()
      EndIf
    EndSub

    Sub name
      wait()
      TextWindow.WriteLine("5")
      TextWindow.WriteLine(" ")
      Timer.Resume()
      Timer.Interval = 1000
      Timer.Tick = n1
    EndSub

    Sub n1
      wait()
      TextWindow.WriteLine("4")
      Timer.Tick = n2
    EndSub

    Sub n2
      wait()
      TextWindow.WriteLine("3")
      Timer.Tick = n3
    EndSub

    Sub n3
      wait()
      TextWindow.WriteLine("2")
      Timer.Tick = n4
    EndSub

    Sub n4
     wait()
      TextWindow.WriteLine("1")
      Timer.Tick = n5
    EndSub

    Sub n5
      Timer.Pause()
      TextWindow.Clear()
      Start()
    EndSub 

    Sub retry
      Start()
    EndSub

    Sub retry1
      TextWindow.Clear()
      TextWindow.WriteLine("No Input Detected")
      TextWindow.WriteLine("Next Time Type Something")
      TextWindow.WriteLine(" ")
      TextWindow.WriteLine("Wait 8 seconds for screen to change")
      TextWindow.WriteLine("Press enter or typing will be forwarded to next screen")
      TextWindow.WriteLine(" ")
      Timer.Interval = 8000
      Timer.Tick = retry1t
    EndSub

    Sub retry1t
      Start()
    EndSub

    Sub wait
      TextWindow.Clear()
      TextWindow.Writeline("Skipped")
      TextWindow.WriteLine("Wait")
    EndSub

    -----------------------------------------------------------------------------------------------------------------------------


    • Edited by YLedEditor Saturday, February 11, 2017 10:11 PM
    • Marked as answer by Forbidden Duck Saturday, February 11, 2017 10:34 PM
    Saturday, February 11, 2017 10:11 PM
    Answerer
  • You don't need all the Subs name, n1, n2.....

    Look at he following part:

    Timer.Tick=tick
    Timer.Interval=1000
    start=8
    
    Sub tick
      start=start-1
      TextWindow.Clear()
      TextWindow.WriteLine("Skipped")
      TextWindow.WriteLine(start)
      If start=0 Then
        Timer.Pause()
        TextWindow.WriteLine("End of timer")
        TextWindow.Pause()
        Program.End()
      EndIf
    EndSub


    Jan [ WhTurner ] The Netherlands

    • Marked as answer by Forbidden Duck Sunday, February 12, 2017 5:17 PM
    Sunday, February 12, 2017 12:04 PM
    Answerer

All replies

  • Forbidden Duck,

    Looks good. Better than goto statements. Easier to read.


    JR

    Saturday, February 11, 2017 9:34 PM
    Answerer
  • Awesome

    I love coding. This is signature is 100% Original. :)

    Saturday, February 11, 2017 9:44 PM
  • Hi Forbidden Duck

    Since those 3 lines repeat 5 times :

      TextWindow.Clear()
      TextWindow.Writeline("Skipped")
      TextWindow.WriteLine("Wait")

    why not put in a SUB.

    SUBs in a SUBs !!

    like this: see the new SUB wait at the end of the listing.

    _________________________________________________________________________________________

    Start()
    Sub Start
      TextWindow.Clear()
      TextWindow.WriteLine("Type (Skip) to skip")
      user = TextWindow.Read()
     
      If Text.ConvertToLowerCase(user) = "skip" Then
        name()
      ElseIf Text.ConvertToLowerCase(user) = "" Then
        retry1()   
      Else
        retry()
      EndIf
    EndSub

    Sub name
      wait()
      TextWindow.WriteLine("5")
      TextWindow.WriteLine(" ")
      Timer.Resume()
      Timer.Interval = 1000
      Timer.Tick = n1
    EndSub

    Sub n1
      wait()
      TextWindow.WriteLine("4")
      Timer.Tick = n2
    EndSub

    Sub n2
      wait()
      TextWindow.WriteLine("3")
      Timer.Tick = n3
    EndSub

    Sub n3
      wait()
      TextWindow.WriteLine("2")
      Timer.Tick = n4
    EndSub

    Sub n4
     wait()
      TextWindow.WriteLine("1")
      Timer.Tick = n5
    EndSub

    Sub n5
      Timer.Pause()
      TextWindow.Clear()
      Start()
    EndSub 

    Sub retry
      Start()
    EndSub

    Sub retry1
      TextWindow.Clear()
      TextWindow.WriteLine("No Input Detected")
      TextWindow.WriteLine("Next Time Type Something")
      TextWindow.WriteLine(" ")
      TextWindow.WriteLine("Wait 8 seconds for screen to change")
      TextWindow.WriteLine("Press enter or typing will be forwarded to next screen")
      TextWindow.WriteLine(" ")
      Timer.Interval = 8000
      Timer.Tick = retry1t
    EndSub

    Sub retry1t
      Start()
    EndSub

    Sub wait
      TextWindow.Clear()
      TextWindow.Writeline("Skipped")
      TextWindow.WriteLine("Wait")
    EndSub

    -----------------------------------------------------------------------------------------------------------------------------


    • Edited by YLedEditor Saturday, February 11, 2017 10:11 PM
    • Marked as answer by Forbidden Duck Saturday, February 11, 2017 10:34 PM
    Saturday, February 11, 2017 10:11 PM
    Answerer
  • Ha Ha good point

    Just sub every word you use


    I love coding. This is signature is 100% Original. :)

    Saturday, February 11, 2017 10:34 PM
  • You don't need all the Subs name, n1, n2.....

    Look at he following part:

    Timer.Tick=tick
    Timer.Interval=1000
    start=8
    
    Sub tick
      start=start-1
      TextWindow.Clear()
      TextWindow.WriteLine("Skipped")
      TextWindow.WriteLine(start)
      If start=0 Then
        Timer.Pause()
        TextWindow.WriteLine("End of timer")
        TextWindow.Pause()
        Program.End()
      EndIf
    EndSub


    Jan [ WhTurner ] The Netherlands

    • Marked as answer by Forbidden Duck Sunday, February 12, 2017 5:17 PM
    Sunday, February 12, 2017 12:04 PM
    Answerer
  • Nice, I'll keep that in mind next time.


    I love coding. This is signature is 100% Original. :)

    Sunday, February 12, 2017 5:17 PM