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

You are not logged in.

#1 2013-01-22 07:36:33

n872yt3r
Power Member

Offline

EndIf is If?

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

Code:

```TextWindow.WriteLine("Testing")
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 , whenever I try to group Ifs into ElseIfs, Small Basic keeps saying there is an error in the program.
Someone help!

Last edited by n872yt3r (2013-01-22 07:47:05)

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

#2 2013-01-22 09:06:33

bob bundy
Moderator

Offline

Re: EndIf is If?

hi n872yt3r

Welcome to the forum.

If test = "Testing Reply" Then

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

You cannot teach a man anything;  you can only help him find it within himself..........Galileo Galilei

#3 2013-01-22 09:21:00

n872yt3r
Power Member

Offline

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!
By the power of the exponent, I square and cube you!

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

gAr
Star Member

Offline

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."

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

n872yt3r
Power Member

Offline

Re: EndIf is If?

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

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

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

gAr
Star Member

Offline

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."

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

n872yt3r
Power Member

Offline

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!
By the power of the exponent, I square and cube you!

#8 2013-01-23 00:25:07

Agnishom
Real Member

Offline

Re: EndIf is If?

Hey n872yt3r

Code:

`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'
'Who are you to judge everything?' -Alokananda

#9 2013-01-23 00:35:17

n872yt3r
Power Member

Offline

Re: EndIf is If?

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

Code:

```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.

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

#10 2013-01-23 00:41:11

Agnishom
Real Member

Offline

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'
'Who are you to judge everything?' -Alokananda

#11 2013-01-23 00:57:07

n872yt3r
Power Member

Offline

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!
By the power of the exponent, I square and cube you!

#12 2013-01-23 01:06:15

Agnishom
Real Member

Offline

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'
'Who are you to judge everything?' -Alokananda

#13 2013-01-23 01:11:34

bobbym

Offline

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.
I have the result, but I do not yet know how to get it.
All physicists, and a good many quite respectable mathematicians are contemptuous about proof.

#14 2013-01-23 01:19:01

n872yt3r
Power Member

Offline

Re: EndIf is If?

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

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

#15 2013-01-23 01:42:45

muxdemux
Full Member

Offline

Re: EndIf is If?

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

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

n872yt3r
Power Member

Offline

Re: EndIf is If?

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

Code:

```TextWindow.WriteLine("Testing")
If test = "Testing Reply" Then
TextWindow.WriteLine("This is text.")
ElseIf
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!
By the power of the exponent, I square and cube you!

#17 2013-01-25 02:05:06

muxdemux
Full Member

Offline

Re: EndIf is If?

Code:

```ElseIf
If test2 = "Testing Reply 2" Then```

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

Code:

```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:

Code:

```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:

Code:

`ElseIf test = "Testing Reply 2" Then`

Finally, with all that thinking, we get this:

Code:

```TextWindow.WriteLine("Testing")
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-25 02:19:46)

#18 2013-01-25 08:03:22

n872yt3r
Power Member

Offline

Re: EndIf is If?

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

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