# boolean problem

• ### Question

• I experiment with a little Programm for chosing a number.

Here a small excerption:

If (val >0 And val < 11 And val <> 5) then
' action ...
EndIf

It worked well until I added for testing

Or val = 11

so the line was:

If ((val >0 And val < 11 And val <> 5) Or val = 11) then

Program should now accept 1 to 11 except  5.
SB gives me after input of 11 in TextWindow this result:

Writing to D:\users\...\temp\test.txt

In this file I find the number 11

Why this?

I checked it: This result is with all values!
Tuesday, December 30, 2008 11:35 AM

• Why not simplify it to simply

 IF (val > 0 And val <= 11 And val <> 5) THEN 'action ENDIF

• Proposed as answer by Tuesday, December 30, 2008 1:47 PM
• Marked as answer by Sunday, October 21, 2012 7:17 PM
Tuesday, December 30, 2008 1:43 PM

### All replies

• This program works good for me :

 V = TextWindow.ReadNumber() If ((V > 0 And V < 11 And V <> 5) Or V = 11) Then TextWindow.WriteLine(v) Else TextWindow.WriteLine("Bad number") EndIf

Try this code, and say me if you still encounter a problem.

Otherwhise, can you check the others part of your program ? It's possible that the error is at another place...
Fremy VB & C#
Tuesday, December 30, 2008 12:19 PM
• Why not simplify it to simply

 IF (val > 0 And val <= 11 And val <> 5) THEN 'action ENDIF

• Proposed as answer by Tuesday, December 30, 2008 1:47 PM
• Marked as answer by Sunday, October 21, 2012 7:17 PM
Tuesday, December 30, 2008 1:43 PM
• Hi Fremy,

But it doesn't work all all.

I used a program of DumpDummy and changed only the underwritten line.
Change was only a "spleeny idea" for testing not real for use.

' my sb02
' based on:

TextWindow.Title = "Test.exe"
TextWindow.Top = 434
TextWindow.Left =  0
GraphicsWindow.Title = "Test.exe"
GraphicsWindow.Width = 400
GraphicsWindow.Height = 400
GraphicsWindow.Top = 0
GraphicsWindow.Left = 0
GraphicsWindow.Show()

Beginning:
TextWindow.WriteLine("Pick a number 1 through 10") ' 3)

If ((V >0 And V < 11 And V <> 5) Or V >= 11) then
'If( Chosen = 1 Or Chosen = 2 Or Chosen = 3 )Then  'commented
GraphicsWindow.Clear()
GraphicsWindow.BrushColor = GraphicsWindow.GetRandomColor()
GraphicsWindow.FillRectangle(V*25,V*25,50,50)
Check = File.WriteContents(Program.Directory+"\Test.txt",V)
TextWindow.WriteLine("Writing to " + Program.Directory+"\Test.txt was " + Check)
Goto Beginning
Else
TextWindow.WriteLine("Try again...")
Goto Beginning
EndIf

Tuesday, December 30, 2008 1:49 PM
• Hi Dink87522

you are right!

it was a "spleeny idea" only for test.
But normaly it should work

Thanks

Horst
• Proposed as answer by Tuesday, December 30, 2008 11:00 PM
Tuesday, December 30, 2008 2:01 PM