Math Is Fun Forum

  Discussion about math, puzzles, games and fun.   Useful symbols: ÷ × ½ √ ∞ ≠ ≤ ≥ ≈ ⇒ ± ∈ Δ θ ∴ ∑ ∫ • π ƒ -¹ ² ³ °

You are not logged in.

#1 2013-01-21 08:36:33

n872yt3r
Member
Registered: 2013-01-21
Posts: 392

EndIf is If?

Someone help me! dunno This glitch keeps bothering me... Ugh! Every time I encounter it, yikes what swear down
In Microsoft Small Basic (here is just a simple example,)

TextWindow.WriteLine("Testing")
test = TextWindow.Read()
If test = "Testing Reply" Then
  TextWindow.WriteLine("This is text.")
Else
  TextWindow.WriteLine("Sorry, this operation did not perform correctly.")
EndIf

it always displays the Else even when I type in "Testing Reply."
And also what, whenever I try to group Ifs into ElseIfs, Small Basic keeps saying there is an error in the program. down
Someone help!

Last edited by n872yt3r (2013-01-21 08:47:05)


- n872yt3r
Math Is Fun Rocks! smile
By the power of the exponent, I square and cube you! cool

Offline

#2 2013-01-21 10:06:33

Bob
Administrator
Registered: 2010-06-20
Posts: 10,621

Re: EndIf is If?

hi n872yt3r

Welcome to the forum.

If test = "Testing Reply" Then

"Testing Reply."

If that is literal then they aren't the same.  The input has a full stop.

Sometimes little things can keep you guesing for a long time.

I had a tester who occasionally hit the caps lock and I'd only allowed for small letters in my program.

If that's not it, try a variable dump.

Bob


Children are not defined by school ...........The Fonz
You cannot teach a man anything;  you can only help him find it within himself..........Galileo Galilei
Sometimes I deliberately make mistakes, just to test you!  …………….Bob smile

Offline

#3 2013-01-21 10:21:00

n872yt3r
Member
Registered: 2013-01-21
Posts: 392

Re: EndIf is If?

No, the period was marked as the end of a sentence. Anyway, that was just an example, if I do it in real time and enter it exactly correctly, so yeah, it's got to be a variable dump.


- n872yt3r
Math Is Fun Rocks! smile
By the power of the exponent, I square and cube you! cool

Offline

#4 2013-01-22 00:09:41

gAr
Member
Registered: 2011-01-09
Posts: 3,482

Re: EndIf is If?

Hi,

Maybe it's taking \n character as well, strip your input of "\n" and try again.


"Believe nothing, no matter where you read it, or who said it, no matter if I have said it, unless it agrees with your own reason and your own common sense"  - Buddha?

"Data! Data! Data!" he cried impatiently. "I can't make bricks without clay."

Offline

#5 2013-01-22 00:26:01

n872yt3r
Member
Registered: 2013-01-21
Posts: 392

Re: EndIf is If?

\n? I don't see \n. Maybe your browser uses Latex differently... sad Do you guys use Small Basic? smile I learned it over the summer.


- n872yt3r
Math Is Fun Rocks! smile
By the power of the exponent, I square and cube you! cool

Offline

#6 2013-01-22 00:29:09

gAr
Member
Registered: 2011-01-09
Posts: 3,482

Re: EndIf is If?

Hi,

I was talking about "newline character", you can't see that on the screen..


"Believe nothing, no matter where you read it, or who said it, no matter if I have said it, unless it agrees with your own reason and your own common sense"  - Buddha?

"Data! Data! Data!" he cried impatiently. "I can't make bricks without clay."

Offline

#7 2013-01-22 00:58:15

n872yt3r
Member
Registered: 2013-01-21
Posts: 392

Re: EndIf is If?

I never recall posting a "newline character," I copied it right off my Microsoft Small Basic program.


- n872yt3r
Math Is Fun Rocks! smile
By the power of the exponent, I square and cube you! cool

Offline

#8 2013-01-22 01:25:07

Agnishom
Real Member
From: Riemann Sphere
Registered: 2011-01-29
Posts: 24,996
Website

Re: EndIf is If?

Hey n872yt3r
Use the following line instead

If test == "Testing Reply" Then

Put two equal signs there


'And fun? If maths is fun, then getting a tooth extraction is fun. A viral infection is fun. Rabies shots are fun.'
'God exists because Mathematics is consistent, and the devil exists because we cannot prove it'
I'm not crazy, my mother had me tested.

Offline

#9 2013-01-22 01:35:17

n872yt3r
Member
Registered: 2013-01-21
Posts: 392

Re: EndIf is If?

2 = signs? According to Microsoft Small Basic Curriculum Lesson 1.4, (here is just an example:) you can do

If Clock.Day = 1 And Clock.Month = 1 Then
  TextWindow.WriteLine("Happy New Year!")
EndIf

'Ya see? Clock.Day = 1 and Month = 1. 1 equals sign. neutral


- n872yt3r
Math Is Fun Rocks! smile
By the power of the exponent, I square and cube you! cool

Offline

#10 2013-01-22 01:41:11

Agnishom
Real Member
From: Riemann Sphere
Registered: 2011-01-29
Posts: 24,996
Website

Re: EndIf is If?

Try 2 = signs anyway


'And fun? If maths is fun, then getting a tooth extraction is fun. A viral infection is fun. Rabies shots are fun.'
'God exists because Mathematics is consistent, and the devil exists because we cannot prove it'
I'm not crazy, my mother had me tested.

Offline

#11 2013-01-22 01:57:07

n872yt3r
Member
Registered: 2013-01-21
Posts: 392

Re: EndIf is If?

I'll try it, but the Microsoft Small Basic Curriculum were downloaded directly from the Microsoft official website.


- n872yt3r
Math Is Fun Rocks! smile
By the power of the exponent, I square and cube you! cool

Offline

#12 2013-01-22 02:06:15

Agnishom
Real Member
From: Riemann Sphere
Registered: 2011-01-29
Posts: 24,996
Website

Re: EndIf is If?

Have you understood what gAr said?


'And fun? If maths is fun, then getting a tooth extraction is fun. A viral infection is fun. Rabies shots are fun.'
'God exists because Mathematics is consistent, and the devil exists because we cannot prove it'
I'm not crazy, my mother had me tested.

Offline

#13 2013-01-22 02:11:34

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

Re: EndIf is If?

Hi;

If you downloaded it exactly from Microsoft then you should email them if the code does not work.

Have you tried changing line 3 to If test = "ok" Then

Or even shorter

If test = "k" Then


In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

#14 2013-01-22 02:19:01

n872yt3r
Member
Registered: 2013-01-21
Posts: 392

Re: EndIf is If?

C'mon, it was just an example. As I said, look at post #3.


- n872yt3r
Math Is Fun Rocks! smile
By the power of the exponent, I square and cube you! cool

Offline

#15 2013-01-22 02:42:45

muxdemux
Member
Registered: 2012-12-23
Posts: 80

Re: EndIf is If?

Works fine over here. Your problem could be that you're entering "testing reply" instead of "Testing Reply".

Can you post some of your code involving ElseIf's?

Offline

#16 2013-01-24 00:04:28

n872yt3r
Member
Registered: 2013-01-21
Posts: 392

Re: EndIf is If?

ElseIfs... Sure! It was like this...

TextWindow.WriteLine("Testing")
test = TextWindow.Read()
If test = "Testing Reply" Then
  TextWindow.WriteLine("This is text.")
ElseIf
test2 = TextWindow.Read()
If test2 = "Testing Reply 2" Then
  TextWindow.WriteLine("This is also text.")
Else
  TextWindow.WriteLine("Sorry, this operation did not perform correctly.")
EndIf

And it never works!


- n872yt3r
Math Is Fun Rocks! smile
By the power of the exponent, I square and cube you! cool

Offline

#17 2013-01-24 03:05:06

muxdemux
Member
Registered: 2012-12-23
Posts: 80

Re: EndIf is If?

Here's your main problem:

ElseIf
test2 = TextWindow.Read()
If test2 = "Testing Reply 2" Then

You need to put your test on the same line as the 'ElseIf' like this:

ElseIf test2 = TextWindow.Read()
If test2 = "Testing Reply 2" Then

And immediately after the test, Small Basic is expecting a "Then," just like with the if statements:

ElseIf test2 = TextWindow.Read() Then
If test2 = "Testing Reply 2" Then

Also, you can't test if TextWindow.Read() is equal to the variable 'test2' because you haven't set it to anything yet. But you already set the "test" variable to TextWindow.Read() on the second line of your program. What I think you meant to do is something like this:

ElseIf test = "Testing Reply 2" Then

Finally, with all that thinking, we get this:

TextWindow.WriteLine("Testing")
test = TextWindow.Read()
If test = "Testing Reply" Then
	TextWindow.WriteLine("This is text.")
ElseIf test = "Testing Reply 2" Then
	TextWindow.WriteLine("This is also text.")
Else
	TextWindow.WriteLine("Sorry, this operation did not perform correctly.")
EndIf

Line by line, the program says this:
1. Show the user "Testing" (print it out on the screen).
2. Set the variable "test" to whatever the user types.
3. Check if the "test" variable is equal to "Testing Reply" (without quotes). If it is, go to step 4, otherwise go to step 5.
4. Show the user "This is text." (Without quotes, of course!) Then go to step 8.
5. Check if the "test" variable is equal to "Testing Reply 2" (without quotes). If it is, go to step 6, otherwise go to step 7.
6. Show the user "This is also text." Then go to step 8.
7. Show the user "Sorry, this operation did not perform correctly." Then go to step 8.
8. This is the "EndIf." It pretty much says "quit asking all these 'if' questions!"

Last edited by muxdemux (2013-01-24 03:19:46)

Offline

#18 2013-01-24 09:03:22

n872yt3r
Member
Registered: 2013-01-21
Posts: 392

Re: EndIf is If?

I didn't get that last part; but thanks for the explanation on ElseIfs.


- n872yt3r
Math Is Fun Rocks! smile
By the power of the exponent, I square and cube you! cool

Offline

Board footer

Powered by FluxBB