Powerbuilder Syntax. How can i use FOR i = 1 TO 3 loop in this statement replacing these numbers

14,522

You'll need to build an array of CheckBox objects that you can then loop through. For instance,

Declare a instance variable on your window

CheckBox boxes[]

Add code in your window open event to collect the objects you want to loop through:

integer i
for i = 1 to UpperBound(this.control)
    if TypeOf(this.control[i]) = CheckBox! Then
        boxes[UpperBound(boxes) + 1] = this.control[i]
    end if
next

Note, you can use whatever logic you want to include (or not) a given control in the list. Here I added EVERY checkbox, you might need to do more testing in the IF condition if you only want SOME checkboxes.

Loop through control array to do whatever you need. For instance in a button click event the following will flip the checked state.

integer i
for i = 1 to UpperBound(boxes)
    boxes[i].Checked = NOT boxes[i].Checked
next

By the way, IF cbx_1.Checked = TRUE THEN is redundant... The Checked property is boolean, so IF cbx_1.Checked THEN is sufficient.

Share:
14,522
Sid
Author by

Sid

Fulltme Developer, Part time gamer Known Languages C++, Powerbuilder, VB, VBA, PHP/CSS/HTML, some techie knowledge in networking and PC skeletal interface. Likes to read books then watch them in Screen. Sci-Fi, ComedyDrama, Pure Comedy, Thriller, Action, War, Documentary... name it.. Into RPG Games, MMO, making private servers of mmo games. Likes to read blogs and stack is the best! One thing I do good in life.. play some games! or... nope.. playing GAMES!!!!!

Updated on June 04, 2022

Comments

  • Sid
    Sid about 2 years

    CBX stands for Check Boxes , i want to minimize the codes using for loop but dont know the syntax for PB to recognize concatenations on statements

    IF cbx_1.Checked = TRUE THEN
        fw_generate(1, cbx_1.Text)  
    
    END IF
    
    IF cbx_2.Checked = TRUE THEN
        fw_generate(2, cbx_2.Text)  
    
    END IF
    
    IF cbx_1.Checked = TRUE THEN
        fw_generate(3, cbx_3.Text)  
    
    END IF