News:

Please note new Forum URL: forum.designcad.com

Main Menu
DesignCAD 3D Max 2027 box
Now available

DesignCAD 2027

Hatches that follow their boundaries, an on-screen dial to turn your model, and a way to find any command by name, in a clean Windows 11 look.

Choice with the INPUT function

Started by GooPie, March 14, 2015, 10:50:45 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

GooPie

Good morning or good evening,
Why the following code does not work?

SYS(996) = 1

INPUT " TEXT SIZE = ?  (1) = Size 1       (2) = Size 2       (3) = Size 3          Default value = (2)",size$
IF SYS(999) = 1 THEN END

size = size$

'size = 1
IF size = 1 then gosub SIZE1
END

'size = 2
IF size = 2 then gosub SIZE2
END

'size = 3
IF size = 3 then gosub SIZE3
END

'default value = size 2
IF size = "" then gosub SIZE2
END

'check validity of entry
IF (size < 1) or (size > 3) then gosub SIZE2
END

SIZE1:
>Text
{
  <Size 1
  <Text "Test Size 1"
  }
RETURN

SIZE2:
>Text
{
  <Size 2
  <Text "Test Size 2"
  }
RETURN

SIZE3:
>Text
{
  <Size 3
  <Text "Test Size 3"
  }
RETURN

Goopie  :-[

prl

SYS(996) = 1

INPUT " TEXT SIZE = ?  (1) = Size 1       (2) = Size 2       (3) = Size 3          Default value = (2)",size$
IF SYS(999) = 1 THEN END

size = val(size$)

'size = 1
IF size = 1 then gosub SIZE1
END

'size = 2
IF size = 2 then gosub SIZE2
END

'size = 3
IF size = 3 then gosub SIZE3
END

'default value = size 2
IF size$ = "" then gosub SIZE2
END

'check validity of entry
IF (size < 1) or (size > 3) then gosub SIZE2
END

SIZE1:
>Text
{
  <Size 1
  <Text "Test Size 1"
  }
RETURN

SIZE2:
>Text
{
  <Size 2
  <Text "Test Size 2"
  }
RETURN

SIZE3:
>Text
{
  <Size 3
  <Text "Test Size 3"
  }
RETURN

GooPie

PRL, once again thank you for your help.

It's so easy for you, I spent my afternoon without result.
Even reading the help file I did not understand, I must not be very good !!!

prl

Quote from: GooPie on March 14, 2015, 12:30:25 PM
It's so easy for you  . . .  I must not be very good !!!

You're doing great.  Don't get discouraged.  I've had more time being obsessed with BasicCAD.

GooPie

This is better and without your help.  :D  :D  :D

Window 4,15
Color 1,9
Print "                             "
Color 1,9
Print "  ( 1 )       Size 1         "
Print "                             "
Print "  ( 2 )       Size 2         "
Print "                             "
Anykey a

'(1)
if a=97 then gosub test1
if a=35 then gosub test1
if a=49 then gosub test1

'(2)
if a=98 then gosub test2
if a=40 then gosub test2
if a=50 then gosub test2

if a=27 then End

test1:
WClose
>Text
{
  <Size 1
  <Text "Test Size 1"
  }
End

test2:
WClose
>Text
{
  <Size 2
  <Text "Test Size 2"
  }
End

DrollTroll

Remember the difference between and If/Then statement all on one line, and an If/Then statement broken out into multiple lines.

In your original macro, you had

If (testcase) Then dosomething
END

Here if testcase is false, the next line is run -- so if testcase fails, the macro ends.
If on the other hand testcase is true, dosomething happens, and then the next line is run -- the macro ends.

On the other hand, if you break it up like this:

If testcase Then
  dosomething
  END
End If

the End statement only gets run if testcase is true.

Go back and re-read the TWO topics on IF statements -- IF Statement (Single Line) and If Statement (Group IF)

Cheers.

DT
25 years with DesignCAD

GooPie

DrollTroll
Thank you advice.
I will re read the TWO topics.

I still have many things to learn  :)

JJG

Quote from: GooPie on March 14, 2015, 03:18:57 PM
This is better and without your help.  :D  :D  :D
....                         "
Anykey a

'(1)
if a=97 then gosub test1
if a=35 then gosub test1
if a=49 then gosub test1

'(2)
if a=98 then gosub test2
if a=40 then gosub test2
if a=50 then gosub test2

if a=27 then End

test1:
WClose
>Text
{
  <Size 1
  <Text "Test Size 1"
  }
End

test2:
WClose
>Text
{
  <Size 2
  <Text "Test Size 2"
  }
End

In such case as you write your code above, you should use a "GOTO" stament instead of "GOSUB" :

GOSUB statement is used to transfer macro execution to another statement out of the normal sequence of execution - it calls a subroutine. The macro resumes execution on the line following the GOSUB statement when a RETURN statement is encountered. "Label" can be any valid DesignCAD macro label. A RETURN statement must be used to return from a subroutine called by a GOSUB statement. Also, don't forget to put an END statement at the end of your main routine and before your first subroutine.

GooPie

Ok thank you, it is noted.
I use DesignCad for some years now.
But it's about a month that I'm interested in BasicCad.
I'm not training, I had also never done before programming.
I test and when I see that it works, it's good for me.
But I am aware that this is not always very clean.

I just see your profile, you are French, so I will say it in French :
"Je programme certainement comme un gros bourrin"  :D :D :D