Array Question

Post Reply
User avatar
Jeff Barnes
Posts: 912
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada
Contact:

Array Question

Post 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?
Thanks,
Jeff Barnes

(FWH 12.01, xHarbour 1.2.1, Bcc582)
User avatar
James Bott
Posts: 4654
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Post 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
User avatar
Jeff Barnes
Posts: 912
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada
Contact:

Post 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.
Thanks,
Jeff Barnes

(FWH 12.01, xHarbour 1.2.1, Bcc582)
User avatar
Roger Seiler
Posts: 223
Joined: Thu Dec 01, 2005 3:34 pm
Location: Nyack, New York, USA
Contact:

Post 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
User avatar
Roger Seiler
Posts: 223
Joined: Thu Dec 01, 2005 3:34 pm
Location: Nyack, New York, USA
Contact:

Post 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
*-------------
User avatar
Jeff Barnes
Posts: 912
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada
Contact:

Post by Jeff Barnes »

Thanks Enrico / James.
Thanks,
Jeff Barnes

(FWH 12.01, xHarbour 1.2.1, Bcc582)
User avatar
James Bott
Posts: 4654
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Post 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
User avatar
Jeff Barnes
Posts: 912
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada
Contact:

Post 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 :-)
Thanks,
Jeff Barnes

(FWH 12.01, xHarbour 1.2.1, Bcc582)
User avatar
Manuel Valdenebro
Posts: 706
Joined: Thu Oct 06, 2005 9:57 pm
Location: Málaga-España

Post 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.
Un saludo

Manuel
User avatar
Roger Seiler
Posts: 223
Joined: Thu Dec 01, 2005 3:34 pm
Location: Nyack, New York, USA
Contact:

Post by Roger Seiler »

Manuel, glad you found it helpful. - Roger
Post Reply