Page 1 of 1

Array Question

Posted: Mon Dec 31, 2007 1:22 pm
by Jeff Barnes
Hi Everybody,

I may be overlooking something simple but it has been awhile since I have worked with array's.

I have set up an array using:

aIDocList := {}
DO WHILE ! EOF()
aAdd( aIDocList, {DropList->Name, DropList->BMPFile} )
skip
ENDDO

I now need to allow the user to select the first item from a combobox in a dialog, store that value to cItem1 while storing the second value to cItem2.

I am stuck at this point ... any ideas?

Posted: Mon Dec 31, 2007 3:51 pm
by James Bott
Jeff,

I suggest creating two arrays. Use the one you wish for the combobox, then after the user makes the selection, extract the related one from the second array by the location of the selection in the first array. Was that clear?

James

Posted: Mon Dec 31, 2007 5:19 pm
by Jeff Barnes
Hi James,

I thought of doing that but I could not figure out how to get the item number from the array when selected from a resource dialog box.

If you could help with that one, I'll be all set.

Posted: Mon Dec 31, 2007 5:25 pm
by Enrico Maria Giordano

Code: Select all

oLbx:nAt
EMG

Posted: Mon Dec 31, 2007 6:13 pm
by Roger Seiler
Jeff,

James is right about needing a single dimension array for your combobox because a combobox cannot handle multidimension arrays directly. However, you may have some unstated reason for wanting to create aIDocList as a multidimensional array for use as such somewhere else in your program. If that is the case, then just download the file "TestComb.zip" from the link below for a sample of how to do that. The example is in 16 bit FiveWin, but works exactly the same in 32 bits...

http://www.leadersoft.com/software/testcomb.zip

- Roger

Posted: Mon Dec 31, 2007 6:23 pm
by Roger Seiler
Jeff, here it is if you just want to see the code without having to download the sample....

*----------------------------

* testcomb.prg

#include "fivewin.ch"

PROCEDURE Main()

LOCAL aNames := {},aIDocList := {},cItem := "",;
cItem1 := "",cItem2 := "",;
oDlg,oCbx,oBtn

USE Droplist ALIAS Droplist NEW

DO WHILE !EOF()

aAdd( aNames, DropList->Name )
aAdd( aIDocList, {DropList->Name, DropList->BMPFile} )

SKIP

ENDDO

DEFINE DIALOG oDlg TITLE "TestCombo for Jeff Barnes" ;
FROM 1,5 TO 10,40

// Here is the important part, using a 1-dimension array for ITEMS, and
// then using the selection to pull data from a multi-dimension array...
@ 2,5 COMBOBOX oCbx VAR cItem ITEMS aNames ;
SIZE 40,40 PIXEL OF oDlg ;
ON CHANGE (cItem1 := aIDocList[oCbx:nAt,1], ;
cItem2 := aIDocList[oCbx:nAt,2], ;
oDlg:Update() )

@ 20, 5 SAY cItem1 SIZE 30,12 PIXEL OF oDlg UPDATE
@ 20,65 SAY cItem2 SIZE 40,12 PIXEL OF oDlg UPDATE

@ 40,5 BUTTON oBtn PROMPT "Cancel" SIZE 25,12 PIXEL OF oDlg ;
ACTION (oDlg:End() )

ACTIVATE DIALOG oDlg



RETURN
*-------------

Posted: Mon Dec 31, 2007 6:23 pm
by Jeff Barnes
Thanks Enrico / James.

Posted: Mon Dec 31, 2007 11:02 pm
by James Bott
Jeff,

>I thought of doing that but I could not figure out how to get the item number from the array when selected from a resource dialog box.

As Enrico or Roger showed, or:

aArray2[ ascan( aArray1, cItem ) )

James

Posted: Tue Jan 01, 2008 4:57 pm
by Jeff Barnes
Thanks Roger.

I ended up using the 2 separate arrays but I like your solution ... I will keep this one for next time :-)

Posted: Thu May 01, 2008 7:19 pm
by Manuel Valdenebro
Roger Seiler wrote:Jeff, here it is if you just want to see the code without having to download the sample....
Thanks Roger. Today I have used your solution succesfully.

Regards.

Posted: Sun May 04, 2008 11:19 pm
by Roger Seiler
Manuel, glad you found it helpful. - Roger