DbCombo and Array Data

DbCombo and Array Data

Postby anserkk » Tue Mar 17, 2009 9:36 am

Hi,

Is it true that ONLY character type data can be used in arrays along with DBCombo :shock: . Or is there any other way of using it. I have found that if numeric data is used in aItems in DbCombo, then DbCombo returns the Array index number instead of the actual Value from the aItems
Can anybody confirm it

For eg:

LIST arrays has to contain only Character type data in it
ITEMS arrays has to contain only Character type data in it

Code: Select all  Expand view
#include "FiveWin.ch"
#include "DbCombo.ch"
//-----------------------------------------------//
FUNCTION Main()
//-----------------------------------------------//
Local oDlg, oDbCmb1,oDbCmb2,oSay1,oSay2
Local aList1,aItem1,aList2,aItem2,nVar1,nVar2,cSay1,cSay2

aList1:={"MCA","BCA","DDC","ENG"}
aItem1:={"101","102","103","104"}   // Has to be Character type data

/* If the Values in aItem1 is Numeric like the following
aList1:={"MCA","BCA","DDC","ENG"}
aItem1:={101,102,103,104}  // Numeric data
then the returning values will be 1,2 3 (Array elemt no instead of the values 101,102,103,104)
*/


aList2:={}
aItem2:={}

nVar1:="101" ; nVar2:=spac(3)  // DbCombo VAR has to be a Character type

DEFINE DIALOG oDlg TITLE "Test" FROM 0,0 to 20,50

@1,1 SAY oSay1 VAR "   " OF oDlg UpDate
@2,1 SAY oSay2 VAR "   " OF oDlg UpDate

@4,1 DBCOMBO oDbCmb1 VAR nVar1 OF oDlg UPDATE ;
     ITEMS aItem1 ;
     LIST aList1   ;
     SIZE 120,200  ;
     ON CHANGE ( SetItems(nVar1,@nVar2,oDbCmb2), ;
                 oSay1:SetText(nVar1),oSay2:SetText(nVar2)        )
     
@5,1 DBCOMBO oDbCmb2 VAR nVar2 OF oDlg UPDATE ;
     ITEMS aItem2 ;    
     LIST aList2   ;
     SIZE 120,200  ;
     ON CHANGE oSay2:SetText(nVar2)
     
ACTIVATE DIALOG oDlg

Return NIL

//-----------------------------------------------//
Function SetItems2(nVar1,nVar2,oDbCmb2)
//-----------------------------------------------//
Local aList2,aItem2
*MsgInfo(nVar1)   // If numeric type then nVar1 will be 1,2 or 3 (Array elemt no) instead of 102,102,103
if nVar1 == "101"
    aList2:={"M1","M2","M3"}
    aItem2:={"201","202","203"}
elseif nVar1 == "102"
    aList2:={"B1","B2","B3"}
    aItem2:={"301","302","303"}
elseif nVar1 == "103"
    aList2:={"D1","D2","D3"}
    aItem2:={"401","402","403"} 
elseif nVar1 == "104"
    aList2:={"E1","E2","E3"}
    aItem2:={"501","502","503"}    
Endif
oDbCmb2:SetItems(aItem2,aList2)
nVar2:=aItem2[1]

Return NIL


I have made a very serious mistake in my code assuming that Numeric data type array works fine with DbCombo. But my PRG worked perfectly. Only recently I came to know about this. Fortunately or unfortunately the Data inside the ITEMS array was numeric 1,2,3,4,5,6 series, so my program worked perfectly as DbCombo returned array index value 1,2,3,4,5,6 because the aItems data was numeric :D

Is it like this DbCombo is expected to work, or is there anything else I have to take care. Would have been nice if DbCombo could handle numeric aItems data too.

Regards

Anser
User avatar
anserkk
 
Posts: 1332
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Re: DbCombo and Array Data

Postby James Bott » Tue Mar 17, 2009 2:43 pm

Anser,

Yes, both Combobox and DBCombo (which inherits from Combobox) require data to be character. We cannot modify them to use numeric without breaking existing code. You just have to convert your array to character before using DBCombo (or create a character copy of your numeric array).

Regards,
James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: DbCombo and Array Data

Postby anserkk » Wed Mar 18, 2009 6:39 am

Dear Mr.James,

Thankyou for the information. I understand that these changes would break the existing DbCombo code and is necessary for keeping backward compatibility. If DbCombo could handle numeric data in aItems, then we could have avoided unnecesary convertions to str() and Val() and thereby reduce the chances of programming mistakes :)

Regards

Anser
User avatar
anserkk
 
Posts: 1332
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 92 guests