wbrowse

wbrowse

Postby Colin Haig » Wed Jul 27, 2011 11:56 am

Hi All

I have a two dimension array but I dont know how to get the data into the browsers bLine
ie oLbx:bLine :=

I have an array of employees which can have eight tasks assigned for a day and I am trying to display this
in a browse - the size of the employee array can change as new staff is hired or they leave.



Any ideas greatly appreciated.

Cheers

Colin
Colin Haig
 
Posts: 310
Joined: Mon Oct 10, 2005 5:10 am

Re: wbrowse

Postby kennedyv » Wed Jul 27, 2011 2:23 pm

Is it the number of rows or the number of columns that change?
User avatar
kennedyv
 
Posts: 8
Joined: Fri Nov 23, 2007 9:19 pm

Re: wbrowse

Postby Colin Haig » Wed Jul 27, 2011 2:50 pm

The number of columns change - the columns depend on the array of employees.

cheers

Colin
Colin Haig
 
Posts: 310
Joined: Mon Oct 10, 2005 5:10 am

Re: wbrowse

Postby kennedyv » Wed Jul 27, 2011 3:22 pm

Have a look at the sample code below.

I am assuming you browsing a 2-dimensional array. In the sample each array element represents a line in the browse while each subarray represents a column, eg. aArrayData[nRow][nCol]

First thing to do is create a dummy browse using

@ 0,0 LISTBOX oBrw FIELDS "" HEADERS "" COLSIZES 10 ...

Later use oBrw:SetArray() to browse the correct array - presumably you will refresh the array from a button or menu option (in the sample below I use a menu - you can do this before ACTIVATE WINDOW also)

The important thing to remember is that before you call :refresh() you must set :aHeaders to the correct number of columns and also :bLine and :aColSizes must be set at this point also.

:bLine must be set to a codeblock that returns an array. The generic function DispVals() generates a suitable codeblock for any size of 2-dimensional array. It converts data of any datatype to character using cValToChar() - you might prefer to use a different method.

Hope this helps.

Code: Select all  Expand view

#include "fivewin.ch"

// ------------------------------------------------------------------------ //

FUNCTION main

LOCAL oWnd,oBrw,oCol
LOCAL aEmploy

SET DATE BRITISH
SET CENTURY ON

DEFINE WINDOW oWnd FROM 0,0 TO 480,640 PIXEL
oWnd:center()

// create a dummy browse
@ 0,0 LISTBOX oBrw FIELDS "" HEADERS "" COLSIZES 10 SIZE 630,470 PIXEL OF oWnd

SET MENU OF oWnd TO MainMenu(oWnd,oBrw)

ACTIVATE WINDOW oWnd

RETURN NIL

// ------------------------------------------------------------------------ //

FUNCTION mainmenu(oWnd,oBrw)

LOCAL oMenu

MENU oMenu
   MENUITEM "&File"

   MENU
      MENUITEM "Refresh Browse &1" ACTION Refresh1(oBrw)
      MENUITEM "Refresh Browse &2" ACTION Refresh2(oBrw)
      SEPARATOR
      MENUITEM "E&xit" ACTION oWnd:end()
   ENDMENU

ENDMENU

RETURN oMenu

// ------------------------------------------------------------------------ //

FUNCTION Refresh1(oBrw)

 // { { cName, cJobTitle, lIsFullTime, nAge, dJoinedFirm }, ... }
LOCAL aArrayData := { { "Smith", "Sales Executive",    .T., 40, CToD("16/06/2000") }, ;
                      { "Jones", "Sales Assistant", .F., 25, CToD("21/10/2009") }, ;
                      { "Brown", "Head of Research & Development", .T., 45, CToD("12/10/2001") } }

oBrw:SetArray(aArrayData)
oBrw:bLine         := { |o| DispVals(aArrayData,o) }
oBrw:aHeaders      := { "Name","Job Title","Fultime?","Age","Date joined firm" }  // MUST have the same number of elements as value returned by :bLine
oBrw:aColSizes     := { 150, 150, 30, 150, 150 }  // MUST be specified here otherwise program falls over!!!
oBrw:aJustify      := { .F., .F., .F., .T., .F. }

oBrw:refresh()

RETURN NIL

// ------------------------------------------------------------------------ //

FUNCTION Refresh2(oBrw)

 // { { cName, nAge, dJoinedFirm }, ... }
LOCAL aArrayData := { { "Smith", 40, CToD("16/06/2000") }, ;
                      { "Jones", 25, CToD("21/10/2009") }, ;
                      { "Brown", 45, CToD("12/10/2001") } }

oBrw:SetArray(aArrayData)
oBrw:bLine         := { |o| DispVals(aArrayData,o) }
oBrw:aHeaders      := { "Name","Age","Date joined firm" }  // MUST have the same number of elements as value returned by :bLine
oBrw:aColSizes     := { 210, 210, 210 }  // MUST be specified here otherwise program falls over!!!
oBrw:aJustify      := { .F., .T., .F. }

oBrw:refresh()

RETURN NIL


******************************************************************************
* DispVals(): returns an array with the current row of browse converted to
*             character values
******************************************************************************

STATIC FUNCTION DispVals(aArrayData,oBrw)

LOCAL aDisplay
LOCAL nRowCount := oBrw:nAt, ;
      nColCount, nColMax

nColMax := len(aArrayData[1])
aDisplay := array(nColMax)

FOR nColCount := 1 TO nColMax
    aDisplay[nColCount] := cValToChar(aArrayData[nRowCount][nColCount])  // convert to character datatype
NEXT

RETURN aDisplay
 
User avatar
kennedyv
 
Posts: 8
Joined: Fri Nov 23, 2007 9:19 pm

Re: wbrowse

Postby Colin Haig » Thu Jul 28, 2011 4:35 am

Hi kenedyv

Thank you - your sample works exactly the way I want my app to work - I am building dynamic arrays and must be doing something wrong , but
at least I have some good code to follow.

Your help is greatly appreciated.

Cheers

Colin
Colin Haig
 
Posts: 310
Joined: Mon Oct 10, 2005 5:10 am

Re: wbrowse

Postby Colin Haig » Thu Jul 28, 2011 8:52 am

Hi Kennedyv

I get an error when calling DispVals

MsgInfo(oLbx2:nAt) // returns 1
oLbx2:bLine := { |o| DispVals(aTasks,o) }

olbx2:nAt // causes error in DispVals function

I presume {|o| is the browse object being passed to the dispvals function.

Cheers

Colin
Colin Haig
 
Posts: 310
Joined: Mon Oct 10, 2005 5:10 am

Re: wbrowse

Postby kennedyv » Thu Jul 28, 2011 10:42 am

Can you send me the Application and Stack Calls sections from your error.log file.

At a guess, it sounds like this may be a parameter passing issue.

In the meantime, a few pointers which might help:

- DispVals() assumes a 2-dimensional array as follows: aArrayData[nRow][nCol]

- :aColSizes must be set between :SetArray() and :refresh()

- the size of :aColSizes and :aHeaders should be equal to the number of cols in browse

- The :nAt data of TWBrowse returns NIL after the browse is created until the first call to :SetArray() is made, at which point :nAt is set to 1

- in the sample code |o| is the browse object itself

Vincent
User avatar
kennedyv
 
Posts: 8
Joined: Fri Nov 23, 2007 9:19 pm

Re: wbrowse

Postby Colin Haig » Thu Jul 28, 2011 1:40 pm

Hi Vincent ( it feels much more polite to address you properly )

I think I have the two dimensional array correct - but I am going to strip my program right back and try build on your code.

Cheers

Coiln
Colin Haig
 
Posts: 310
Joined: Mon Oct 10, 2005 5:10 am

Re: wbrowse

Postby kennedyv » Thu Jul 28, 2011 4:17 pm

Hi Colin

OK. Let me know how things go. I've done a lot of work with arrays in TWBrowse - it can be tricky.

Vincent
User avatar
kennedyv
 
Posts: 8
Joined: Fri Nov 23, 2007 9:19 pm

Re: wbrowse

Postby Colin Haig » Thu Jul 28, 2011 11:02 pm

Hi Vincent

I found why I cant get your code to work in my app

{|0| DispVals(aData,0) } works fine with the fivewin wbrowse but I use a modified wbrowse ( Hernans) and the browse
object is not getting passed down.

This is the error I get
Error BASE/1004 Class: 'NIL' has no exported method: NAT

I have checked the code for the fivewin browse eval(::bLine, Self) , the browse I use eval(:: bLine) - so I modified the
code in my wbrowse but still the same error.

Cheers

Colin
Colin Haig
 
Posts: 310
Joined: Mon Oct 10, 2005 5:10 am

Re: wbrowse

Postby kennedyv » Fri Jul 29, 2011 8:53 am

DispVals() is not receiving the oBrw parameter

In the sample program

replace

oBrw:bLine := { |o| DispVals(aArrayData,o) }

with

oBrw:bLine := { |o| DispVals(aArrayData,oBrw) }

Also, ensure that oBrw has been created and is passed t the function in which this line appears.

Vincent
User avatar
kennedyv
 
Posts: 8
Joined: Fri Nov 23, 2007 9:19 pm

Re: wbrowse

Postby Colin Haig » Sat Jul 30, 2011 8:38 am

Hi Vincent

I have my app all working now - thats for all your assistance.

Cheers

Colin
Colin Haig
 
Posts: 310
Joined: Mon Oct 10, 2005 5:10 am

Re: wbrowse

Postby surGom » Mon Sep 26, 2011 12:08 am

Thanks kennedyv was looking the same as Colling, and I could not solve with my code.

Luis Sáenz (surGom)
surGom
 
Posts: 640
Joined: Wed Oct 19, 2005 12:03 pm


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Silvio.Falconi and 101 guests