Page 1 of 2

Multiple Dimension Array in Combobox

PostPosted: Fri May 25, 2018 3:52 pm
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,

Re: Multiple Dimension Array in Combobox

PostPosted: Fri May 25, 2018 10:28 pm
by nageswaragunupudi
We can use multi-dimensional array in DBCOMBO.

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

Re: Multiple Dimension Array in Combobox

PostPosted: Fri May 25, 2018 10:36 pm
by cdmmaui
Hi Rao,

Redefine works the same as well, correct?

Re: Multiple Dimension Array in Combobox

PostPosted: Sat May 26, 2018 3:32 am
by nageswaragunupudi
Yes.

Re: Multiple Dimension Array in Combobox

PostPosted: Sat May 26, 2018 4:53 pm
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)

Re: Multiple Dimension Array in Combobox

PostPosted: Sat May 26, 2018 4:56 pm
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

Re: Multiple Dimension Array in Combobox

PostPosted: Sun May 27, 2018 2:59 am
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:

Re: Multiple Dimension Array in Combobox

PostPosted: Sun May 27, 2018 6:02 am
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.

Re: Multiple Dimension Array in Combobox

PostPosted: Sun Jun 03, 2018 7:03 am
by nageswaragunupudi
From version FWH 1804, item values can be numeric also ( any datatype )

Re: Multiple Dimension Array in Combobox

PostPosted: Sun Jun 03, 2018 11:42 pm
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:

Re: Multiple Dimension Array in Combobox

PostPosted: Tue Aug 27, 2019 9:56 pm
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.

Re: Multiple Dimension Array in Combobox

PostPosted: Wed Aug 28, 2019 2:14 pm
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

Re: Multiple Dimension Array in Combobox

PostPosted: Wed Aug 28, 2019 2:33 pm
by betoncu
Perfect :D

Re: Multiple Dimension Array in Combobox

PostPosted: Wed Aug 28, 2019 4:53 pm
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.

Re: Multiple Dimension Array in Combobox

PostPosted: Wed Aug 28, 2019 7:32 pm
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  Expand view


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 !!!!