Announcement

Collapse
No announcement yet.

type variable - Data type mismatch error

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

  • Michael Mattias
    replied
    >>...what kind of application needs an MS-DOS date/time structure?
    > an old one?

    Put that man on the short list for one of the Nobel Prizes.

    Leave a comment:


  • John Montenigro
    replied
    ...an old one??
    Last edited by John Montenigro; 25 Jul 2009, 12:39 PM.

    Leave a comment:


  • Michael Mattias
    replied
    Inquiring Minds Want to Know:

    In the year two thousand nine, more than twenty-five years since the introduction of Windows(r) and at least fifteen years since the last release of MS-DOS(r), what kind of application needs an MS-DOS date/time structure?


    Windows and MS-DOS are registered trademarks of Microsoft Corporation Redmond WA USA

    Leave a comment:


  • Scott Slater
    replied
    You could also use a Word Ptr to get the job done.

    Code:
    TYPE test 'this is the structure for api call
       ' (FileTimeToDosDateTime)
       Day       AS BIT * 5 IN WORD
       Month    AS BIT * 4
       year      AS BIT * 7
    END TYPE
    
    Local pTest as Word Ptr
    Local tTest as test
    
    pTest = VarPtr(tTest)
    
    now use:  @pTest = {whole word value}
    and            tTest.{element} for individual elements
    In the union example all of the elements would start at the same exact location. If the entire word is to encompass all of the parts as in the TYPE, then you want to use the TYPE as a member of the UNION instead of just the individual members themselves.

    Leave a comment:


  • Jeff Blakeney
    replied
    Charles,

    Re: API documentation. Yes, lp stands for long pointer. Like Michael said, it is best to check the documentation for the API call and the declare statement being used by your PB program to be sure you are passing it the proper parameter types. The WIN32API.INC has this declare for FileTimeToDosDateTime:

    Code:
    DECLARE FUNCTION FileTimeToDosDateTime LIB "KERNEL32.DLL" ALIAS "FileTimeToDosDateTime" (lpFileTime AS FILETIME, lpFatDate AS WORD, lpFatTime AS WORD) AS LONG
    As you can see it is expecting a FILETIME structure and two WORD values but doesn't specify them as pointers. The reason it can be declared this way is that PB defaults to sending parameters BYREF. This means it sends the pointer to the parameter rather than the value of the parameter. If you need to send the value instead of the pointer you need to use BYVAL.

    RE: The bit values being overlayed. My example code was wrong. In my example, wrd, Day, Month and Year would have all been overlayed with wrd being bits 0 to 15, Day 0 to 4, Month 0 to 3 and Year 0 to 6. It wouldn't have worked very well. Your code in post 5 for creating the TYPE and UNION are correct.

    Leave a comment:


  • Michael Mattias
    replied
    FWIW, I did (some time ago) submit a NSF to allow TYPE SET to use a scalar variable as the either the subject or object of the assignment.

    That would have solved this problem...
    >structure = variable '- error Data type mismatch
    .. by using the syntax
    TYPE SET structure=Variable

    It would also allow doing some stuff with UDTs using some simple macros; macros which expand into TYPE SET scalarvar = string or scalarvar, which is not allowed.

    MCM

    Leave a comment:


  • Charles Perry
    replied
    Looking further into the union and type, don't I have to have a type/end type in the union so the bit entries don't overlay each other?

    TYPE FileDate
    Day as BIT * 5 in word
    Month as BIT *4
    Year as BIT * 7
    END TYPE

    UNION FatD
    FatDate as WORD
    FDate as FileDate
    END UNION

    Function PBMAIN () as LONG

    DIM FD as FatD
    DIM Var_Year as WORD

    so to extract the year

    Var_Year = FD.FDate.Year

    END FUNCTION

    This seems to work OK.
    Am I missing something or making it more complicated than necessary?

    Leave a comment:


  • Michael Mattias
    replied
    >This works fine, but are these variable notations pointers?

    This just came up here last week.

    "In general" when you see "lp<anything>" in the SDK docs, it means "the address of [pointer to]" the variable.

    However, you should always read the remarks in the documentation; and then check your call against the DECLARE statement you are using.

    MCM

    Leave a comment:


  • Charles Perry
    replied
    API and pointer notation

    Thanks. that pointed me in the right direction. Another question -

    From the API Documentation

    FileTimeToDosDateTime(const Filetime *lpFile,LPWORD lpFatDate,LPWORD lpFatTime)

    This indicates that the entries are all pointers.

    I'm using the dot notation for type and union structures. Are these pointers?

    example API call

    FileTimeToDosDateTime(List.ftLastWriteTime,FD.FatDate,FT.FatTime)

    This works fine, but are these variable notations pointers?

    Leave a comment:


  • Jeff Blakeney
    replied
    You need to use a UNION for what you are trying to do. Try this instead:

    Code:
    #COMPILE EXE
    #DIM ALL
    
    UNION test 'this is the structure for api call (FileTimeToDosDateTime)
        wrd   AS WORD
        Day   AS BIT * 5 in WORD
        Month AS BIT * 4
        year  AS BIT * 7
    END UNION
    
    FUNCTION PBMAIN () AS LONG
    
        LOCAL variable AS WORD
        LOCAL structure AS test
    
        structure.wrd = variable
    
    END FUNCTION

    Leave a comment:


  • Charles Perry
    started a topic type variable - Data type mismatch error

    type variable - Data type mismatch error

    Trying to use typed variables to assign data to the structure and retrieve the elements for conversion. The structure is a word and variable is defined as a word but the complier errors them as different types, why?
    Can't I assign a variable to a typed variable if they are the same length?

    #COMPILE EXE
    #DIM ALL
    TYPE test 'this is the structure for api call
    ' (FileTimeToDosDateTime)
    Day AS BIT * 5 IN WORD
    Month AS BIT * 4
    year AS BIT * 7
    END TYPE
    FUNCTION PBMAIN () AS LONG
    DIM variable AS WORD
    DIM structure AS test
    structure = variable - error Data type mismatch
    END FUNCTION
Working...
X