NTK and The NTK Project
are properties of Jn Dechereux
Home | Documentation | FAQ.

Vanilla 1.1.8 is a product of Lussumo. More Information: Documentation, Community Support.

Welcome Guest!
Want to take part in these discussions? If you have an account, sign in now.
If you don't have an account, apply for one now.
    •  
      CommentAuthorGaza
    • CommentTimeJul 7th 2011 edited
     
    Dear Members,

    Just joint this forum on 6 July 2011 after getting NTK Pro registered.

    Below are the 2 Clipper functions and 1 attached function convert to NTK

    1. FUNCTION SortCode(), showing how to use FUNCTION ASELECT(), it appears
    this function can be used directly with NTK and xHarbour.

    2. FUNCTION ASELECT(), need suggestion for this function and tips how
    to convert to NTK code, for getting an idea how fast I can learn
    NTK language.

    3. FUNCTION NTKASELECT(), alredy tried to convert to NTK, but not sure if
    this will work and/or a correct convertion. Please advise.

    Any tip(s) in order to understand faster Learning NTK is appreciated.

    Thanks.
    Gaza

     
    
    FUNCTION SortCode(pcKode, pcField1, pcField2, pcArea, pnT, pnL, pnB, pnR)
    
    Local cReturn := Spac(Len((pcArea)->&pcField1)), nSel := 0, nJ := 0
    Local aNo := {}
    (pcArea)->(dbGoTop())
    
    While TRUE
      If (pcArea)->(dbSeek(AllTrim(pcKode)))
         While (AllTrim(pcKode) = SubS((pcArea)->&pcField1, 1,;
               Len(AllTrim(pcKode))) .and. ! (pcArea)->(Eof()))
           nJ++
           aAdd(aNo, Spac(Len((pcArea)->&pcField1)))
           aNo[nJ] := AllTrim((pcArea)->&pcField1)+;
                      "   "+AllTrim((pcArea)->&pcField2)
           (pcArea)->(dbSkip(1))
         Enddo
      Else
         Exit
      Endif
      If nJ > 20
         nJ := 20
      Endif
      nSel := ASELECT(pnT+1, pnT+1, pnT+nJ, pnR-1, aNo, .T.)
      If Empty(nSel)
         cReturn := Spac(Len((pcArea)->&pcField1))
      Else
         cReturn := SubS(aNo[nSel], 1, 5)
      Endif
      Exit
    End
    Return(cReturn)
    
    //-------------------------------------------
    
    #xtrans SayTxt(<row>,<col>,<xpr> [,<c>]) => ;
            SetPos(<row>,<col>); DispOut(<xpr>[,<c>])
    
    FUNCTION ASELECT(pnTop, pnLeft, pnBottom, pnRight, aMenu, aLog)
    
    Local oBrw, nKey, oCol, nLen, nNew, nInit, nWin, nWidth, nSub
    Local nRet, nAct
    
    nLen := Len( aMenu )
    cWar := "n/bg,w+/br,w+/r"
    
    If ValType(aLog) != "A"    // No logical array
       aLog := Array(nLen)     // so, create one!
       AFill( aLog, .T. )
    Endi
    nInit := 0
    nWin  := pnBottom - pnTop
    nWidth  := pnRight - pnLeft - 1
    nRet  := 0
    bBlk  := {|| .F.}
    
    Scroll(pnTop-1, pnLeft-1, pnBottom+1, pnRight+1)
    DispBox(pnTop-1, pnLeft-1, pnBottom+1, pnRight+1)
    DispBox(pnTop, pnRight+1, pnBottom, pnRight+1, Chr(176), "w/g")
    SayTxt(pnTop, pnRight+1, Chr(18), "w+/r")
    oBrw:=TBrowseNew(pnTop, pnLeft, pnBottom, pnRight)
    oBrw:colorSpec := cWar
    
    nSub := 1
    oBrw:goTopBlock    := {|| nSub := 1 }
    oBrw:goBottomBlock := {|| nSub := nLen }
    oBrw:skipBlock     := {|nI| nAct := if(Abs(nI) >= if(nI >= 0,;
                           nLen - nSub, nSub - 1), if(nI >= 0, nLen - nSub,;
                           1 - nSub),nI), nSub += nAct, nAct }
    
    oCol := TBColumnNew(, {|| aMenu[nSub]})
    oCol:colorBlock := {|| if(aLog[nSub], {1,2}, {1,3})}
    oCol:width := nWidth
    oBrw:addColumn(oCol)
    
    While .T.
      DispBegin()
      While !oBrw:stabilize()
      Enddo
      DispEnd()
      If (oBrw:hitTop .or. oBrw:hitBottom )
         Tone(87.3,1)
         Tone(40,3.5)
      Endif
      nNew := nWin / (nLen / nSub)   // Update Bar Gauge
      If nSub == 1
         nNew := 0
      Elseif nSub == nLen
         nNew := nWin
      Endif
      If ( nInit != nNew )
         SayTxt(pnTop+nInit, pnRight+1, Chr(176), "w/g")
         SayTxt(pnTop+nNew,  pnRight+1, Chr(18),  "w+/r")
         nInit := nNew
      Endif
      While ((nKey := InKey(0.1)) == 0)
        Eval(bBlk)
      Enddo
      If ( nKey == K_DOWN )
         oBrw:Down()
      ElseIf ( nKey == K_UP )
         oBrw:Up()
      ElseIf ( nKey == K_PGDN )
         oBrw:PageDown()
      ElseIf ( nKey == K_PGUP )
         oBrw:PageUp()
      ElseIf ( nKey == K_ESC )
         Exit
      Elseif ( nKey == K_ENTER )
         If aLog[nSub]            // Is the item selectable...?
            nRet := nSub          // If so, return array subscript
            Exit                  // for the element
          Endif
      Endif
    Enddo
    Return(nRet)
    
    
    •  
      CommentAuthorAbbougaga
    • CommentTimeJul 8th 2011 edited
     
    Hello Gaza,
    Welcome on board.

    ##Any tip(s) in order to understand faster Learning NTK is appreciated.
    Well, not sure there are so many. no magic!
    IMHO,
    goodwill, reading of docs, exploring source code of numerous tutorials and libs, and also asking questions this place are some of them.

    ##3. FUNCTION NTKASELECT(), alredy tried to convert to NTK, but not sure if
    ##this will work and/or a correct convertion. Please advise.
    Correct me if I'm wrong, but glancing at your snipets I guess you're trying to convert some kind of custom menu?
    In that case why shouldn't you try the NtkArrayView() function. I often use it - not only for quick browsing of memory arrays, but also when needed to make special/custom menus. It is very handy to implement and highly configurable (because it relies internally on a NtkTbrwse object). The full source is located in: c:\wntk4hrb\ntklib\radex\rntkcdlg.prg

    Below a code snipet extracted from one of my apps - hope you'll find it useful.
    Cheers,
    Ab


    PROCEDURE PRTMENU_EMPL(hWndP)
    LOCAL nChoix
    LOCAL hFontMenu := NTK_GetStockObject(ANSI_VAR_FONT)
    LOCAL aMenuTitle := { "- Votre Choix ? -" }
    LOCAL aMenuData  := { "Editer la Fiche courrante    ",;
                          "Liste des employés (couleur) ",;
                          "Liste détaillée des employés " }
    
    
    LOCAL aCfg := {} // array of settings to be passed to NtkArrayView()
         AADD( aCfg, { "sbHorz"        , .F.            })
         AADD( aCfg, { "sbVert"        , .F.            })
         AADD( aCfg, { "colGrids"      , .F.            })
         AADD( aCfg, { "ShowNumbers"   , .T.            })
         AADD( aCfg, { "NubColor"      , NTK_RGB(064,064,255)   })
         AADD( aCfg, { "nuBAlign"      , DT_RIGHT     })
         AADD( aCfg, { "nubWidth"      , -1   })
         AADD( aCfg, { "headFont"      , hFontMenu })
    
    
    SET RGB COLOR TEXT    C_BLACK ;  // Define your own blend on fly...
                  BACKGND C_BKGMENU
    
    // Syntax:
    // NtkArrayView( hWnd, nTop, nLeft, nBottom, nRight, cWinTitle, aRowHeaders, aRowDatas, aRowSizes, aCfg, nWinStyle )
    nChoix := NtkArrayView( hWndP, 06,68 , (06+08), (68+36),;
                            "MENU IMPRESSION...",;
                            aMenuTitle, aMenuData, Nil,;
                            aCfg, WND_FIXED ) // WS_DLGFRAME )
    
    
    CLEAR TYPEAHEAD
    
    IF nChoix==1
       PRT_EMPL_FORM()
    ELSEIF nChoix==2
       PRT_EMPL_LIST(2)   // Liste Couleurs
    ELSEIF nChoix==3
       PRT_EMPL_LIST(1)   // Liste Détaillée
    ENDIF
    RETURN
    
    
    •  
      CommentAuthorGaza
    • CommentTimeJul 8th 2011 edited
     
    Morning Ab,

    Thank you for your fast tips, I will try NtkArrayView()and let you know it is same as I use to my app or not.

    NTKASELECT()to be use for browsing database already filter by function SortCode().

    I just doubted how to get correct data when press Enter keyboard or click left mouse in browsing.

    what your advise for the below code, it this true.

    oBrw:DoubleClick := {|| oGet := oBrw:ColPos }
    ....
    ....
    oEdit := Field(Val(AllTrim(Str(oGet))))
    Return(oEdit)

    Rgds,
    Gaza
    •  
      CommentAuthorGaza
    • CommentTimeJul 8th 2011
     
    Dear Ab,

    Have try NtkArrayView() not working...???

    See attched.


    Rgds,
    Gaza
    •  
      CommentAuthorAbbougaga
    • CommentTimeJul 8th 2011
     
    Gaza,

    The code provided is a sub-routine that needs a parent window.
    Also, just keep in mind that each NTK app always requires a main container.
    Anyway, I made the needed changes to your Arrayview.prg. Now it works properly.

    See attached - Good luck with your testings.
    Cheers,
    Ab
    •  
      CommentAuthorAbbougaga
    • CommentTimeJul 9th 2011 edited
     
    Gaza,

    ##I just doubted how to get correct data when press Enter keyboard or click left mouse in ##browsing. what your advise for the below code, it this true.
    ##
    ##oBrw:DoubleClick := {|| oGet := oBrw:ColPos }
    ##....
    ##....
    ##oEdit := Field(Val(AllTrim(Str(oGet))))
    ##Return(oEdit)

    If your aim is to edit the value of the current hilighted cell in the datagrid object, I think you're going a wrong way. You should rather try something like this:
    // Do edit routine
    oB:doubleClick  := { |oB,nMsg,nWparam,nLparam| EditCell_dgv(oB)     } 
    
    // Exit from the active get session (if any), when user singleclick...
    oB:singleClick  := { |oB,nMsg,nWparam,nLparam| NtkTBAutoExitCell(oB) }  
    

    Learn more and find useful informations on how to make an EditCell procedure looking at
    c:\wntk4hrb\contribs\dgridview\dgriview.prg -> function EditCell_dgv(ob), L290

    Dgridview is a tutorial I wrote some years ago. Now it is officially part of NTK contribs.
    Hope it helps,
    Ab
    •  
      CommentAuthorGaza
    • CommentTimeJul 9th 2011
     
    Dear Ab,

    Thank you for your help.
    Now Arrayview.prg work properly.

    I just view days learning how to convert old DOS base program to Windows base program, it looks I must follow some role to write code in windows enviroment.

    I still learn and would like to know the structure programing in windows.

    By the way on my contribs directory, I can not found
    dgridview directory as well as dgriview.prg file.

    Below my list of directory.

    07/06/2011 07:51 PM <DIR> ActiveX
    07/06/2011 07:51 PM <DIR> AT
    07/06/2011 07:51 PM <DIR> Designer
    07/06/2011 07:51 PM <DIR> Helper
    07/06/2011 07:51 PM <DIR> MetaFile
    07/06/2011 07:51 PM <DIR> NewTV
    07/06/2011 07:51 PM <DIR> PrompMnu
    07/06/2011 07:51 PM <DIR> savnrest
    03/10/2006 08:27 PM 2,184 apicalls.prg
    12/17/2007 12:11 PM 5,563 COMPUTER.PRG
    07/08/2008 05:05 PM 26,506 CRYSTAL.PRG
    04/13/2007 05:30 PM 5,072 FoxLike.prg
    10/12/2006 08:09 PM 5,838 GaugeDmo.prg
    09/16/2009 05:28 PM 9,520 memstat.prg
    09/16/2009 04:54 PM 1,027,584 SHABOUT.exe
    01/29/2007 12:23 PM 4,850 SHABOUT.PRG
    04/16/2007 12:17 PM 10,076 TGauge.prg
    04/16/2007 10:36 PM 9,107 TTGauge.prg
    10/12/2006 08:32 PM 20,443 TTView.prg
    02/18/2007 01:15 AM 8,423 TViewDmo.prg
    11/12/2007 06:13 PM 13,806 W32API.PRG
    10/13/2006 12:49 PM 17,276 wrun.prg

    It is possible you to attached here the files.

    Rgds,
    Gaza
    •  
      CommentAuthorxbasefan
    • CommentTimeJul 9th 2011
     
    hi Gaza, welcome aboard!
    dgridview.zip is also available from the 'Knowledge Sharing' section of this ng.
    http://www.ntkproject.com/forum_ntk/comments.php?DiscussionID=8&page=1#Item_0
    wilson
    •  
      CommentAuthorGaza
    • CommentTimeJul 10th 2011
     
    Hi Wilson,

    Thank you, it good sample.

    But this is directly edit, EditCell procedure.

    What I looking for sample as follows.

    On main transaction let says to make delivery order.

    we browse "Customer code" and "customer name" only, when we click mouse or press enter, the "customer code" will get and input into main transaction.

    we browse "Part Number" and "Part Name" only, when we click mouse or press enter, the "Part Number" will get and input into main transaction.

    And than we can print the delivery order.

    So they are 3 database we use, Main.dbf, Customer.dbf, Parts.dbf.

    On Main.dbf only consist "Customer Code" field and
    "Part Number" field.

    Until now I have still not success yet do it with NTK,
    but with Clipper is easier as per sample above.

    Who may help me...???

    As per AB suggest NtkArrayView() can work in temporary I can use, but no good looking, because between Customer Code and Customer Name are not spared with vertical line such as brows.

    NtkArrayView() for other application not for database.

    Rgds,
    Gaza
    •  
      CommentAuthorGaza
    • CommentTimeJul 10th 2011
     
    Dear Forum,

    I still not clear for.

    SET ROW RATIO TO 20
    SET COL RATIO TO 8

    Why set Row Ratio to 20 instead of to 24 for example,
    as well as way set Col Ratio to 8 instead of to 40.

    If the setting of.

    SET PIXEL MODE OFF
    SET ROW RATIO TO 20
    SET COL RATIO TO 8

    Will effect to CHILD windows or we must re-setting
    for CHILD windows.

    When SET PIXEL MODE ON (back to default), I can not find in the samples.

    Rgds,
    Gaza
    •  
      CommentAuthorGaza
    • CommentTimeJul 13th 2011 edited
     
    Dear JN,

    I get the answer to my above question base on doing try and error.

    I need your confirmation.

    SET ROW RATIO or SET COL RATIO depend on Screen Resolution setting.

    For examples :

    1. Screen Resolution set to 640 (width) x 480
    (height) pixels
    Standard DOS Screen Size 80 (width) x 25 (height)
    SET ROW RATIO TO -> 480 : 25 = 19.20 equal to 20
    SET COL RATIO TO -> 640 : 80 = 8

    2. Screen Resolution set to 800 (width) x 600
    (height) pixels
    SET ROW RATIO TO -> 600 : 25 = 24
    SET COL RATIO TO -> 800 : 80 = 10

    3. Screen Resolution set to 1024 (width) x 768
    (height) pixels
    SET ROW RATIO TO -> 768 : 25 = 30.72 = 31 or 30
    SET COL RATIO TO -> 1024 : 80 = 12.80 = 13 or 12

    Regarding below question still
    not get answer, I have not try and error yet, any help.

    1. Will effect to CHILD windows or we must re-setting
    for CHILD windows.

    2. When SET PIXEL MODE ON (back to default), I can not find in the samples, it means when program terminated, it will be back to default..?

    Rgds
    Gaza
    •  
      CommentAuthorjnd
    • CommentTimeJul 15th 2011 edited
     
    Dear Gaza,

    You've hit the bull's eye!

    >1. Screen Resolution set to 640 (width) x 480(height) pixels
    >Standard DOS Screen Size 80 (width) x 25 (height)
    >SET ROW RATIO TO -> 480 : 25 = 19.20 equal to 20
    >SET COL RATIO TO -> 640 : 80 = 8

    Correct. Though nothing prevents you to use such a canvas in a 1024x728 sized window.
    Actually, the row/col ratio you defined, will only affect the display unit in use within the client-area of each window container of your program. In other words, the number of available row/col is depending on two parameters: the canvas you defined at top of your main proc and the size of the dialog for which you are currently using text or graphic commands.

    >1. Will effect to CHILD windows or we must re-setting
    >for CHILD windows.
    Yes, child containers will be affected automatically. Btw, these settings are done only once, at top of your main procedure. Afterwards, they are permanently active everywhere in the program until it stops. Also, here are a couple limits (and exceptions) you have to take care:
    - The scope of these commands is limited to the NTKRad layer. NTKCore's text and graphic functions are not affected.
    - Do not switch from SET PIXEL ON to OFF and viceversa from a prg module to another.
    - Keep in mind that CREATE WINDOW command only supports pixel coordinates.

    >2. When SET PIXEL MODE ON (back to default), I can not find in the samples, it means when
    >program terminated, it will be back to default..?
    You'll find many samples across NTK folders showing how to use these commands. Anyway you may take a particular look to \wntk4hrb\ntkrad\dosklike.prg and also \wntk4hrb\contribs\foxlike.prg


    N.B. Those commands have been designed only in order to facilitate migration of old xBase dos-applications to MS-Windows. However, I would not advise to use them for new/modern win32 projects (i.e. when starting from scratch).

    Hope this helps.

    Kind regards,
    JN