wbrowse
-
- Posts: 310
- Joined: Mon Oct 10, 2005 5:10 am
wbrowse
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
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
Re: wbrowse
Is it the number of rows or the number of columns that change?
-
- Posts: 310
- Joined: Mon Oct 10, 2005 5:10 am
Re: wbrowse
The number of columns change - the columns depend on the array of employees.
cheers
Colin
cheers
Colin
Re: wbrowse
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.
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
#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
-
- Posts: 310
- Joined: Mon Oct 10, 2005 5:10 am
Re: wbrowse
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
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
-
- Posts: 310
- Joined: Mon Oct 10, 2005 5:10 am
Re: wbrowse
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
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
Re: wbrowse
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
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
-
- Posts: 310
- Joined: Mon Oct 10, 2005 5:10 am
Re: wbrowse
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
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
Re: wbrowse
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
OK. Let me know how things go. I've done a lot of work with arrays in TWBrowse - it can be tricky.
Vincent
-
- Posts: 310
- Joined: Mon Oct 10, 2005 5:10 am
Re: wbrowse
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
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
Re: wbrowse
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
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
-
- Posts: 310
- Joined: Mon Oct 10, 2005 5:10 am
Re: wbrowse
Hi Vincent
I have my app all working now - thats for all your assistance.
Cheers
Colin
I have my app all working now - thats for all your assistance.
Cheers
Colin
Re: wbrowse
Thanks kennedyv was looking the same as Colling, and I could not solve with my code.
Luis Sáenz (surGom)
Luis Sáenz (surGom)