Multiple Dimension Array in Combobox

Multiple Dimension Array in Combobox

Postby cdmmaui » Fri May 25, 2018 3:52 pm

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
cdmmaui
 
Posts: 689
Joined: Fri Oct 28, 2005 9:53 am
Location: Houston ∙ Chicago ∙ Los Angeles ∙ Miami ∙ London ∙ Hong Kong

Re: Multiple Dimension Array in Combobox

Postby nageswaragunupudi » Fri May 25, 2018 10:28 pm

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
nageswaragunupudi
 
Posts: 10653
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Multiple Dimension Array in Combobox

Postby cdmmaui » Fri May 25, 2018 10:36 pm

Hi Rao,

Redefine works the same as well, correct?
*~*~*~*~*~*~*~*~*~*
Darrell Ortiz
CDM Software Solutions, Inc.
https://www.cdmsoft.com
User avatar
cdmmaui
 
Posts: 689
Joined: Fri Oct 28, 2005 9:53 am
Location: Houston ∙ Chicago ∙ Los Angeles ∙ Miami ∙ London ∙ Hong Kong

Re: Multiple Dimension Array in Combobox

Postby nageswaragunupudi » Sat May 26, 2018 3:32 am

Yes.
Regards

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

Re: Multiple Dimension Array in Combobox

Postby cdmmaui » Sat May 26, 2018 4:53 pm

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: 689
Joined: Fri Oct 28, 2005 9:53 am
Location: Houston ∙ Chicago ∙ Los Angeles ∙ Miami ∙ London ∙ Hong Kong

Re: Multiple Dimension Array in Combobox

Postby cdmmaui » Sat May 26, 2018 4:56 pm

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
cdmmaui
 
Posts: 689
Joined: Fri Oct 28, 2005 9:53 am
Location: Houston ∙ Chicago ∙ Los Angeles ∙ Miami ∙ London ∙ Hong Kong

Re: Multiple Dimension Array in Combobox

Postby joseluisysturiz » Sun May 27, 2018 2:59 am

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
joseluisysturiz
 
Posts: 2064
Joined: Fri Jan 06, 2006 9:28 pm
Location: Guatire - Caracas - Venezuela

Re: Multiple Dimension Array in Combobox

Postby nageswaragunupudi » Sun May 27, 2018 6:02 am

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: 10653
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Multiple Dimension Array in Combobox

Postby nageswaragunupudi » Sun Jun 03, 2018 7:03 am

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

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

Re: Multiple Dimension Array in Combobox

Postby joseluisysturiz » Sun Jun 03, 2018 11:42 pm

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
joseluisysturiz
 
Posts: 2064
Joined: Fri Jan 06, 2006 9:28 pm
Location: Guatire - Caracas - Venezuela

Re: Multiple Dimension Array in Combobox

Postby TimStone » Tue Aug 27, 2019 9:56 pm

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
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
User avatar
TimStone
 
Posts: 2945
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: Multiple Dimension Array in Combobox

Postby Silvio.Falconi » Wed Aug 28, 2019 2:14 pm

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.
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7075
Joined: Thu Oct 18, 2012 7:17 pm

Re: Multiple Dimension Array in Combobox

Postby betoncu » Wed Aug 28, 2019 2:33 pm

Perfect :D
Birol Betoncu
birol.betoncu@gmail.com
Using Harbour, FWH 19.05, BCC7
User avatar
betoncu
 
Posts: 126
Joined: Sat Oct 08, 2005 9:38 pm
Location: Cyprus (North)

Re: Multiple Dimension Array in Combobox

Postby TimStone » Wed Aug 28, 2019 4:53 pm

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
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
User avatar
TimStone
 
Posts: 2945
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: Multiple Dimension Array in Combobox

Postby Silvio.Falconi » Wed Aug 28, 2019 7:32 pm

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  Expand view  RUN


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 !!!!
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7075
Joined: Thu Oct 18, 2012 7:17 pm

Next

Return to FiveWin for Harbour/xHarbour

Who is online

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