Home | Forums | Contact | Search | Syndication  
 
 [login] [create account]   Sunday, August 24, 2025 
 
slxdeveloper.com Community Forums  
   
The Forums on slxdeveloper.com are now retired. The forum archive will remain available for the time being. Thank you for your participation on slxdeveloper.com!
 Architect Forums - SalesLogix Scripting & Customization
Forum to discuss writing script in Architect plugins for SalesLogix & general SalesLogix customization topics (for Windows client only). View the code of conduct for posting guidelines.
Forums RSS Feed


 Back to Forum List | Back to SalesLogix Scripting & Customization | New ThreadView:  Search:  
 Author  Thread: Looping through controls in a form.
Greg Jebb
Posts: 25
 
Looping through controls in a form.Your last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 18 Jul 08 7:47 AM
I've been asked to modify the Accounts Details view in SLX (7.02) so that the background turns Red/Green based on the happiness of the account.

Changing the background colour of the form alone looks terrible with all the buttons and labels over the top of it, so i decided I should modify the labels to use the same BG colour aswell, the only problem is that there are a lot of them and more will be added over time. I dont want to have to be writing "lblAccount.color = wclSeaGreen" over and over again.

Using some info I found in one Ryans guides I was able to loop through all controls in the form. My problem however is that I have no idea how to identify labels from other controls. (Not every label has been prefixed with "lbl"). Is there an easy way to ID them?

for i = 0 to frmAccountDetail.ControlCount - 1
???? if frmAccountDetail.Controls(i)."I WOULD LIKE TO SAY TYPE" = "Label" then
frmAccountDetail.Controls(i).color = clColor
end if
next

If i stick in an "On error resume next" the for loop does work (less the control type test) and changes every control that can be changed to green, but I'm only after labels at the mo.

Any ideas guys?


[Reply][Quote]
Steve Robertson
Posts: 146
 
Re: Looping through controls in a form.Your last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 18 Jul 08 8:27 AM

If TypeName(frmAccountDetail.Controls(i)) = "Label"

Cheers,

Steve
[Reply][Quote]
Greg Jebb
Posts: 25
 
Re: Looping through controls in a form.Your last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 18 Jul 08 10:01 AM
Nice one, thanks.

Now if I could just figure out how to stop the buttons looking like crap... BG Colour will go green but the 3d effect colours arent customizable.

Cheers

Greg
[Reply][Quote]
Steve Robertson
Posts: 146
 
Re: Looping through controls in a form.Your last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 18 Jul 08 10:19 AM
Hi Greg,

For a button you need to turn off the UseThemes:
m_form.Controls(i).Color = Color
m_form.Controls(i).UseThemes = False

Cheers,

Steve
[Reply][Quote]
Greg Jebb
Posts: 25
 
Re: Looping through controls in a form.Your last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 18 Jul 08 10:24 AM
I've tried that, you still get a grey border around the button.

Also you cant change usethemes on the fly (unless I was doing it wrong).

I think I may resort to replacing the buttons with labels that have on click events.

Or giving up and just make the text box containing the Account name turn green/red.

Or even better: objSLXDB.ExecuteSQL "DROP ACCOUNT"#

Cheers
[Reply][Quote]
Steve Robertson
Posts: 146
 
Re: Looping through controls in a form.Your last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 18 Jul 08 10:56 AM
Hi Greg,

The following should work for button the usethemes on the fly:
If TypeName(frmAccountDetail.Controls(i)) = "Button" Then
frmAccountDetail.Controls(i).UseThemes = False
frmAccountDetail.Controls(i).Color = = clColor
End If

Choice is yours on next steps!

Be aware that checkboxes also are a pain too - need to remove the text portion and change to a label so that the color will change...

Cheers,

Steve
[Reply][Quote]
Greg Jebb
Posts: 25
 
Re: Looping through controls in a form.Your last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 18 Jul 08 11:38 AM
You're right. Me being an idiot did it the same way as a boolean in the SLX DB (.usethemes = "F")

I think it's going to look messy, so I'm just going to change the BG of the Account textbox.

But the typename() will be very useful in the future. Thanks
[Reply][Quote]
Mike Spragg
Posts: 1226
Top 10 forum poster: 1226 posts
 
Re: Looping through controls in a form.Your last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 19 Jul 08 2:33 AM
Greg, no matter what you do here - the ultimate form will look like crap ! The mix of colour, bevel, pane and so on just doesn't lend itself to be colorised liek this.

I'd suggest to alternatives - have a horizontal bar running complete width of the form and change the colour of this - and put some text in there too - e.g. "Great Customer!" - as this is enough to focus the eye and highlight - without getting seasick (as opposed to seagrape).

Or, put a web control on the right - and use HTML to create a nice looking "Status" panel.

Regards
Mike
[Reply][Quote]
Greg Jebb
Posts: 25
 
Re: Looping through controls in a form.Your last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 22 Jul 08 7:58 AM
Indeed it did.

The higher-ups agreed, and we've settled on changing the colour of the textbox that contains the account name. (We barely have space on the form for our current controls, let alone space to stick a green/red bar up the top)

Thanks a lot guys

Greg
[Reply][Quote]
Mike Spragg
Posts: 1226
Top 10 forum poster: 1226 posts
 
Re: Looping through controls in a form.Your last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 22 Jul 08 8:20 AM
Thought so ! I get asked for this a lot - and always turn it down as a bad idea.
Also, have you thought about a tab control in the main views? You can separate data into the tabs - most important at the front and others for other data. This is a tabcontrol on the mv - not a tab in the tabset. Worth considering if you have a lot of fields.
[Reply][Quote]
Paul Hutchison
Posts: 30
 
Re: Looping through controls in a form.Your last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 06 Aug 08 6:21 PM
Hi,

I've stumbled across this bit of code and realised how much easier it would make life, but I'm having some difficulty getting it working!

All I am trying to do is enable / disable controls on a panel, so I have used the following (to enable the fields):

For i = 0 to pnl_Printer.ControlCount - 1
pnl_Printer.Controls(i).Enabled = True
Next

But it does not work, I get an error when the code is called.

Any ideas, or can this only be used for forms rather than for panels?
[Reply][Quote]
Steve Robertson
Posts: 146
 
Re: Looping through controls in a form.Your last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 07 Aug 08 3:09 AM
Hi Paul,

Just disable/enable the panel as you require:

pnl_Printer.Enabled = False

or

pnl_Printer.Enabled = True

Cheers,

Steve
[Reply][Quote]
Paul Hutchison
Posts: 30
 
Re: Looping through controls in a form.Your last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 07 Aug 08 3:22 AM
I will now hang my head and sulk in the corner.

Why do I always look for the difficult way to do things!!??!!

Thanks for pushing me in the right direction!
[Reply][Quote]
Mike Spragg
Posts: 1226
Top 10 forum poster: 1226 posts
 
Re: Looping through controls in a form.Your last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 07 Aug 08 3:45 AM
Unfortunately, the side effect is that all controls are disabled too - no hyperlink, no copy/paste.
Did you do this : http://www.slxdeveloper.com/page.aspx?action=viewarticle&articleid=70
You could probably simplify it for your case.
[Reply][Quote]
Paul Hutchison
Posts: 30
 
Re: Looping through controls in a form.Your last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 07 Aug 08 7:19 AM
Mike,

Yes I've had a look at that, and I have tried to implement it and come across errors. Basically I have a form with (literally) hundreds of controls on it, some on the form but the majority are on 1 of 6 panles which I set Visible as required (the panels are on top of each other).

I have three panels which are visible at the same time, but I only want the controls on one to be enabled at a time.

I would really like to use this code as it is by far the simplest solution, but It would be very difficult to identify which controls should be enabled and which disabled using the TypeName. Is there any way of using the 'Name' of the control - I have been very strict as to the naming convention, so I can guarantee that doing it this way would ensure the correct controls would be disabled.

For example: "If Left(Name(Controls(i)), 3) <> "ABC" Then Controls(i).Enabled = False" would do exactly what I wanted, but the Name property does not return the name of the control?

Regards,
Paul.
[Reply][Quote]
Mike Spragg
Posts: 1226
Top 10 forum poster: 1226 posts
 
Re: Looping through controls in a form.Your last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 07 Aug 08 7:24 AM
Yup, you can:

============================
Dynamic Objects/VariableName
============================

> For T = 1 to 58
> Execute "MyControl" & T & ".Enabled = True"
> Next

So, if they are numbered sequentially (or you use an array/whatever) - you can do that.

Mike
[Reply][Quote]
Paul Hutchison
Posts: 30
 
Re: Looping through controls in a form.Your last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 07 Aug 08 7:38 AM
Although I can see the benefit, due to my naming convention this would still be fairly messy.

I have named the controls PanleName_Label_01, PanelName_Text_01, etc. so I'd have to do a seperate loop for each type of control, and for each panel!

If there is a way of using the TypeName(Controls(i)) but to get the neam of the control rather than the Type it would be 3-4 lines of code.

I may be expecting too much, but woudl NameName(Controls(i)) work??? I'm going to try...

...No, that didn't work!
[Reply][Quote]
Steve Robertson
Posts: 146
 
Re: Looping through controls in a form.Your last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 07 Aug 08 10:04 AM
Hi Paul,

What about the following:


Dim x
For x = 0 To frmTest.ControlCount - 1
msgbox frmTest.Controls(x).Name
Next


Cheers,

Steve
[Reply][Quote]
Paul Hutchison
Posts: 30
 
Re: Looping through controls in a form.Your last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 07 Aug 08 10:25 AM
Steve,

You really are coming to my aid today!

yes, this has done the trick.

Looking at the code, the fact that I had "Controls(i).Enabled = False", I should have really guessed that I could reference "Controls(i).Name".

I'm reminded of a phrase regarding wood & trees.

Thanks again.
Paul.
[Reply][Quote]
Steve Robertson
Posts: 146
 
Re: Looping through controls in a form.Your last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 07 Aug 08 10:28 AM
Hi Paul,

No problems, glad to help!

Cheers,

Steve
[Reply][Quote]
Ryan Farley
Posts: 2265
slxdeveloper.com Site Administrator
Top 10 forum poster: 2265 posts
 
Re: Looping through controls in a form.Your last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 07 Aug 08 11:23 PM
Hi Paul,

Optionally, you could so something like add a value in the tag property of the controls you want to disable. So in the loop you only set it as enabled=false if the tag value equals something like "1". Then just add the "1" in the controls you want to disable (or do it the other way around by flagging the ones you want left alone. This way you don't need to hard code all the control names.

-Ryan
[Reply][Quote]
Paul Hutchison
Posts: 30
 
Re: Looping through controls in a form.Your last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 08 Aug 08 3:01 AM
Ryan,

Thanks for the hint. In this situation I have six panels,a dn the user is able to switch between them, so I'd have to have each one with a different number in the Tag, an to be honest if anybody else does any development, getting them to remember to do this would be more difficult than getting them to remember to name the controls correctly!

Thanks all the same, I may well use this elsewhere.
Paul.
[Reply][Quote]
 Page 1 of 1 
  You can subscribe to receive a daily forum digest in your user profile. View the site code of conduct for posting guidelines.

   Forum RSS Feed - Subscribe to the forum RSS feed to keep on top of the latest forum activity!
 

 
 slxdeveloper.com is brought to you courtesy of Ryan Farley & Customer FX Corporation.
 This site, and all contents herein, are Copyright © 2025 Customer FX Corporation. The information and opinions expressed here are not endorsed by Sage Software.

code of conduct | Subscribe to the slxdeveloper.com Latest Article RSS feed
   
 
page cache (param): 8/24/2025 6:23:27 PM