Results 1 to 4 of 4

Thread: Function: DFRecnumToRowId

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2009
    Location
    New Zealand
    Posts
    1,574

    Default Function: DFRecnumToRowId

    Hi

    If anyone is interested, here's a function that converts the good old RECNUM to a ROWID

    I generally use to when populating a cCJGrid via an SQL Statement - when the dataSource RowId needs to be populated.

    Usage:
    Get SQLColumnValue Of hstmt 1 To iRecnum
    Get CreateDataSourceRow of hoDataSource to aRowData
    Move (DFRecnumToRowId(iRecnum)) to aRowData.riID


    Code:
    Function DFRecnumToRowId Global Integer iDec Returns RowID
      String sHex
      String sRet
      Integer iCnt
      Move "" to sHex
      While (iDec>0)
        Move (Mid("0123456789ABCDEF", 1, ((iDec iand |CI$0F) + 1)) + sHex) to sHex
        Move (iDec / 16) to iDec
      Loop
      If (sHex="") Move "0" to sHex
      Move (Lowercase(Right("00000000"+sHex,8))) to sHex
      For iCnt from 1 to 4
        Move (Insert(Mid(sHex,2,(iCnt*2)-1),sRet,1)) to sRet
      Loop
      Function_Return (DeserializeRowID(sRet))
    End_Function
    Regards,
    Raveen Sundram

    Software Development Manager
    Excellent Software Ltd
    Auckland, New Zealand
    www.xls.co.nz

  2. #2
    Join Date
    Mar 2009
    Posts
    963

    Default Re: Function: DFRecnumToRowId

    Code:
    Use UI
    External_Function wvsprintf "wvsprintfA" USER32.DLL Pointer pResult String sTemplate Pointer pParam Returns Integer
    External_Function htonl "htonl" Ws2_32.dll Uinteger u Returns UInteger
    Function DFRecnumToRowId Global UInteger uDec Returns RowId
        Integer iVoid
        String sResult
        Move (htonl(uDec)) to uDec
        Move (Repeat(" ",9)) to sResult
        Move (wvsprintf(AddressOf(sResult), "%.8lx", AddressOf(uDec))) to iVoid
      Function_Return  (DeserializeRowID(Left(sResult,8))) 
    End_Function
    Used APIs to help out with the byte swap and int-to-hex conversion.

    Frank Cheng
    Last edited by Frank Cheng; 8-Jan-2021 at 10:41 PM. Reason: Wrong return type

  3. #3
    Join Date
    Feb 2009
    Posts
    1,938

    Default Re: Function: DFRecnumToRowId

    Frank
    I think you have the wrong return type on the reworked function.
    It should be a RowID

  4. #4
    Join Date
    Mar 2009
    Posts
    963

    Default Re: Function: DFRecnumToRowId

    Chris,

    I corrected the original reply. Thanks.

    Frank Cheng

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •