Announcement

Collapse
No announcement yet.

help - syntax error ???

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

  • help - syntax error ???

    ok ... I know this is probably something obvious that I am missing, but why does this generate a syntax error?

    I seems to be something to do with the ASCIIZ type....

    thanks..

    DECLARE FUNCTION dmstod SDECL ALIAS "dmstod" (BYREF dms AS ASCIIZ * 12) AS ASCIIZ * 10

  • #2
    The problem is that you can't return an asciiz string as the result of a function.
    Forum: http://www.jose.it-berater.org/smfforum/index.php

    Comment


    • #3
      got it...thanks.

      I can use STRING instead of ASCIIZ ...

      Comment


      • #4
        The DECLARE has to match the procedure header.

        If that is your function in your DLL, make sure it is returning STRING before you try to DECLARE in the using program that it returns a string; if that is someone else's library, recheck the documentation to see what it is returning.

        Some libraries *do* return an ASCIIZ string... or more often, an ASCIIZ PTR. You can't call either of those a STRING in your DECLARE statement if the library is not returing an OLE string (what PB uses for STRING types).
        Michael Mattias
        Tal Systems (retired)
        Port Washington WI USA
        [email protected]
        http://www.talsystems.com

        Comment


        • #5
          response to Michael Mattias

          thanks Michael...

          I got that ... understood that DECLARE has to match the proceedure.

          The function in question is one that I am writting as part of a DLL, so using STRING is not a problem. I simply used AS STRING in both the DECLARE and the FUNCTION statement ... it works fine.

          but...

          I would rather used a fixed length string ... I have it in the back of my mind that it is better coding practice. So, I was looking at passing the ASCIIZ PTR to a fixed length string. After reading the documentation I see that it says you should declare the variable in the function as GLOBAL or STATIC which has raised another question ???

          I will post that question in a separate thread since it is another line of thinking ...

          so...thanks for the help...worst case, my DLL will work passing STRING in and out of the function

          M

          Comment


          • #6
            You can always return an ASCIIZ (or fixed string or UDT) to your calling module by using parameters....
            Code:
            #COMPILE EXE 
            
            DECLARE FUNCTION GetMyString LIB "Mylib.dll" (sz AS ASCIIZ) AS LONG 
             ....
               LOCAL szA   AS ASCIIZ * %SOME_SIZE
            
               X =  GetMyString  ( szA) 
               IF ISTRUE X THEN
                  szA was filled by the function in the dll
            
            
            ...
            #COMPILE DLL 
            
            FUNCTION GetMyString (sz AS ASCIIZ) EXPORT AS LONG
            
                sz = "the new value" 
                FUNCTION = %TRUE    ' success
            
            END FUNCTION
            MCM
            Michael Mattias
            Tal Systems (retired)
            Port Washington WI USA
            [email protected]
            http://www.talsystems.com

            Comment


            • #7
              ok - question?

              yes ... I knew I could do that ... would prefer it to be the functions return value but yes...would work fine...

              question ... in your code example, do we not care what the value of sza is initially. When you just create a variable i.e.

              LOCAL szA AS ASCIIZ * %SOME_SIZE

              noteI get it that sz = "the new value" is the returned value to sza)

              but...

              there is no (pre call) initial value assigned to szA right? I would think you needed to assign it at least a dummy value before it was passed TO the function so tht the function could re-assign it to "the new value" ??

              second unrelated question...

              Am I correct in assuming that using a fixed length string is better practice than using a variable length string ... in general? My old college Pascal teaching is hauning me as I steer towards the BASIC STRING type instead of the more "acceptable" fixed lengths of Pascal and C

              Comment


              • #8
                there is no (pre call) initial value assigned to szA right? I would think you needed to assign it at least a dummy value before it was passed TO the function so tht the function could re-assign it to "the new value" ??
                Unlike some other languages, BASIC initializes variables.

                LOCAL szA AS ASCIIZ * %SOME_SIZE

                is equivalent to

                LOCAL szA AS ASCIIZ * %SOME_SIZE
                szA = ""
                Forum: http://www.jose.it-berater.org/smfforum/index.php

                Comment


                • #9
                  thanks

                  ok ... so declaring the variable also inits it to null...

                  thanks...

                  Comment


                  • #10
                    >ok ... so declaring the variable also inits it to null...

                    The better reason for 'declaring' the variable is so the program will compile when you compile with #DIM ALL, which in turn will prevent you from doing something dopey, like accidentally using some variable incorrectly.

                    The use of #DIM ALL is highly recommended!! (By me, anyway).
                    Michael Mattias
                    Tal Systems (retired)
                    Port Washington WI USA
                    [email protected]
                    http://www.talsystems.com

                    Comment

                    Working...
                    X