# Thread: three questions

1. ## three questions

one more question to math things with thinbasic.

[code=thinbasic]' Empty GUI script created on 03-09-2010 10:22:46 by denis (ThinAIR)

Uses "console", "math"

MsgBox 0, "my multiply result: " + mymath()

Function mymath() As Long
Dim a,b,c As Long
Dim pival As Integer

a = 5
b = 6
c = a*b

PrintL a + b

PrintL Sin(a)
'PrintL Pi(b) '-- doesn't work, why ?

PiVal = 4 * Atn(1)
PrintL "my pival result: " + pival

PrintL Log(b)
'PrintL c-a ' c(-a) '-- doesn't work, why ?
'Printl a + mymath() '--- works, but fast list cannot stop to see

Function = c

End Function

WaitKey[/code]

my questions I named in code example

denis

2. ## Re: three questions

Post moved to General forum because this in an inquiry and not a code/snipet

• [@]pi is a reserved keyword of MATH module: http://www.thinbasic.com/public/prod...lp/html/pi.htm
[@]PrintL accept strings as parameters and not numeric calculations so if you want make a calculation just use a formatting function like PrintL Format\$(c - a)
[@]with "PrintL a + mymath()" you are recursively calling your function without an exit strategy. Are you sure about your code?
[@]to slow down your application, enter something like SLEEP [milliseconds] where [milliseconds] is the time the script has to stop

Eros

3. ## Re: three questions

thanks eros

a) does it mean I cannot calculate "PI" with different values ? (sorry)
(for example: pi*180/r)

b) how would this new example looks like with increase "mymath() function" and stop it at number I = 50 for exit ? I cannot manage. (sorry again) It's possible to increase a function? I don't think so. Was just an idea.

c) printl format\$(c-a): good! I have saved in my mind, thanks!

with "PrintL a + mymath()" you are recursively calling your function without an exit strategy. Are you sure about your code?
no, I am no more sure about that

[code=thinbasic]
' Empty GUI script created on 03-09-2010 10:22:46 by denis (ThinAIR)

Uses "console", "math"

MsgBox 0, "my multiply result: " + mymath()

Function mymath() As Long
Dim a,b,c As Long
Dim pival As Integer
Dim counter As Long

a = 5
b = 6
c = a*b

PrintL Format\$(c + b)

PrintL Sin(a)
MsgBox 0," this is cos(a) result: " + Cos(a),%MB_OK, "pi " + Pi

PiVal = 4 * Atn(1)
PrintL "my pival result: " + pival

PrintL Log(b)
PrintL Format\$(c-a)
counter += 1

Sleep 1000
Incr counter

PrintL a + counter '+ mymath() --- works, but fast list cannot Stop To see
If counter = 30 Then Exit Function

PrintL counter

Function = c

End Function

WaitKey
[/code]

bye, thanks, denis

4. ## Re: three questions

• yes you can pi*180/r but not Pi(b) like in your first example. What is Pi(b)?
• If you have a recursive function you must have an exit test otherwise you will enter into a loop and after a while a possible GPF or overflow. So what is your exit test here?
If your exit test is "If counter = 30 Then Exit Function"
you will never get that line of code because recursion is the line before it.

Solution?
Change
DIM counter As Long
to
Global counter As Long

and invert line
PrintL a + mymath()
with line
If counter = 30 Then Exit Function

Also note you are increasing Counter twice

Eros

5. ## Re: three questions

hello chris, (christianssen)
what are you trying ?
i don't understand whats going on in your code

Joshy
[code=thinbasic]' Empty ThinBASIC CONSOLE file template

Uses "Console"

Uses "console", "math"

MsgBox 0, "my multiply result: " + mymath()

Function mymath() As Long
Dim a,b,c,r As Long
Dim pival As Long
Dim counter As Long

a = 5
b = 6
c = a*b
r = c+b
PrintL "c+b = " + r

PrintL "sin(a) = " + Sin(a)
r= Cos(a) + Pi
PrintL " this is cos(a)+pi = " + r

PiVal = 4 * Atn(1)
PrintL "my pival result: " + pival

PrintL Log(b)
r=c-a
PrintL " c-a" = r
counter += 1

Sleep 1000
Incr counter
r=a+ counter + mymath()
PrintL "a + counter + mymath() =" r
If counter = 30 Then Exit Function

PrintL "counter=" + counter

Function = c

End Function

WaitKey
[/code]

6. ## Re: three questions

hi denis, hi joshy, hi eros.

@denis:

if you use your first example with some function like "printl a + math()" you will get no exit for your function, neither for "counter = 30" nor "counter = 5". I have tested such similar things with functions and value increases some weeks before.
but with a loop (this I would prefer to do) you can have a serious exit if you want. don't know what's your intention? to combine a mathematical function with a loop, increasing values for what ? I don't know that. I can suggest this kind of tb example:

[code=thinbasic]
' Empty GUI script created on 03-09-2010 10:22:46 by denis (ThinAIR)
' franks modification with loop and exit

Uses "console", "math"

Global counter As Long

PrintL

MsgBox 0, "my multiply result: " + mymath()

Function mymath() As Long
Dim a,b,c,d,i As Long
Dim pival As Integer
Dim counter As Long

a = 5
b = 6
c = a*b
d = Sin(a)

PrintL Format\$(c + b)

PrintL "sin(a) is: " + d
Sleep 1000

MsgBox 0," this is cos(a) result: " + Cos(a),%MB_OK, "pi " + Pi

PiVal = 4 * Atn(1)
PrintL "my pival result: " + pival

PrintL Log(b)
PrintL Format\$(c-a)
counter = 0
Do
Incr counter

Sleep 500
Console_WriteLine ("-- my counter :"+Str\$(counter))
'PrintL

Function = c
Loop Until counter = 10 '----- Then Exit Do

PrintL

Sleep 100
'PrintL "mymath result: " + mymath()

End Function
PrintL
PrintL "again: mymath result: " + mymath()
PrintL
PrintL "pi(b) is sometimes one piece biscuit (b) cut off the pastry ?"
PrintL

WaitKey

[/code]

2) if you activate "PrintL "mymath result: " + mymath() " before end function you will have the same dilemma that this function will never end and exit you can test it.

eros has mentioned it already above:
If you have a recursive function you must have an exit test otherwise you will enter into a loop and after a while a possible GPF or overflow. So what is your exit test here?
thanks for your little example, frank

7. ## Re: three questions

thanks joshy, eros, frank for help.

think about best example for my idea was today with loop exit. because I am new with console modus I didn't see I cannot break the "PrintL "a + counter + mymath() " function for exit. that's new for me. sorry for unserious question or I didn't explain it clear. thanks to all for help! learning day by day one little cake of thinbasic

denis

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•