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

Accessing a checkbox's state at runtime

Status
Not open for further replies.

swisslog

Programmer
Jul 11, 2002
20
CH
... that's not complicated!
BUT: How can I construct the checkbox's name at runtime?

I have 640 checkboxes in a Window. They are called chck_1_1 / chck_1_2 / chck_1_3 .... chck_2_1 ... chck_32_20

I would like to read the state of all these checkboxes into a loop:

For i=1 to 32
For j=1 to 20
lb_val=chck_i_j
...
Next j
Next i

How to do this in PB ?

 
Use the window's control array. You can locate the checkboxes using the typeof e.g.:
Code:
integer n

FOR n = 1 to 5

IF w_dept.Control[n].TypeOf() = CheckBox! THEN
		... // Some processing
	END IF

NEXT

This code comes from the PB help files , TypeOf function.

You should then be able to use Clasname(obj) to narrow down to the checkboxes you're interested in.

Cheers
 
Hi,

You may have to rename your checkboxes to a standard convention for the string functions to work - such as:

cbx_01_01
cbx_03_12
cbx_32_20...

Then, when you get the Classname() from the object, use the string functions Mid()... to get the row/col array coordinates to populate them in a 2-dimensional array:

lcbx_Obj = cbx_32_15 ;
ls_Name = ClassName( lcbx_Obj ) ;
//
lb_Checkbox[ Integer( Mid( ls_Name, 5, 2 )), Integer( Mid( ls_Name, 8 )) ] = lcbx_Obj.Checked ;
// That can be interpreted as under:
// lb_Checkbox[ 32, 15 ] = cbx_32_15.Checked


While evaluating the ClassName(), you may like to use the CHOOSE CASE/END CHOOSE statement instead of IF/END IF as this is more elegant and easier to use/read.

Regards,

--
PowerObject!
-----------------------------------------
PowerBuilder / PFC Developers' Group
 
Thank you PowerObject & BetterLateThanNever!

I turned arround both of your solutions. I started a bit like PowerObject's suggestion but tought that would make too much code. And also the script would be too dependent to the control names.
Then I started like suggested by BetterLateThanNever. I retained that solution. I declared an array of 640 structures: str_eg
x
y
control_index
row
column

Then I analyse the 640 x/y positions in order to afect the row/column values. This way, the chexbox names are not relevant.
Then I can manipulate all the checkboxes like this:

checkbox lcbx_a
if str_eg.row=... / str_eg.col=...
lcbx_a=lwindow.control[str_eg.control_index]
lcbx_a.checked=TRUE //changes the value to checked
...

This works wonderfull and does not take more than a half screen of code!

Thanks a lot for your help

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top