Multiple Dimension Array in Combobox

User avatar
cdmmaui
Posts: 653
Joined: Fri Oct 28, 2005 9:53 am
Location: The Woodlands - Dallas - Scottsdale - London
Contact:

Multiple Dimension Array in Combobox

Post by cdmmaui »

Hello Everyone,

Happy Friday!

Is it possible to use a multiple dimension array in a COMBOBOX where one array element is the selected item and another array element is the display item in the COMBOBOX. I believe it would be similar to DBCOMBO.

If possible, can someone please provide an example?

Thank you,
*~*~*~*~*~*~*~*~*~*
Darrell Ortiz
CDM Software Solutions, Inc.
https://www.cdmsoft.com
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: Multiple Dimension Array in Combobox

Post by nageswaragunupudi »

We can use multi-dimensional array in DBCOMBO.

Example
@ r,c DBCOMBO <clauses> ALIAS <array> ITEMFIELD "1" LISTFIELD "2"
Regards

G. N. Rao.
Hyderabad, India
User avatar
cdmmaui
Posts: 653
Joined: Fri Oct 28, 2005 9:53 am
Location: The Woodlands - Dallas - Scottsdale - London
Contact:

Re: Multiple Dimension Array in Combobox

Post by cdmmaui »

Hi Rao,

Redefine works the same as well, correct?
*~*~*~*~*~*~*~*~*~*
Darrell Ortiz
CDM Software Solutions, Inc.
https://www.cdmsoft.com
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: Multiple Dimension Array in Combobox

Post by nageswaragunupudi »

Yes.
Regards

G. N. Rao.
Hyderabad, India
User avatar
cdmmaui
Posts: 653
Joined: Fri Oct 28, 2005 9:53 am
Location: The Woodlands - Dallas - Scottsdale - London
Contact:

Re: Multiple Dimension Array in Combobox

Post by cdmmaui »

Dear Rao,

I am loading data in to an array with the SQLLOAD below, however I am getting the following error message, source code below the error message.

// ERROR MESSAGE------------------------------------------------------------------

Application
===========
Path and name: C:\winapps\ual\ualdash.exe (32 bits)
Size: 3,873,280 bytes
Compiler version: Harbour 3.2.0dev (r1801051438)
FiveWin version: FWH 18.02
C compiler version: Borland/Embarcadero C++ 7.0 (32-bit)
Windows version: 6.2, Build 9200

Time from start: 0 hours 0 mins 3 secs
Error occurred at: 05/26/2018, 11:52:55
Error description: Error BASE/1068 Argument error: array access
Args:
[ 1] = C
[ 2] = N 1

Stack Calls
===========
Called from: .\source\classes\DBCOMBO.PRG => TDBCOMBO:FILL( 508 )
Called from: .\source\classes\DBCOMBO.PRG => TDBCOMBO:REDEFINE( 174 )
Called from: ualdash.prg => EDITBILL( 363 )
Called from: ualdash.prg => (b)MAIN( 105 )
Called from: .\source\classes\BTNBMP.PRG => TBTNBMP:CLICK( 693 )
Called from: .\source\classes\BTNBMP.PRG => TBTNBMP:LBUTTONUP( 944 )
Called from: .\source\classes\CONTROL.PRG => TCONTROL:HANDLEEVENT( 1721 )
Called from: .\source\classes\BTNBMP.PRG => TBTNBMP:HANDLEEVENT( 1909 )
Called from: .\source\classes\WINDOW.PRG => _FWH( 3368 )
Called from: => WINRUN( 0 )
Called from: .\source\classes\WINDOW.PRG => TWINDOW:ACTIVATE( 1043 )
Called from: ualdash.prg => MAIN( 158 )


// Code
REDEFINE DBCOMBO aGet[07] VAR nVessel ID 4007 OF oDlg ALIAS aVessel ITEMFIELD "1" LISTFIELD "2"

//-----------------------------------------------------------------------------
FUNCTION _SqlLoad( cSqlTable )
local oSqlLoad, cSqlLoad := "", aReturn := {}, cDat1 := "", cDat2 := "", cDat3 := "", cToday := "", cYr, cMon, cDay

IF PCOUNT()<1
cSqlTable := ""
ENDIF
AADD( aReturn, "" )
IF EMPTY(cSqlTable)
RETURN aReturn
ENDIF
cSqlTable := UPPER( cSqlTable )

TRY
oSqlLoad:=TOleAuto():New("ADODB.Recordset")
CATCH
MsgWait( "Unable to Load SQL Driver", Ptitle )
RETURN (.F.)
END

// Set...
oSqlLoad:CursorType := 1 // opendkeyset
oSqlLoad:CursorLocation := 3 // local cache
oSqlLoad:LockType := 3 // lock opportunistic

// Set SQL string...
cSqlLoad := "SELECT * FROM vessels WHERE Active=1 ORDER BY [DateCreated] DESC"
TRY
oSqlLoad:Open( cSqlLoad, 'Provider='+xPROVIDER+';Data Source='+xSOURCE+';Initial Catalog='+xDATABASE+';User Id='+xUSERID+';Password='+xPASSWORD )
CATCH oError
MsgInfo("Failed to Connect to the Database" + cEol + cSqlLoad + cEol + oError:Description, Ptitle )
RETURN .F.
END

DO WHILE (! oSqlLoad:BOF) .AND. (! oSqlLoad:EOF)
cDat1 := oSqlLoad:Fields( "id" ):Value
cDat2 := oSqlLoad:Fields( "Vessel Name" ):Value
cDat3 := oSqlLoad:Fields( "Voyage CSA" ):Value
IF (VALTYPE(cDat1)<>"U") .AND. (VALTYPE(cDat2)<>"U") .AND. (VALTYPE(cDat3)<>"U")
AADD( aReturn, { cDat1, ALLTRIM(cDat2) + " V." + ALLTRIM(cDat3) } )
ENDIF
oSqlLoad:Move( 1 )
ENDDO

oSqlLoad:Close()
oSqlLoad:=NIL

RETURN (aReturn)
*~*~*~*~*~*~*~*~*~*
Darrell Ortiz
CDM Software Solutions, Inc.
https://www.cdmsoft.com
User avatar
cdmmaui
Posts: 653
Joined: Fri Oct 28, 2005 9:53 am
Location: The Woodlands - Dallas - Scottsdale - London
Contact:

Re: Multiple Dimension Array in Combobox

Post by cdmmaui »

Rao,

Also, here is the resource code. Should that change? I could not find DBCOMBO in samples that uses RC file

CONTROL "", 4007, "ComboBox", WS_BORDER|CBS_DROPDOWNLIST|CBS_SORT|WS_VSCROLL|WS_TABSTOP, 425, 10, 225, 100
*~*~*~*~*~*~*~*~*~*
Darrell Ortiz
CDM Software Solutions, Inc.
https://www.cdmsoft.com
User avatar
joseluisysturiz
Posts: 2024
Joined: Fri Jan 06, 2006 9:28 pm
Location: Guatire - Caracas - Venezuela
Contact:

Re: Multiple Dimension Array in Combobox

Post by joseluisysturiz »

cdmmaui wrote:Dear Rao,

I am loading data in to an array with the SQLLOAD below, however I am getting the following error message, source code below the error message.

// ERROR MESSAGE------------------------------------------------------------------

Application
===========
Path and name: C:\winapps\ual\ualdash.exe (32 bits)
Size: 3,873,280 bytes
Compiler version: Harbour 3.2.0dev (r1801051438)
FiveWin version: FWH 18.02
C compiler version: Borland/Embarcadero C++ 7.0 (32-bit)
Windows version: 6.2, Build 9200

Time from start: 0 hours 0 mins 3 secs
Error occurred at: 05/26/2018, 11:52:55
Error description: Error BASE/1068 Argument error: array access
Args:
[ 1] = C
[ 2] = N 1

Stack Calls
===========
Called from: .\source\classes\DBCOMBO.PRG => TDBCOMBO:FILL( 508 )
Called from: .\source\classes\DBCOMBO.PRG => TDBCOMBO:REDEFINE( 174 )
Called from: ualdash.prg => EDITBILL( 363 )
Called from: ualdash.prg => (b)MAIN( 105 )
Called from: .\source\classes\BTNBMP.PRG => TBTNBMP:CLICK( 693 )
Called from: .\source\classes\BTNBMP.PRG => TBTNBMP:LBUTTONUP( 944 )
Called from: .\source\classes\CONTROL.PRG => TCONTROL:HANDLEEVENT( 1721 )
Called from: .\source\classes\BTNBMP.PRG => TBTNBMP:HANDLEEVENT( 1909 )
Called from: .\source\classes\WINDOW.PRG => _FWH( 3368 )
Called from: => WINRUN( 0 )
Called from: .\source\classes\WINDOW.PRG => TWINDOW:ACTIVATE( 1043 )
Called from: ualdash.prg => MAIN( 158 )


// Code
REDEFINE DBCOMBO aGet[07] VAR nVessel ID 4007 OF oDlg ALIAS aVessel ITEMFIELD "1" LISTFIELD "2"

//-----------------------------------------------------------------------------
FUNCTION _SqlLoad( cSqlTable )
local oSqlLoad, cSqlLoad := "", aReturn := {}, cDat1 := "", cDat2 := "", cDat3 := "", cToday := "", cYr, cMon, cDay

IF PCOUNT()<1
cSqlTable := ""
ENDIF
AADD( aReturn, "" )
IF EMPTY(cSqlTable)
RETURN aReturn
ENDIF
cSqlTable := UPPER( cSqlTable )

TRY
oSqlLoad:=TOleAuto():New("ADODB.Recordset")
CATCH
MsgWait( "Unable to Load SQL Driver", Ptitle )
RETURN (.F.)
END

// Set...
oSqlLoad:CursorType := 1 // opendkeyset
oSqlLoad:CursorLocation := 3 // local cache
oSqlLoad:LockType := 3 // lock opportunistic

// Set SQL string...
cSqlLoad := "SELECT * FROM vessels WHERE Active=1 ORDER BY [DateCreated] DESC"
TRY
oSqlLoad:Open( cSqlLoad, 'Provider='+xPROVIDER+';Data Source='+xSOURCE+';Initial Catalog='+xDATABASE+';User Id='+xUSERID+';Password='+xPASSWORD )
CATCH oError
MsgInfo("Failed to Connect to the Database" + cEol + cSqlLoad + cEol + oError:Description, Ptitle )
RETURN .F.
END

DO WHILE (! oSqlLoad:BOF) .AND. (! oSqlLoad:EOF)
cDat1 := oSqlLoad:Fields( "id" ):Value
cDat2 := oSqlLoad:Fields( "Vessel Name" ):Value
cDat3 := oSqlLoad:Fields( "Voyage CSA" ):Value
IF (VALTYPE(cDat1)<>"U") .AND. (VALTYPE(cDat2)<>"U") .AND. (VALTYPE(cDat3)<>"U")
AADD( aReturn, { cDat1, ALLTRIM(cDat2) + " V." + ALLTRIM(cDat3) } )
ENDIF
oSqlLoad:Move( 1 )
ENDDO

oSqlLoad:Close()
oSqlLoad:=NIL

RETURN (aReturn)
Saludos, debes estar pendiente que DBCOMBO no admite valores numericos, debes convertirnos a STRING, a menos que esto lo hayan arreglado...gracias, saludos... :shock:
Dios no está muerto...

Gracias a mi Dios ante todo!
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: Multiple Dimension Array in Combobox

Post by nageswaragunupudi »

Error description: Error BASE/1068 Argument error: array access
Args:
[ 1] = C
[ 2] = N 1

Stack Calls
===========
Called from: .\source\classes\DBCOMBO.PRG => TDBCOMBO:FILL( 508 )
This error means that the first element of aVessal is a empty character string, where as it should be an array.
Please check again.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: Multiple Dimension Array in Combobox

Post by nageswaragunupudi »

From version FWH 1804, item values can be numeric also ( any datatype )
Regards

G. N. Rao.
Hyderabad, India
User avatar
joseluisysturiz
Posts: 2024
Joined: Fri Jan 06, 2006 9:28 pm
Location: Guatire - Caracas - Venezuela
Contact:

Re: Multiple Dimension Array in Combobox

Post by joseluisysturiz »

nageswaragunupudi wrote:From version FWH 1804, item values can be numeric also ( any datatype )
Ok, gracias por la informacion, pero igual no tengo esa version...algun dia...jejeje...saludos...gracias... :shock:
Dios no está muerto...

Gracias a mi Dios ante todo!
User avatar
TimStone
Posts: 2536
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA
Contact:

Re: Multiple Dimension Array in Combobox

Post by TimStone »

I would like to revisit this thread.

For the code:

REDEFINE DBCOMBO oCbxA54 VAR oEditWork:oWorkPartsr:paruf2 ALIAS a Src ITEMFIELD "1" LISTFIELD "2" ;
ID 2504 OF oEditWork:oFld:aDialogs[2] UPDATE

and the Resource:

COMBOBOX. 2504, 395, 65, 25, 60, CBS_DROPDOWN | WS_BORDER | WS_VSCROLL | WS_TABSTOP

Using a two element array where 1 is a single character field, and 2 is a longer description.

When running, the field displays, and returns, only the values of LISTFIELD "2" and does not set the proper width for that display.

What is wrong with this code ? I have not been using the DBCOMBO previously.
Tim Stone
http://www.MasterLinkSoftware.com
timstone@masterlinksoftware.com
Using: FWH 19.06 with Harbour 3.2.0 / Microsoft Visual Studio Community 2019
User avatar
Silvio.Falconi
Posts: 4956
Joined: Thu Oct 18, 2012 7:17 pm

Re: Multiple Dimension Array in Combobox

Post by Silvio.Falconi »

use an array and combobox instead of dbcombo

@ 36,75 COMBOBOX cFilter ITEMS ArrTranspose( aListini )[ 2] SIZE 120,400 PIXEL OF oInfoTariffe;
ON CHANGE
Last edited by Silvio.Falconi on Wed Aug 28, 2019 7:56 pm, edited 1 time in total.
I use : FiveWin for Harbour August 2020 (Revision) - Harbour 3.2.0dev (r1712141320) - Bcc7.30 - xMate ver. 1.15.3 - PellesC
User avatar
betoncu
Posts: 120
Joined: Sat Oct 08, 2005 9:38 pm
Location: Cyprus (North)

Re: Multiple Dimension Array in Combobox

Post by betoncu »

Perfect :D
Birol Betoncu
birol.betoncu@gmail.com
Using Harbour, FWH 19.05, BCC7
User avatar
TimStone
Posts: 2536
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA
Contact:

Re: Multiple Dimension Array in Combobox

Post by TimStone »

I use RESOURCES ( .rc file ). Thus @ x,y does not work ...

I did try using arrTranspose() and COMBOBOX, and the drop down display does show the 2nd element. However, I need it to return the 1st element to the actual field for saving.

Again, the objective is to display the 2nd element of the array in the drop down, but to return the value of the 1st element to the field being edited by the combobox.

Thanks.
Tim Stone
http://www.MasterLinkSoftware.com
timstone@masterlinksoftware.com
Using: FWH 19.06 with Harbour 3.2.0 / Microsoft Visual Studio Community 2019
User avatar
Silvio.Falconi
Posts: 4956
Joined: Thu Oct 18, 2012 7:17 pm

Re: Multiple Dimension Array in Combobox

Post by Silvio.Falconi »

Dear Timm
run also with resources rc!!!!


aListini := Crea_Listini()

the array must not as { "One", "Two", "Three" } but two elements
sample

Code: Select all

 

Function Crea_Listini()
   local oListini
   Local alist_temp:={}
   local nArea    := Select()

    // create a array of all price list

   oListini:= TListini():new()
   oListini:gotop()


        DO While !oListini:eof()
             AaDd(alist_temp,{ oListini:name,trim(oListini:id)  })
            oListini:skip()
         ENDDO

        oListini:close()
     Select (nArea)

   return alist_temp
DEFINE DIALOG oDlg RESOURCE "Combos" BRUSH oBrush TRANSPARENT

REDEFINE COMBOBOX oCbx1 VAR cItem1 ITEMS ArrTranspose( aListini )[ 2] //I wish show trim(oListini:id)
ID 100 OF oDlg;
ON CHANGE Msginfo()

ACTIVATE DIALOG oDlg CENTERED

return nil


Dear Timm
> I need it to return the 1st element to the actual field for saving.


you always told me in the e-mails you sent me that you have been an experienced programmer for 40 years

and you tell me that if you use ArrTranspose () then you can't save because you need the first element ... are you kidding?

We Know the combobox returns a selection number oCbx1: nat

then to save the first element take the array alistini and taking the first element

aListini [oCbx1: nat] [1] ...

it was easy ...

so I know that you wanted joke with me .... to know that I was able,

But the programmer are you instead !!!!
I use : FiveWin for Harbour August 2020 (Revision) - Harbour 3.2.0dev (r1712141320) - Bcc7.30 - xMate ver. 1.15.3 - PellesC
Post Reply