Can I access the data in a control via an array?

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

Post Reply
User avatar
metron9
Posts: 45
Joined: Sat Sep 08, 2012 7:18 am
Location: Minnesota U.S.A.

Can I access the data in a control via an array?

Post by metron9 »

If I have a button, instead of changing the caption using code like this:

main_win.button_1.caption = '12345'

could I do something like this:

button_1 [x] = '12345'
User avatar
mol
Posts: 3825
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Re: Can I access the data in a control via an array?

Post by mol »

metron9 wrote:If I have a button, instead of changing the caption using code like this:

main_win.button_1.caption = '12345'

could I do something like this:

button_1 [x] = '12345'
I don't know.
But you can use it in this way:

Code: Select all

SetProperty("Main_Win", "button_1","caption","'12345")
if you have a lot of numbered buttons, you can do it:

Code: Select all

for i:=1 to 10
  cButtonName := "button_"+alltrim(str(i))
  SetProperty("Main_Win", cButtonName","caption", str(1,2))

Regards, Marek
User avatar
esgici
Posts: 4543
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Contact:

Re: Can I access the data in a control via an array?

Post by esgici »

Hi Mark
metron9 wrote:If I have a button, instead of changing the caption using code like this:

main_win.button_1.caption = '12345'

could I do something like this:

button_1 [x] = '12345'
For naming and assigning properties to controls, in addition to Marek's suggestion (using SetProperty() function), you may use also macro substitution (with & operator).

For an example please refer here.
Viva INTERNATIONAL HMG :D
User avatar
metron9
Posts: 45
Joined: Sat Sep 08, 2012 7:18 am
Location: Minnesota U.S.A.

Re: Can I access the data in a control via an array?

Post by metron9 »

Both replies I needed to implement.

I was trying to use a macro in the ACTION like this:

function anewbutton(parm1,Parm2,Parm3,Parm4)

N_Button= 'col'+ltrim(str(parm1))+'_B'
A_ct = 'virt_board.job_'+ltrim(str(Parm1))+'.caption'
DEFINE BUTTON &N_button
PARENT VIRT_BOARD
ROW Parm2
COL Parm3
WIDTH 80
HEIGHT 25
CAPTION parm4
ACTION virtbutton1(&A_ct)
FONTNAME "Arial"
FONTSIZE 9
TOOLTIP ""
FONTBOLD .T.
END BUTTON

return nil


So I changed the ACTION to

ACTION virtbutton1(Parm1)

and then changed the function virtbutton to:

function virtbutton1(parm1) /* Save last job button pushed */
lastBpushed := parm1
N_Button= 'col'+ltrim(str(parm1))+'_B'
lastJpushed = GETProperty("virt_board", N_button,"caption")
msgbox(N_button+' '+lastJpushed)
return nil

I had actually wrote a program to generate the code to make the buttons and put it in a file.ch
then included it inside the window declaration.

got to go , dentist appointment :o

Thank you.
Post Reply