Announcement

Collapse
No announcement yet.

Declare Function Parameter as ANY

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Declare Function Parameter as ANY

    Code:
    #COMPILE EXE
    #DIM ALL
    #INCLUDE "Win32Api.inc"
    DECLARE FUNCTION TestFunction(TestVariable AS ANY) AS LONG
    
    FUNCTION PBMAIN () AS LONG
         LOCAL MyVariable AS STRING
         MyVariable = " Hello"
         TestFunction MyVariable
        
    
    END FUNCTION
    
    FUNCTION TestFunction(TestVariable AS ANY) AS LONG
         MSGBOX TestVariable
    END FUNCTION
    Ok what the heck am I doing wrong? I can declare the function but as soon as I try to use it, I get an "Undefined TYPE"
    If I change "TestVariable" to AS STRING in the function I get a type mismatch. (Which is correct)

    Now why can I have AS ANY in Win32Api.inc, but not AS ANY in my own code?????

    I am missing something here that must be fundamental
    Engineer's Motto: If it aint broke take it apart and fix it

    "If at 1st you don't succeed... call it version 1.0"

    "Half of Programming is coding"....."The other 90% is DEBUGGING"

    "Document my code????" .... "WHYYY??? do you think they call it CODE? "

  • #2
    You cannot compile a procedure which is using an undefined data type ("ANY" is undefined in your program).

    "ANY" in a DECLARE has a special meaning. See help.

    Besides, "FUNCTION TestFunction(var as ANY)" cannot make sense. Look at your own code: how could the function know that "TestVariable" is a datatype compatible with the first argument to the MSGBOX function" (Hint: it can't).
    Michael Mattias
    Tal Systems Inc. (retired)
    Racine WI USA
    [email protected]
    http://www.talsystems.com

    Comment


    • #3
      There have been numerous postings here on "writing a function which services any data type". The two solutions which make sense are...

      1. Pass a VARIANT and use VARIANTVT to interrogate the data type
      2. Pass a one-element array and use ARRAYATTR to interrogate the data type
      Michael Mattias
      Tal Systems Inc. (retired)
      Racine WI USA
      [email protected]
      http://www.talsystems.com

      Comment


      • #4
        Although a search of these forums for "as any" likely will produce an error and give you nothing, try searching Poffs for it. A search of the exact match in the subject gives an immediate response while 'entire message' likely gives lots of hits that are useless for your purposes (because any comment including the words 'as any' would be included as well as the usefull messages).
        Last edited by Fred Buffington; 17 Jul 2009, 09:12 PM.
        Client Writeup for the CPA

        buffs.proboards2.com

        Links Page

        Comment


        • #5
          "ANY" in a DECLARE has a special meaning. See help.
          I saw that in the Help, and thats what got me thinking that in a situation I have (still working on it) that if I do not know the datatype until runtime then maybe I can say "Hey give me anything, and I will figure it out and pass back the correct answer)

          Hence my sample declared "AS ANY" (its in the Win32API.inc" with no problems, and the docs say declaring "AS ANY" disables the checking as to what the variable type is.

          In this case, I would not care if it were a Byte, Long, Currency, String, Fixed String, AsciiZ or Apples or Oranges......it would ALLLLLLLllll be one function and let my function sort it out (as best it can)

          I have more :coffee: researching to do, but I think my confusion is that Win32Api.inc declares of AS ANY, really has noimplementation of the function (just that it is declared for later use), ANNNNNND each declare is in a DLL (not my own module) so the rules may be different? (Not sure how to explain since I am still learning)

          Some of the research I am doing and MCM did mention was
          There have been numerous postings here on "writing a function which services any data type". The two solutions which make sense are...

          1. Pass a VARIANT and use VARIANTVT to interrogate the data type
          2. Pass a one-element array and use ARRAYATTR to interrogate the data type
          Hey wait a sec....did I NOT work on Find that Datatype a while back???
          Yep you bet I did....(but I had to search my own name directed at the Source Code forums to find it, and wouldnt you know it, from my comments, I guess I got the idea from MCM??? )

          Well I guess I am back to researching if code posted for another purpose may be further developed to serve a new purpose????

          (Good part is...its my own code, so maybe I can pick up on the train of thought faster than I normally would???) :laugh:
          Engineer's Motto: If it aint broke take it apart and fix it

          "If at 1st you don't succeed... call it version 1.0"

          "Half of Programming is coding"....."The other 90% is DEBUGGING"

          "Document my code????" .... "WHYYY??? do you think they call it CODE? "

          Comment

          Working...
          X