Results 1 to 7 of 7

Thread: three questions

  1. #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. #2
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    50
    Posts
    8,197
    Blog Entries
    2
    Rep Power
    10

    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
    www.thinbasic.com | www.thinbasic.com/community/ | psch.thinbasic.com
    Win10Pro 64bit - 8GB Ram - Intel i7 M620 2.67GHz - NVIDIA Quadro FX1800M 1GB

  3. #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
    Attached Files Attached Files

  4. #4
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    50
    Posts
    8,197
    Blog Entries
    2
    Rep Power
    10

    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
    www.thinbasic.com | www.thinbasic.com/community/ | psch.thinbasic.com
    Win10Pro 64bit - 8GB Ram - Intel i7 M620 2.67GHz - NVIDIA Quadro FX1800M 1GB

  5. #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]
    (Sorry about my bad English.)

  6. #6
    Senior Member Lionheart008's Avatar
    Join Date
    Sep 2008
    Location
    Germany, Bad Sooden-Allendorf
    Age
    45
    Posts
    914
    Rep Power
    101

    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
    Attached Files Attached Files
    you can't always get what you want, but if you try sometimes you might find, you get what you need

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

Similar Threads

  1. A few more questions..
    By oldpapa49 in forum thinBasic General
    Replies: 12
    Last Post: 21-03-2009, 21:45
  2. DT questions
    By Dave in forum DT (Date module)
    Replies: 9
    Last Post: 16-04-2008, 09:48

Posting Permissions

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