Results 1 to 8 of 8

Thread: call statement

  1. #1

    call statement

    for next thinbasic issue
    I don't understand the meaning of "call" function. why you can't call up a simple function with "call" statement ?
    bye, tom

  2. #2

    Re: call statement

    Can you please explain your issue? Call works fine for me.

  3. #3
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10

    Re: call statement

    CALL is mainly used when you want to call a function whose name is not know and can change at runtime.
    You can compute the name of the function as a string expression and ask thinBasic to search for that function name and call it.

    What is not working for you or what you was expecting from CALL?
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  4. #4
    Senior Member Lionheart008's Avatar
    Join Date
    Sep 2008
    Location
    Germany, Bad Sooden-Allendorf
    Age
    51
    Posts
    934
    Rep Power
    109

    Re: call statement

    hi tom, perhaps this little "call" example can help ?

    [code=thinbasic]' Empty GUI script created on 08-17-2010 17:43:44 by (ThinAIR)

    Uses "console"

    Dim str As String

    PrintL "Usual 'print' message"
    str = PrintAndReturnLine("this is a teststring with " + _
    Chr$(13) + Chr$(10) + "Breaking the lines")
    Call PrintAndReturnLine "Line: " & Str$(str)
    PrintAndReturnLine "this is working fine too "

    Function PrintAndReturnLine (ByVal Texts As String) As Integer
    PrintL Texts
    Function = 1
    End Function

    MsgBox 0, "little 'call' test ok for you?"

    WaitKey

    [/code]

    bye, 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

  5. #5

    Re: call statement

    thanks for replies, michael, eros and frank for example

    I was last week on that trip to understand ...

    [code=thinbasic]' Empty GUI script created on 08-17-2010 11:10:44 by (ThinAIR)

    Uses "console"

    Dim myvary As Long
    Dim vary1, vary2, vary3 As Long

    If myvary = 1 Then
    MyCalc_A(vary1, vary2, vary3)
    Else
    MyCalc_B(vary1, vary2, vary3)
    Else
    MyCalc_C(vary1, vary2, vary3)
    End If

    Function MyCalc_A( ByVal x As Long, ByVal y As Long, ByVal z As Long ) As Long
    x = 200
    y = 150
    Function = x + y
    End Function

    Function MyCalc_B( ByVal a As Long, ByVal b As Long, ByVal c As String ) As String
    a = 100
    b = 50
    c = "hello summertime"

    Function = c
    End Function

    Function MyCalc_C( ByVal a As Long, ByVal b As Long, ByVal c As Long ) As Long
    a = 100
    b = 50
    Function = a - b
    End Function

    Call "MyCalc_" & IIf$(myvary = 1, "A", "B") (vary1, vary2, vary3)

    PrintL myCalc_A(1,1,1)
    PrintL myCalc_B(1,1,"y")
    PrintL myCalc_c(1,1,1)

    MsgBox 0, "test 1 ok? " + myCalc_A(1,1,1)
    MsgBox 0, "test 2 'string' ok? " + myCalc_B(1,1,"y")
    MsgBox 0, "test 3 ok? " + myCalc_C(1,1,1)

    WaitKey[/code]

    now it`s more clear to understand call statement. Have found another examples at the board and on help manual. thought it was easy to call up function only with one parameter behind command call. my mistake. sorry.

    for eros:

    You can compute the name of the function as a string expression and ask thinBasic to search for that function name and call it.
    do you have any other example for me ?

    thanks for help! , bye, tom

  6. #6

    Re: call statement

    Hi Tom,

    http://community.thinbasic.com/index.php?topic=1598.0

    here I show how to calculate the function name and call it.

    Cheers
    Michael

  7. #7
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732

    Re: call statement

    Tom,

    there are 2 examples on CALL in the help file, just write CALL to thinAir, move cursor to it and hit F1.

    Here is one more example to demonstrate the use:
    [code=thinbasic]
    Dim sFunctionNameFromUser As String
    Dim sFunctions As String

    ' -- Get names of functions in script
    sFunctions = Function_Names(%FUNCTION_USER, $CRLF)

    ' -- Offer the user to call them
    sFunctionNameFromUser = InputBox$("Please enter name of function you want to execute:"+$CRLF(2)+sFunctions, "Request", "FUNCTION_A")

    If Function_Exists(sFunctionNameFromUser) = %FALSE Then
    MsgBox 0, "There is no function "+sFunctionNameFromUser
    Else
    ' -- Function name is in string, and CALL statement will execute it
    ' -- So it does not call function named "sFunctionNameFromUser", but the one you entered, such as Function_A, ...
    Call sFunctionNameFromUser()
    End If

    Function Function_A()
    MsgBox 0, "I am in function A, which does ... not much"
    End Function

    Function Function_B()
    MsgBox 0, "I am in function B, as you wanted"
    End Function

    Function Function_C()
    MsgBox 0, "I am in function C, last here "
    End Function
    [/code]

    And here another one:
    [code=thinbasic]
    ' Use File module for handling files
    uses "FILE"

    function TBMain()
    ' Assign file name to variable, notice assignment can be done at time of declaring variable
    local MyFile as string = "c:\File.txt"
    local ReturnValue as long

    ' Functions are named Load_<fileExtension>, so we can determine
    ' the function name we need at run time and save some lines of code
    call "Load_"+FILE_PATHSPLIT(MyFile, %Path_Ext) ( MyFile ) To ReturnValue

    end function

    function Load_TXT( fName as string ) as long

    ' Code to load TXT file here
    MSGBOX 0, "Loading TXT"

    end function

    function Load_BMP( fName as string ) as long

    ' Code to load BMP file here
    MSGBOX 0, "Loading BMP"

    end function
    [/code]


    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  8. #8
    thinBasic MVPs
    Join Date
    May 2007
    Location
    UK
    Posts
    1,427
    Rep Power
    159

    Re: call statement

    Here is an example using a table of routines

    http://community.thinbasic.com/index.php?topic=1405.0
    Home Desktop : Windows 7 - Intel Pentium (D) - 3.0 Ghz - 2GB - Geforce 6800GS
    Home Laptop : WinXP Pro SP3 - Intel Centrino Duo - 1.73 Ghz - 2 GB - Intel GMA 950
    Home Laptop : Windows 10 - Intel(R) Core(TM) i5-4210U CPU @ 1.70GHz, 2401 Mhz, 2 Core(s), 4 Logical Processor(s) - 4 GB - Intel HD 4400
    Work Desktop : Windows 10 - Intel I7 - 4 Ghz - 8GB - Quadro Fx 370

Similar Threads

  1. PCT statement
    By Petr Schreiber in forum Fixed or cleared errors in help material
    Replies: 1
    Last Post: 11-09-2005, 17:10

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

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