none
Small Basic Or problem RRS feed

  • Question

  • So here is the code

    TextWindow

    .WriteLine("Hello")


    TextWindow

    .WriteLine("Please type your age.")


    age = TextWindow.Read()


    If

    age < 18 Then


        TextWindow.Write("YOU ARE TOO YOUNG")


        TextWindow.PauseWithoutMessage()


        Program.End()


    ElseIf

    age > 18 Then

      TextWindow.BackgroundColor = ("Red")


      TextWindow.ForegroundColor = ("Black")


      TextWindow.Title = ("Batch File Maker")


      TextWindow.WriteLine("Congratulations!")


    Else


      Program.End()


    EndIf


    TextWindow

    .Clear()


    TextWindow

    .WriteLine("What would you like to do?")


    Sound

    .PlayMusic("E8 E8 F8 F8 E8 E8 G8 G8 E8 E8")


    TextWindow

    .WriteLine("A) Shutdown")


    TextWindow

    .WriteLine("B) Overload")


    TextWindow

    .WriteLine("C) Delete C:\")


    If

    TextWindow.Read() = "A" Or "a" Then


      TextWindow.WriteLine("Shutdown.bat")


      File.CreateDirectory("C:\Batch\Shutdown")


      File.WriteContents("C:\Batch\Shutdown\Shutdown.bat", "@echo off shutdown -i" )


    ElseIf

    TextWindow.Read() = "B" or "b" then


      File.CreateDirectory("C:\Batch\Overload")


      File.WriteContents("C:\Batch\Overload\overload.bat","@echo off :1 Start Goto 1")


      EndIf

    So the problem lies here

    TextWindow.Read() = "A" Or "a" Then

    The uppercase A works fine, but when i try to hit the lowercase it acts if i said hit enter to go down a line... then i do it again and it says

    the press any button to continue and exits without making the download... I am 99.9% sure that it is correct and consulted with another expert and he has not used Small Basic, rather used first basic language any suggestions would be really appreciated

    Saturday, July 7, 2012 2:57 AM

Answers

  • Hey Dakota0121!

    Sorry to tell you, but: If TextWindow.Read() = "A" Or "a" Then is doubly wrong!

    Let me explain why:

    Generally Or & And logical operators are used to establish a logic check between pairs like:

    If a = 10 Or a = 20 Then... : Pair 1 -> a=10; Pair 2 -> a=20

    If a < -4 And b > 5 Then... : Pair 1 -> a<-4; Pair 2 -> b>5

    In your case we have: Pair 1 -> TextWindow.Read() = "A"; Pair 2? -> "a" (it's not a pair! :P)

    Theoretically it shoulda been: If TextWindow.Read() = "A" Or TextWindow.Read() = "a" Then

    But then we got another big problem:
    Each TextWindow.Read() would re-ask the user to type again!!! And the user coulda typed something different for each of those!

    The sane thing to do is to have just 1 TextWindow.Read() and use a variable to store what was entered. Like Input = TextWindow.Read(), for example.
    Then use that variable in our If code blocks.

    But there's even a neater way to do it:
    Input = Text.ConvertToLowerCase( TextWindow.ReadKey() )

    TextWindow.ReadKey() -> reads just 1 key from user
    Text.ConvertToLowerCase -> converts to lowercase, so we only need to test for "a", "b" or "c", and skip "A", "B" and "C".  :D

    Laterz!

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

    Saturday, July 7, 2012 3:44 AM
    Answerer
  • In a condition, you compare two different expressions.
    So in your condition:
    If TextWindow.Read() = "A" Or "a" Then

    you have one expression:
    TextWindow.Read() = "A"

    and then another "thing" that isn't an expression:
    "a"


    To fix this problem, you need to make your "a" into an expression:
    If TextWindow.Read() = "A" or TextWindow.Read() = "a" Then

    Except…

    You can't have two TextWindow.Read() methods.

    Fix:

    read = TextWindow.Read()
    If read = "A" or read = "a" Then


    Or, you can solve this with a single expression:
    If Text.toLower( TextWindow.Read() ) = "a" Then


    ~~AirWaves!!~~

    Wednesday, July 11, 2012 7:55 AM

All replies

  • Hey Dakota0121!

    Sorry to tell you, but: If TextWindow.Read() = "A" Or "a" Then is doubly wrong!

    Let me explain why:

    Generally Or & And logical operators are used to establish a logic check between pairs like:

    If a = 10 Or a = 20 Then... : Pair 1 -> a=10; Pair 2 -> a=20

    If a < -4 And b > 5 Then... : Pair 1 -> a<-4; Pair 2 -> b>5

    In your case we have: Pair 1 -> TextWindow.Read() = "A"; Pair 2? -> "a" (it's not a pair! :P)

    Theoretically it shoulda been: If TextWindow.Read() = "A" Or TextWindow.Read() = "a" Then

    But then we got another big problem:
    Each TextWindow.Read() would re-ask the user to type again!!! And the user coulda typed something different for each of those!

    The sane thing to do is to have just 1 TextWindow.Read() and use a variable to store what was entered. Like Input = TextWindow.Read(), for example.
    Then use that variable in our If code blocks.

    But there's even a neater way to do it:
    Input = Text.ConvertToLowerCase( TextWindow.ReadKey() )

    TextWindow.ReadKey() -> reads just 1 key from user
    Text.ConvertToLowerCase -> converts to lowercase, so we only need to test for "a", "b" or "c", and skip "A", "B" and "C".  :D

    Laterz!

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

    Saturday, July 7, 2012 3:44 AM
    Answerer
  • In a condition, you compare two different expressions.
    So in your condition:
    If TextWindow.Read() = "A" Or "a" Then

    you have one expression:
    TextWindow.Read() = "A"

    and then another "thing" that isn't an expression:
    "a"


    To fix this problem, you need to make your "a" into an expression:
    If TextWindow.Read() = "A" or TextWindow.Read() = "a" Then

    Except…

    You can't have two TextWindow.Read() methods.

    Fix:

    read = TextWindow.Read()
    If read = "A" or read = "a" Then


    Or, you can solve this with a single expression:
    If Text.toLower( TextWindow.Read() ) = "a" Then


    ~~AirWaves!!~~

    Wednesday, July 11, 2012 7:55 AM