none
Subroutine troubble RRS feed

  • Question

  • I have hopefully a simple question. Can anyone tell me why when I run the following code in Small Basic that when the program calls the subroutine YNcheck, that it will not return to the Asksource section. It skips it and goes onto the askdest section. That is not what I want.

    Thank you for the help

    Jorge

    asksource:
    'Asking for input from use
    clear()
    TextWindow.Write ("What is the starting folder? " )
    startfolder = TextWindow.Read()
    TextWindow.WriteLine ("")
    TextWindow.Write ("So " +startfolder+ " is what you want? Y/N ")
    'Checking Condition for source folder
    check = TextWindow.Read()
    YNcheck()
    If check = "n" Or "N" Then
      Goto asksource
    EndIf

    askdest:
    'Asking for input from use
    clear()
    TextWindow.Write ("What is the desitnation folder?" )
    destfolder = TextWindow.Read()
    TextWindow.WriteLine("")
    TextWindow.Write ("So " +destfolder+ " is what you want? Y/N ")
    correct = TextWindow.Read()
    YNcheck()
    If correct = "n" or "N" then   
       goto askdest
    EndIf

    '+++++++++++++++
    'Subroutines Section
    '+++++++++++++++

    'Clearing screen routine
    sub clear
    TextWindow.WriteLine("")
    TextWindow.Pause()
    TextWindow.Clear()
    EndSub

    'Incorrect input routine
    Sub YNcheck
      If  check <> "y" or "Y" or "n" or "N" then
        TextWindow.Clear()
        TextWindow.Write(check+ " was not a valid response. ")
        TextWindow.WriteLine("")
        TextWindow.WriteLine("Hit either Y/y or N/n. Try again. ")
      EndIf
    EndSub

     
    Wednesday, August 7, 2013 2:16 AM

Answers

  • If check = "n" Or "N" Then
      Goto asksource
    EndIf

    Any answer different from "n" Or "N", program would continue forward.

    Even something like "nn" would not make execution go back!

    Since you just want a single key answer from the user, why not use TextWindow.ReadKey() instead of regular TextWindow.Read()?

    Here's an enhanced version which eliminates the need to check whether a letter is capitalized or not:

    correct = Text.ConvertToUpperCase( TextWindow.Read() )
    
    If check <> "Y" Then
      Goto askSource
    EndIf


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

    • Edited by GoToLoopEditor Wednesday, August 7, 2013 4:50 AM ......
    • Marked as answer by JorgeFR Thursday, August 22, 2013 7:39 PM
    Wednesday, August 7, 2013 4:48 AM
    Answerer
  • The line:

    If  check <> "y" or "Y" or "n" or "N" then

    has a wrong syntax. After an OR you should also have a logical statement:

    If  check <> "y" or check<>"Y" or check<>"n" or check<>"N" then


    Jan [ WhTurner ] The Netherlands


    Wednesday, August 7, 2013 9:05 AM
    Answerer

All replies

  • If check = "n" Or "N" Then
      Goto asksource
    EndIf

    Any answer different from "n" Or "N", program would continue forward.

    Even something like "nn" would not make execution go back!

    Since you just want a single key answer from the user, why not use TextWindow.ReadKey() instead of regular TextWindow.Read()?

    Here's an enhanced version which eliminates the need to check whether a letter is capitalized or not:

    correct = Text.ConvertToUpperCase( TextWindow.Read() )
    
    If check <> "Y" Then
      Goto askSource
    EndIf


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

    • Edited by GoToLoopEditor Wednesday, August 7, 2013 4:50 AM ......
    • Marked as answer by JorgeFR Thursday, August 22, 2013 7:39 PM
    Wednesday, August 7, 2013 4:48 AM
    Answerer
  • The line:

    If  check <> "y" or "Y" or "n" or "N" then

    has a wrong syntax. After an OR you should also have a logical statement:

    If  check <> "y" or check<>"Y" or check<>"n" or check<>"N" then


    Jan [ WhTurner ] The Netherlands


    Wednesday, August 7, 2013 9:05 AM
    Answerer
  • To Jan,

    Thank you very much Jan.  I am just starting out how to learn how to to program in Small Basic. I didn't realize that there a need to add logical expressions to each part or the if statement. Also your idea to convert the case to all uppercase and then check for the condition is an excellent solution. I'll use that from now on.

    Again thanks very much.

    Jorge

    Thursday, August 22, 2013 7:48 PM