Home | Forums | Contact | Search | Syndication  
 
 [login] [create account]   Tuesday, November 26, 2024 
 
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: Dynamically Set Control Properties in v6.2
Brett Willis
Posts: 9
 
Dynamically Set Control Properties in v6.2Your last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 26 Oct 06 3:15 PM
fiogf49gjkf0d
One very useful method of dynamically programming control properties in v5.2 was to get and set the control properties using variables. For Example, if you had 8 check boxes and 8 corresponding textboxes, you could easily set the visibility of each textbox based on the corresponding checkbox being checked or not by calling a common script like this:

For i = 1 to 8
If GetPropertyOf("CheckBox" & i, "Text") = "T" then
SetPropertyOf "TextBox" & i, "Visible", "False"
Else
SetPropertyOf "TextBox" & i, "Visible", "True"
End If
Next i

Anyone know of an equivalent way of doing this in v6.2?

Thanks.

Brett
[Reply][Quote]
Ryan Farley
Posts: 2265
slxdeveloper.com Site Administrator
Top 10 forum poster: 2265 posts
 
Re: Dynamically Set Control Properties in v6.2Your last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 26 Oct 06 3:23 PM
fiogf49gjkf0d
You can access a form's control collection and easily iterate through the controls. Take a look here for more on that: http://saleslogixblog.com/rfarley/archive/2004/07/26/925.aspx

-Ryan
[Reply][Quote]
Ryan Farley
Posts: 2265
slxdeveloper.com Site Administrator
Top 10 forum poster: 2265 posts
 
Re: Dynamically Set Control Properties in v6.2Your last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 26 Oct 06 3:32 PM
fiogf49gjkf0d
Another alternative is to use VBScipt's Execute function (Refer to the VBScript docs for full reference). The Execute statement allows you to execute a string of code as part of the script. Also, the Eval function will do the same but return the result of an evaluation.

You could rewrite the code you posted as this:

For i = 1 To 8
If Eval("CheckBox" & i & ".Checked") Then
Execute "TextBox" & i & ".Visible = False"
Else
Execute "TextBox" & i & ".Visible = True"
End If
Next


Something like that anyway. Although, IMO using the controls collection, like I posted before, would provide a more elegant solution.
[Reply][Quote]
Brett Willis
Posts: 9
 
Re: Dynamically Set Control Properties in v6.2Your last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 26 Oct 06 3:57 PM
fiogf49gjkf0d
I can see how it can be done using the VB Eval and Execute functions, but looking at the more elegant solution of iterating through the form controls, I still can't see how that would work.

If you check chk8, how would you ONLY make the corresponding txt8 control visible? I can easily determine that it was the chk8 control that invoked the script, and that the chk8.text value is T or F, but I'm not clear on how I would then SET the txt8.visible = TRUE or FALSE. I can see how to set ALL text boxes to visible, but not how to only do it for a specific one.

Muchos Gracias!
[Reply][Quote]
Ryan Farley
Posts: 2265
slxdeveloper.com Site Administrator
Top 10 forum poster: 2265 posts
 
Re: Dynamically Set Control Properties in v6.2Your last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 26 Oct 06 4:14 PM
fiogf49gjkf0d
It's been a while since I tried this, but IIRC, you can reference items in the collection by index or name:

If Controls("CheckBox1").Checked Then Controls("TextBox1").Visible = False


But like I said, it's been a while since I tried that so I might be remembering it wrong (I'll leave it to you to test )
[Reply][Quote]
Jeremy Brayton
Posts: 491
Top 10 forum poster: 491 posts
 
Re: Dynamically Set Control Properties in v6.2Your last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 27 Oct 06 2:10 PM
fiogf49gjkf0d
Big duh moment: I didn't know about Eval or Execute and I've worked around it years ago. Sad.

If there are 10 controls or less, I generally hard-code whatever I need. If hard-coding isn't an option I'll either use an array to link the controls somehow or use similar Control.Name properties, creating a map of sorts. I'd then loop through the array setting the properties accordingly. I prefer arrays because it allows me to build everything once looping through the control collection but if something is screwy it won't have to halt mid-stream.

Taking the mapping idea a step further, I place all of the controls on the same panel. Then I can check to make sure Control.Parent.Name = "panelWhatever" and only affect controls on that panel. GroupBoxes and Tabs also have Parent.Name properties I believe, so controls placed on those can utilize the technique as well. An added side effect is the fact that all of the controls are created within the same space, so they should be close together when you loop through the controls collection.
[Reply][Quote]
Sal Passanisi
Posts: 1
 
Re: Dynamically Set Control Properties in v6.2Your last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 28 Oct 06 4:41 PM
fiogf49gjkf0d
How many controls are you talking about? If it’s just a few, I would agree with Jeremy's previous post and leave them hard-coded.

Such an optimization, in my opinion, would make the supporting code a bit obscure and would potentially affect future maintenance or extension the affected form.

There would have to be a sound justification like demonstrating some sort of performance gain.

Alternatively, if the controls you wish to hide are functionally related to each other, you can place them on one or more Panels and simply hide the panel by setting its “Visible” property to False.
[Reply][Quote]
Doug Miller
Posts: 20
 
Re: Dynamically Set Control Properties in v6.2Your last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 29 Oct 06 9:30 AM
fiogf49gjkf0d
To go along with what Ryan said, you can use the name of the control with the Controls collection. First, make sure your Textbox and Checkbox have similar names( [txt1 | chk1] or [txtQuestion1 | chkQuestion1])

Then, have each checkbox point to a common OnClick event. Inside that event, take out the first 3 characters of the controls name and build your textbox name

dim commonname
dim txtname

'common name of controls excludes the first 3 characters here, change code to reflect your naming convention
commonname = right(Sender.Name, len(Sender.name) - 3)
txtname = "txt" & commonname


Now that we have the name of the Textbox, set its visibility

Controls(txtname).Visible = Sender.Checked
[Reply][Quote]
Brett Willis
Posts: 9
 
Re: Dynamically Set Control Properties in v6.2Your last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 30 Oct 06 8:53 AM
fiogf49gjkf0d
Thanks, Doug. That is actually what I was looking for. I didn't realize you could pass the control name built into a variable into the Controls(var) object property.

Knowing about the Eval and Execute methods is very helpful too. Thanks to all.
[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 © 2024 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): 11/26/2024 8:32:12 PM