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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Toggle mode for command buttons? 5

Status
Not open for further replies.

german12

Programmer
Nov 12, 2001
563
0
16
DE
As an example: I have a form with 4 command buttons
placed in a row next to each other.
Click events:
cmd1 produces an "A"
cmd2 produces a "B"
cmd3 produces a "C"
cmd4 produces a "D"
So if I click all the buttons - I get
"ABCD"
But now I just want to
have "ABD".
Is it possible to click cmd3 again (toggle mode), and with it the string
"ABD" to achieve - or do I need a second set of
command-buttons (cmd5 to cmd8) where each click is a
withdrawal reached.
Maybe there is a code for this?

Klaus


Peace worldwide - it starts here...
 
I'm not really sure what you want, but that said, I would put a hidden (in production, visible in dev) button
on your form called process and give it this click method - other people would use a method for the form, but
I like buttons I can see during development... Also you need somewhere to show the result - so I would pop a
text box on as well

Code:
THISFORM.TEXT1.Value = ""
IF thisform.command1.ForeColor<> RGB(0,0,0)
	thisform.text1.Value = thisform.text1.Value + "A"
ENDIF
IF thisform.command2.ForeColor<> RGB(0,0,0)
	thisform.text1.Value = thisform.text1.Value + "B"
ENDIF
IF thisform.command3.ForeColor<> RGB(0,0,0)
	thisform.text1.Value = thisform.text1.Value + "C"
ENDIF
IF thisform.command4.ForeColor<> RGB(0,0,0)
	thisform.text1.Value = thisform.text1.Value + "D"
ENDIF

Then in the click method of each of the four command buttons
I would put code like this...

Code:
this.ForeColor = IIF(this.ForeColor=RGB(0,0,0),RGB(125,125,125),RGB(0,0,0))
thisform.process.click



Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.
 
Obviously, you don't need to toggle the button colour, you could use another device, an image or
a check box.

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.
 
Griff is on the right track, the checkbox has a special style called "graphical".

In this style a checkbox looks like a button that can have the default state and pressed down state and the value changes from .t. to .f., well, as it still is a checkbox.

A group of checkboxes is what you need and if any of them changes by interactivechange or programmaticchange put together the alphabetical string by the states of the checkboxes.

In the simplest form add 4 checkboxes to a container, so that each checkbox within the container can iterate over all checkboxes by a For Each oCheckbox in This.Parent.Controls. Let the captions be A,B,C,D,E... Then iterating over each oCheckbox you put together a string by starting with '' and then add checkbox captions by string = string + iif(oCheckbox.Value,oCheckbox.caption,'').

Is it enough to sketch the idea or should I get more concrete what to do?

Chriss
 
Thanks Griff & Chriss.
Sorry...
I think I have to make my thread more understandable.

The question is based on my former thread
Thread184-1814144
Chriss gave me the good advice to search with randomized terms.

Meanwhile I therefore created this form:

Zufall_-_Screenshot_2022-03-27_185827_lc9y7r.jpg

By having 4 tables open when this form starts it has not been a problem to populate the blue fields by randomizing.
eg. for Noun:

Code:
SELECT 1  *Get the table for Nouns in workarea 1
x = INT(1+RECCOUNT() * RAND())
GO x
this.Value = hauptw
[/code]

That works fine - and with only one click on a button named "Generate" I can populate all textboxes by using 4 different files at the same time.
(and with every new Click on the "Generate"-button I can get a new combination.)

And then it was no problem to send the combined string (Noun+adjective+color+Technik) to GOOGLE and can see perhaps interesting pictures for that.

But sometimes it would be better to send only one or two and not not all 4 terms to google, then the results are better.
I would then like to keep some of the terms (and put the other part away temporarily) and try again with a smaller group to find something interesting in Google.
(Something that gives me a new idea as a subject for a watercolor.)

So for example I want to delete values of two of the textboxes (or set them to blank) and just search for Noun+Color.
But sometimes I would like to have the old combination back first and use e.g. noun + technology as a search term.

I think I have that explained better now.

Klaus






Peace worldwide - it starts here...
 
Klaus said:
I think I have that explained better now.

Sure, the context is clearer now, but it will surprise you, I won't change my advice.

Instead of having textboxes with that randomizing code have checkboxes, and instead of setting this.value, set this.caption=hauptw.
Also set checkbox.style=1, which makes them graphical. Actually the style is only a matter of taste, but a button can't have two states, a checkbox can. Isnt that what your question is about by the title you gave it? Buttons you can toggle. Yes, there are such buttons: Checkboxes with graphical style.

Now when you have these checkboxes (no matter in which style) you add a search button and in its click you can put together the captions of these checkboxes, but only when they are in the selected state, so unselected words are skipped and the search only as the picked words.

Even the code stays alsmost as is:
Code:
Local searchstring
searchstring= ''
For Each oCheckbox in Thisform.Checkboxcontainer.Controls
   searchstring = searchstring + IIF(oCheckbox.Value,' '+oCheckbox.caption,'')
Endfor

The only important part for this loop to work is that these four checkboxes are in a container and are the only controls in that container. And I am more concrete with the name of the container, but you can of course adapt that. If you don't want controls in a container for the sake of grouping them, you can also put them on the form, but then buílding the searchstring will be uglier:
Code:
Local searchstring
searchstring = IIF(Thisform.Checkbox1.Value,' '+Thisform.Checkbox1.caption,'') + ;
IIF(Thisform.Checkbox2.Value,' '+Thisform.Checkbox2.caption,'') + ;
IIF(Thisform.Checkbox3.Value,' '+Thisform.Checkbox3.caption,'') + ;
IIF(Thisform.Checkbox4.Value,' '+Thisform.Checkbox4.caption,'')

Also note, that the value of a checkbox is only .t. or .f. and therefore an ideal boolean to use in an IIF, but the word then isn't the value, it's the caption instead.

Chriss
 
I have to say I had completely forgotten the styling 'Graphical' for check boxes.
That said, in Windows 11 at least, it is really quite unclear as to which ones are clicked
and which are not!

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.
 
Hello Klaus,

you may have an entry "ignore" or "-" in you tables. If selected this button (or "column") is ignored.

Regards
tom

 
Griff said:
in Windows 11 at least, it is really quite unclear as to which ones are clicked and which are not!

True, that was easier in the older 3d style Winforms.

But you can add a picture of an LED and change it to lit/unlit or use the usual checkbox. AS said, just a matter of taste.
The checkbox is still the logical control to use as it can be toggled.

Chriss
 
Chriss,
I tried your code to find out, whether it works.

Code:
Local searchstring
searchstring= ''
For Each oCheckbox in Thisform.Checkboxcontainer.Controls
   searchstring = searchstring + IIF(oCheckbox.Value,' '+oCheckbox.caption,'')
Endfor

but got this

Container_-_Screenshot_2022-03-29_230925_jxmco1.jpg


What did I do?
My Test:
I created a form with 4 checkboxes
I gave each checkbox a caption

In the click-event of the form I placed your code

There were nothing else but these four checkboxes.

When I run the form I marked 2 of the checkboxes and then clicked into the form ,but then the error above came.

What did I do wrong?
I can not find it.

Can you help?

Thanks
Klaus


Peace worldwide - it starts here...
 
Did you put a container on the form and called it Checkboxcontainer?
Did you put the 4 checkboxes inside that container, as child objects (not just in the same rectangle area)?

If not, the code for you would be the other one.

Also, the initial value for the checkboxes should be either .t. (words are picked by default - or .f., the value of a checkbox can also be 0 and toggle between 0 and 1 and you don't want that for the IIF works on boolean .t./.f. but not on 0/1. Other languages make no difference between boolean values and numbers, but VFP does.

Chriss
 
Oh...I think I just found my error: ( I crossed with your answer.

You wrote that with a checkbox only the logical state .t. or .f. may have.
I confused that with 1 and 0 and assigned these values ​​to the checkboxes for the test.

Sorry....the program is running now.
I had never worked with checkboxes before, but now I see how useful they can be.

Thanks
Klaus

Btw. The program also works when I put only the four checkboxes in a form. It was not necessary to have a special container for that boxes. (a form is a container, is it not?)
condition - you are right - no other objects within this formular


Peace worldwide - it starts here...
 
Klaus said:
It was not necessary to have a special container for that boxes. (a form is a container, is it not?)

That's true, I gave the code not using the container.Controls, a Form als has a Controls property. For Each oCheckbox in Thisform.Controls you iterate all controls, not only the four checkboxes.
You can adapt to it by using other methods like checking whether oCheckbox is a checkbox by making a baseclass a condition, but even then you might have other checkboxes for other means than for the search keyword picking.

A container is just a natural object to group a subset of controls including the option to iterate over them and only them instead over all form controls.

Chriss
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top