Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I need a radio button to enable others 3

Status
Not open for further replies.

Bryan - Gendev

Programmer
Jan 9, 2011
408
AU
In my app I have a form with a pageframe pg01 on it with 3 pages.
On page 3 I have 6 radio buttons ON/OFF

Button #1 is on page 3
Buttons #2 to #6 are on a container conAdvanced on that page

I want button 1 - ON to

enable the container
enable the other 5 radio buttons

In button1.option1 I have

Code:
With This

	.pg01.page3.conAdvanced.enabled = .t.

	.pg01.page3.conAdvanced.editoptions.Enabled = .T.

	.pg01.page3.conAdvanced.impooptions.Enabled = .T.

	.pg01.page3.conAdvanced.chkpreview.Enabled = .T.

	.pg01.page3.conAdvanced.chkwmark.Enabled = .T.

	.pg01.page3.conAdvanced.cmdselect.Enabled = .T.
Endwith

Thisform.Refresh

When clicking option1 to ON the other buttons are not enabled.

What am I missing?

GenDev
 
Your request it's a little unclear. Maybe you must change the word This to ThisForm in your sample code.

I tried to reconstitute your situation:

Code:
PUBLIC ofrm
ofrm=CREATEOBJECT("MyForm")
ofrm.show()

DEFINE CLASS Myform as Form
	height=500
	ADD OBJECT pg01 as mypageframe 
ENDDEFINE

DEFINE CLASS mypageframe as PageFrame
	height=400
	PageCount=3
	PROCEDURE Init
		This.Pages[3].AddObject("button1","MyOptionGroup")
		This.Pages[3].button1.Value=2
		This.Pages[3].button1.Visible=.T.
		This.Pages[3].AddObject("conAdvanced","mycontainer")
		This.Pages[3].conAdvanced.Top=50
		This.Pages[3].conAdvanced.Visible=.T.
		This.Pages[3].AddObject("conAdvanced2","mycontainer2")
		This.Pages[3].conAdvanced2.Top=50
		This.Pages[3].conAdvanced2.Left=200
		This.Pages[3].conAdvanced2.Visible=.T.
	ENDPROC
ENDDEFINE

DEFINE CLASS MyOptionGroup as OptionGroup
	ButtonCount=2
	width=100
	height=50
	PROCEDURE Init
		This.Option1.AutoSize=.T.
		This.Option1.Caption='On'
		This.Option2.AutoSize=.T.
		This.Option2.Caption='Off'
	ENDPROC
	PROCEDURE Option1.Click
		With ThisForm
			.pg01.page3.conAdvanced.enabled = .t.
			.pg01.page3.conAdvanced.editoptions.Enabled = .T.
			.pg01.page3.conAdvanced.impooptions.Enabled = .T.
			.pg01.page3.conAdvanced.chkpreview.Enabled = .T.
			.pg01.page3.conAdvanced.chkwmark.Enabled = .T.
			.pg01.page3.conAdvanced.cmdselect.Enabled = .T.
		ENDWITH

		ThisForm.pg01.page3.conAdvanced2.Enabled=.T.
		ThisForm.pg01.page3.conAdvanced2.Setall("enabled",.T.)
		Thisform.Refresh
	ENDPROC
	PROCEDURE Option2.Click
		With ThisForm
			.pg01.page3.conAdvanced.enabled = .F.
			.pg01.page3.conAdvanced.editoptions.Enabled = .F.
			.pg01.page3.conAdvanced.impooptions.Enabled = .F.
			.pg01.page3.conAdvanced.chkpreview.Enabled = .F.
			.pg01.page3.conAdvanced.chkwmark.Enabled = .F.
			.pg01.page3.conAdvanced.cmdselect.Enabled = .F.
		Endwith

		ThisForm.pg01.page3.conAdvanced2.Enabled=.F.
		ThisForm.pg01.page3.conAdvanced2.Setall("enabled",.F.)
		Thisform.Refresh
	ENDPROC
ENDDEFINE

DEFINE CLASS mycontainer as Container
	width=150
	height=300
	Enabled=.F.
	ADD OBJECT editoptions as optionGroup WITH enabled=.F.,width=100,height=50,ButtonCount=2
	ADD OBJECT impooptions as optionGroup WITH enabled=.F.,top=50,width=100,height=50,ButtonCount=2
	ADD OBJECT chkpreview as optionGroup WITH enabled=.F.,top=100,width=100,height=50,ButtonCount=2
	ADD OBJECT chkwmark as optionGroup WITH enabled=.F.,top=150,width=100,height=50,ButtonCount=2
	ADD OBJECT cmdselect as optionGroup WITH enabled=.F.,top=200,width=100,height=50,ButtonCount=2
ENDDEFINE

DEFINE CLASS mycontainer2 as Container
	width=200
	height=300
	Enabled=.F.
	ADD OBJECT editoptions as optionbutton WITH enabled=.F.
	ADD OBJECT impooptions as optionbutton WITH enabled=.F.,top=50
	ADD OBJECT chkpreview as optionbutton WITH enabled=.F.,top=100
	ADD OBJECT chkwmark as optionbutton WITH enabled=.F.,top=150
	ADD OBJECT cmdselect as optionbutton WITH enabled=.F.,top=200
ENDDEFINE

Respectfully,
Vilhelm-Ion Praisach
Resita, Romania
 
First of all, you don't need [tt]Thisform.Refresh[/tt]. It's got nothing to do with enabling buttons, and only wastes time. But that's not directly related to your problem.

More importantly, your containership paths seem to be all wrong. You say the code runs from Button 1 in the first option group. But then you have [tt]WITH THIS[/tt], followed by a reference to the page frame. That can't be right. The page frame is a member of the form, not the option group. Perhaps you meant [tt]WITH THISFORM[/tt], in which case the paths would be correct. But, better still, you should do [tt]WITH THISFORM.g01.page3.conAdvanced[/tt] or better still [tt]WITH THIS.Parent[/tt].

Finally, there is a difference in enabling / disabling an option group vs the individual buttons in the group. As well as setting the Enabled property of EditOptions, etc, you need to set the property for the contained buttons. You can do that using [tt].EditOption.SetAll("enabled", .T.)[/tt].

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Hi,
You may want to try this

Code:
With This.Parent.conAdvanced

	.enabled = .t.

	.editoptions.Enabled = .T.

	.impooptions.Enabled = .T.

	.chkpreview.Enabled = .T.

	.chkwmark.Enabled = .T.

	.cmdselect.Enabled = .T.
Endwith

.Refresh

hth

MK
 
I believe in Visual Basic optionbuttons are placed individually inside a container. In VFP there is a specialized object, called OptionGroup.
Instead of programming each option button click, you can use the OptionGroup's interactivechange event.
Reading Mike Lewis's reply I guess maybe you are referring to the visual aspect. In this case instead of disabling the optiongroup (container), you must disable the optionbuttons.
Code:
PROCEDURE button1.Interactivechange
	ThisForm.pg01.page3.conAdvanced.editoptions.setall("Enabled",This.Value=1)
	ThisForm.pg01.page3.conAdvanced.impooptions.setall("Enabled",This.Value=1)


Respectfully,
Vilhelm-Ion Praisach
Resita, Romania
 
Thanks to everyone..

Mike and Vilhelm-Ion Praisach's suggestion does exactly what I was wanting to do on that page. Thanks Guys.

I also added the same commands in the init of the Option to set them up when the form loads however I need to set the

operation up the same way as before when I load the form based on an ini file entry.

I put this code in the form's init but it does not work

All init code is within With Thisform construct.

Code:
If readpwini(inifile,'read','MODE','Status')='Advanced'

		.pg01.page3.conAdvanced.Enabled = .T.
		
		ELSE
		
		.pg01.page3.conAdvanced.Enabled = .f.
		
		.pg01.page3.conAdvanced.editoptions.SetAll("Enabled",This.Value=2)
		.pg01.page3.conAdvanced.impoptions.SetAll("Enabled",This.Value=2)
		.pg01.page3.conAdvanced.chkpreview.SetAll("Enabled",This.Value=2)
		.pg01.page3.conAdvanced.chkwmark.SetAll("Enabled",This.Value=2)
		.pg01.page3.conAdvanced.cmdselect.SetAll("Enabled",This.Value=2)

	Endif

Anyone help here - then I'm finished with this form?

GenDev
 
Well, you need WITH THISFORM for code starting with a dot like .pg01.page3....
That'll give error "expression is not valid outside of WITH/ENDWITH". Pretty straight forward. If you don't get that error, then you have a WITH statement somewhere up not showing and if that's the wrong parent object you'd get pg01 is not an object.

Why don't you at least post your errors? Do you suppress them?

Did you move code from the form level to a control? On the form level, eg in Form.Init code THIS is the form. on the control level, eg in an optiongroup init, THIS is the optiongroup and THISFORM would work as the form, so you can't simply copy around code and expect it to work everywhere, it has to be in the right context.

Also make the right dependencies. If you have a config.ini, that contains the info on what parts of the form should be enabled/disabled directly or indirectly, and some parts of the form, eg a configuration page of the form pageframe displays the config and is there to change it, then don't influence the form from click or interactive change, just update the ini file from there and reuse the code using the ini to configure the form, or you're doing things twice or three times and have a less maintainable form.

Bye, Olaf.
 
Olaf,

I don't get errors - The construct in the init is valid WITH/ENDWITH.

My app has a large 100+ lines of ini dependencies which I use throughout my app. There are many forms which are used throughout my app.

What I am doing on page 3 in the subject 'Options' form is simply enabling 'Advanced' mode which then makes more facilities available within my app.

I just need the options form to open recognising what the 5 options I have been discussing are set to. My init code works there except for enabling the options as the code in the options1 interactivechange on page 3 does so well.

Cheers

GenDev
 
Well, interactivechange is not programmaticchange.

That's why I suggest not using the control methods/events. Let them just call form methods, so you can call the same code from option interactivechange and from programmaticchange, too.

The code enabling all form objects shouldn't do that controlled from the current optiongroup value, but from the ini value itself.

If you automate outlook and create a mailitem, you send a mail by oMailitem.send(), not by application.cmdSend.click(), do you? See what this is all about?

Events are there to process events. The configuration of your form should change immediately, if a user changes the options, but the bigger thruth is, the forms enabled and disabled parts should depend on the configuration. So get things straight and you won't have to do this more than in one place.

Bye, Olaf.
 
I am not an expert programmer - just one with many ideas of what I want my app to do. And with your,Mike and other's help I have come a long way over the last ten years. I'm now a septuagenarian.

I'm not too clear about the things in your last message but I think you are suggesting putting that list of SetAlls in a method on the form and calling it when needed.

I shall try that, thanks.

GenDev
 
>I think you are suggesting putting that list of SetAlls in a method on the form and calling it when needed.
Yes, indeed. That's centralizing this operation and you can do it from interactivechange, programmaticchange or init or activate or whatever other events of whatever controls will matter. You're always doing the same thing from the same context this way. All that needs to be done in advnace is update the config.ini or at least it's representation in memory, in array, variables or cursors. And the only other thing is of course storing the current settings in the ini.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top