FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Array Question
Posts: 933
Joined: Sun Oct 09, 2005 01:05 PM
Array Question
Posted: Mon Dec 31, 2007 01: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)
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Array Question
Posted: Mon Dec 31, 2007 03: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

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 933
Joined: Sun Oct 09, 2005 01:05 PM
Array Question
Posted: Mon Dec 31, 2007 05: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)
Posts: 9022
Joined: Thu Oct 06, 2005 08:17 PM
Posts: 223
Joined: Thu Dec 01, 2005 03:34 PM
Array Question
Posted: Mon Dec 31, 2007 06: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
Posts: 223
Joined: Thu Dec 01, 2005 03:34 PM
Array Question
Posted: Mon Dec 31, 2007 06: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
*-------------

Posts: 933
Joined: Sun Oct 09, 2005 01:05 PM
Array Question
Posted: Mon Dec 31, 2007 06:23 PM

Thanks Enrico / James.

Thanks,

Jeff Barnes



(FWH 16.11, xHarbour 1.2.3, Bcc730)
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Array Question
Posted: 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

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 933
Joined: Sun Oct 09, 2005 01:05 PM
Array Question
Posted: Tue Jan 01, 2008 04: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)
Posts: 711
Joined: Thu Oct 06, 2005 09:57 PM
Array Question
Posted: Thu May 01, 2008 07: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
Posts: 223
Joined: Thu Dec 01, 2005 03:34 PM
Array Question
Posted: Sun May 04, 2008 11:19 PM

Manuel, glad you found it helpful. - Roger

Continue the discussion