Results 1 to 7 of 7

Thread: Sub/Function-Optional-parameters

  1. #1
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    54
    Posts
    1,530
    Rep Power
    171

    Sub/Function-Optional-parameters

    the help-file does not tell me, but I want to know what happens with Optional arguments?

    can I set some default value to missing optional arguments somehow?
    Last edited by ReneMiner; 30-10-2012 at 00:54.
    I think there are missing some Forum-sections as beta-testing and support

  2. #2
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10
    Yes it is possible but only in a limited way: only numeric parameters and only if passed BYVAL

    http://www.thinbasic.com/public/prod...ameter_val.htm
    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

  3. #3
    Member REDEBOLT's Avatar
    Join Date
    Dec 2006
    Location
    Pickerington, Ohio, USA
    Age
    87
    Posts
    62
    Rep Power
    24
    In looking at the supplied example, I see that

    MyFunction(,)

    has two missing arguments, so it would be

    MyFunction(p1,p2).

    But the printed result shows

    100 100 -1 0.

    Since p1 = 100, and p2 = 200, I think the result should be

    100 200 -1 0.

    Where have I gone wrong?

    Regards
    Bob

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

    right you are.
    I will open an issiue in Support.

    http://www.thinbasic.com/community/p...hp?issueid=366
    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

  5. #5
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10
    Fixed, will be present in next 1.9.x beta update
    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

  6. #6
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    54
    Posts
    1,530
    Rep Power
    171
    Two things:

    1. I'm not sure about and want to know:

    Sub A(Optional X , Y)
    
    Sub B(Optional X, Optional Y)
    
    is there a difference? Is B valid?

    2. By searching help for Optional I found in
    Navigation: thinBasic language > Script structure >Functions/Subs

    an example:
    Function  Factorial(InVal AsNumber)  As Number
     Dim Count  AsLong
     Dim RetVal  AsLong
     
      RetVal = 1
     For Count =  2 To InVal
         RetVal = RetVal * i
     Next
     
     Function =  RetVal
     
     End Function
    

    where does i in line 7 come from ?
    Last edited by ReneMiner; 13-06-2013 at 11:39.
    I think there are missing some Forum-sections as beta-testing and support

  7. #7
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10
    1. both are valid, thinBasic has some ... flexibility
      "Optional" is considered just a marker: from the first "optional" param, all subsequent parameters will be automatically "optional"
      But remember: not defined variable types are interpreted as VARIANT type. If you debug this little example you will see it.
      Uses "Console"
      
      Sub A(Optional X , Y)
        PrintL Function_Name, x, y
      End Sub
      
      
       
      Sub B(Optional X, Optional Y)
        PrintL Function_Name, x, y
      End Sub
      
      
      a(1,2)
      b(3,4)
      WaitKey
      
    2. My error, fixed. Variable "I" is instead "Count"


    Thanks
    Eros
    Last edited by ErosOlmi; 16-06-2013 at 11:29.
    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

Similar Threads

  1. KeywordDocumenter, optional tool to document module keywords
    By Petr Schreiber in forum thinBasic SDK
    Replies: 6
    Last Post: 27-02-2011, 23:10
  2. How to parse multiple optional parameters?
    By Michael Hartlef in forum Module SDK (Power Basic version)
    Replies: 7
    Last Post: 17-03-2008, 18:36
  3. Default values for function parameters
    By ErosOlmi in forum thinBasic vaporware
    Replies: 2
    Last Post: 19-06-2007, 10:20

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
  •