Announcement

Collapse
No announcement yet.

help - syntax error ???

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

  • Michael Mattias
    replied
    >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).

    Leave a comment:


  • Mark Farrar
    replied
    thanks

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

    thanks...

    Leave a comment:


  • José Roca
    replied
    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 = ""

    Leave a comment:


  • Mark Farrar
    replied
    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

    Leave a comment:


  • Michael Mattias
    replied
    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

    Leave a comment:


  • Mark Farrar
    replied
    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

    Leave a comment:


  • Michael Mattias
    replied
    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).

    Leave a comment:


  • Mark Farrar
    replied
    got it...thanks.

    I can use STRING instead of ASCIIZ ...

    Leave a comment:


  • José Roca
    replied
    The problem is that you can't return an asciiz string as the result of a function.

    Leave a comment:


  • Mark Farrar
    started a topic help - syntax error ???

    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
Working...
X