Array Question

Array Question

Postby Jeff Barnes » Mon Dec 31, 2007 1:22 pm

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 16.11, xHarbour 1.2.3, Bcc730)
User avatar
Jeff Barnes
 
Posts: 929
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada

Postby James Bott » Mon Dec 31, 2007 3:51 pm

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
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Postby Jeff Barnes » Mon Dec 31, 2007 5:19 pm

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 16.11, xHarbour 1.2.3, Bcc730)
User avatar
Jeff Barnes
 
Posts: 929
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada


Postby Roger Seiler » Mon Dec 31, 2007 6:13 pm

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

Postby Roger Seiler » Mon Dec 31, 2007 6:23 pm

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

Postby Jeff Barnes » Mon Dec 31, 2007 6:23 pm

Thanks Enrico / James.
Thanks,
Jeff Barnes

(FWH 16.11, xHarbour 1.2.3, Bcc730)
User avatar
Jeff Barnes
 
Posts: 929
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada

Postby James Bott » Mon Dec 31, 2007 11:02 pm

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
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Postby Jeff Barnes » Tue Jan 01, 2008 4:57 pm

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 16.11, xHarbour 1.2.3, Bcc730)
User avatar
Jeff Barnes
 
Posts: 929
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada

Postby Manuel Valdenebro » Thu May 01, 2008 7:19 pm

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
Manuel Valdenebro
 
Posts: 706
Joined: Thu Oct 06, 2005 9:57 pm
Location: Málaga-España

Postby Roger Seiler » Sun May 04, 2008 11:19 pm

Manuel, glad you found it helpful. - Roger
User avatar
Roger Seiler
 
Posts: 223
Joined: Thu Dec 01, 2005 3:34 pm
Location: Nyack, New York, USA


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 64 guests