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: Making a Check Box checked by default, when connected to a null data record
Marc Johnson
Posts: 252
 
Making a Check Box checked by default, when connected to a null data recordYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 11 Aug 06 11:04 AM
fiogf49gjkf0d
I have a check box (multiple actually) that enable or disable a calculation. By default I want these boxes checked. However, when I go to a new record and pull up the form they are unchecked making all my calculations zero.

I've tried a few different methods to force the box to be checked, including looking for a null value and setting:
.State = cbChecked (didn't work)
.Text = "T" (didn't work)

I'm guessing I'm missing something stupid.

My other option is to make the check boxes "Disable" and changing my statements to calculate on False instead of True.

Thoughts?

Marc
[Reply][Quote]
Ryan Farley
Posts: 2265
slxdeveloper.com Site Administrator
Top 10 forum poster: 2265 posts
 
Re: Making a Check Box checked by default, when connected to a null data recordYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 11 Aug 06 11:15 AM
fiogf49gjkf0d
Checkbox1.Checked = True (although IIRC setting the Text property to "T" does work for me)
[Reply][Quote]
Jeremy Brayton
Posts: 491
Top 10 forum poster: 491 posts
 
Re: Making a Check Box checked by default, when connected to a null data recordYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 11 Aug 06 1:45 PM
fiogf49gjkf0d
Your checkbox method should be in the OnChange event of the form so that it fires every time the record changes.

I use the .Checked property only because I find traditional bools (true/false) easier to deal with than "T", "F" or sometimes NULL with the SLX Boolean field.

If you have multiple checkboxes and you're looking for a way to simplify checking them all, you could place them all on a panel then loop through the Form.Controls collection to only check the checkboxes who's Parent.Name = "panelName". 2 checkboxes wouldn't benefit from this technique much but anything over 5 and this is how I do it.
[Reply][Quote]
Marc Johnson
Posts: 252
 
Re: Making a Check Box checked by default, when connected to a null data recordYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 11 Aug 06 1:51 PM
fiogf49gjkf0d
I've ended up switching my logic so the check box disables the control rather than enables it. This isn't the solution I wanted but it works. The suggestions given above work fine, the problem is that they get reset back to unchecked somewhere in my loop. I've tried to figure it out but I suspect it has a lot more to do with my logic flow than my code.

I'm caulking this up to my novice developer level. I'll email the code to anyone who wants to look at it but I honestly wouldn't expect any of you guys to optimise it for me.

Marc A. Johnson
Network Administrator
Optimum Solutions, Inc.
615-329-2313 x2240 office
615-329-4448 fax
mjohnson@optimum-solutions.com
www.optimum-solutions.com
Your only payroll, HR and time & attendance solution.
[Reply][Quote]
Jeremy Brayton
Posts: 491
Top 10 forum poster: 491 posts
 
Re: Making a Check Box checked by default, when connected to a null data recordYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 11 Aug 06 2:04 PM
fiogf49gjkf0d
I can look at it if you'd like or you could post just the method here if it's not too huge (unless of course you don't want everyone to see it, which I understand completely). I've never had that specific problem before but I have had code not behave as expected. I'm way too stubborn to work around an issue like that because most of the time the problem is something I overlook.
[Reply][Quote]
Jim Crowley
Posts: 8
 
Re: Making a Check Box checked by default, when connected to a null data recordYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 14 Aug 06 11:13 AM
fiogf49gjkf0d
Are your checkboxes bound on any of the properties (.checked, .text or .caption)? I ask this because more often than not, that is where I have problems with checkboxes and radio buttons/groups. I pretty much don't bind them at all anymore.
[Reply][Quote]
Marc Johnson
Posts: 252
 
Re: Making a Check Box checked by default, when connected to a null data recordYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 14 Aug 06 1:13 PM
fiogf49gjkf0d
Even more interesting CheckBox issues. The following sub routine is called, onClick:

Sub cbPRClick(Sender)
if cbPR.Text = "F" then
CalculatePR
else
txtPayroll.Text = 0
end if
End Sub

The problem is that this event is firing when the form is opened, without any click. I can only assume that it's working similar to onChange when the data is loaded into the checkbox from the database. The check box is bound to a field (Boolian).

Why would this event fire without a click and is there any way to prevent this?

Marc
[Reply][Quote]
Bob (RJ)Ledger
Posts: 1103
Top 10 forum poster: 1103 posts
 
Re: Making a Check Box checked by default, when connected to a null data recordYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 14 Aug 06 1:30 PM
fiogf49gjkf0d
You really cannot prevent it. However, you can use a NEW event - OnMouseUp to tell if it was a user or the "system" that did it.
--
rjl
[Reply][Quote]
Jim Crowley
Posts: 8
 
Re: Making a Check Box checked by default, when connected to a null data recordYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 14 Aug 06 1:33 PM
fiogf49gjkf0d
As far as I can tell, (someone please correct me if I am wrong), but OnClick would be similar to OnChange - pretty much as you describe. If Record A has the Boolean field as "T" and then you move to another record, as the checkbox goes to Record B whose Boolean field is "F" then the checkbox "CLICKS" itself to false.

Instead of cbPRClick, you could try cbPRMouseUp as that is actually a user clicking something.

Also consider unbinding the checkbox, throwing a textbox that is bound to your Boolean field and basing your cbPR.checked property on the txtKludge.text value. It is ugly, cumbersome and can compete for top honors in a Kludge competion, but it does work. Now if you have a ton of checkboxes, then you'd better get to work...
[Reply][Quote]
Marc Johnson
Posts: 252
 
Re: Making a Check Box checked by default, when connected to a null data recordYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 14 Aug 06 1:34 PM
fiogf49gjkf0d
Bob,

Thank you! That worked. Still other bugs to work out but that particular part worked.
[Reply][Quote]
Jeremy Brayton
Posts: 491
Top 10 forum poster: 491 posts
 
Re: Making a Check Box checked by default, when connected to a null data recordYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 14 Aug 06 6:46 PM
fiogf49gjkf0d
Jim's right in that the checkbox's OnClick behaves EXACTLY like a editboxes OnChange event.

This means that when the FORM's OnChange event fires and proceeds to change cbPR.Text from the default NULL to (database value), cbPRClick fires. This happens with EVERY CONTROL that has an OnChange event and some events behave as an OnChange event (like checkbox's OnClick).

To me it sounds like you're looking for an event that fires with your Form's OnChange event that will set everything up, then events that fire during the editing process that will make calculations on the fly. If this is the case you'll want the on-the-fly calculations to be done as little as possible because OnChange events that affect another control's Text property will trigger that control's OnChange event, causing a cascading effect that may skew the end result.

If for instance you do the calculation on a button press you can perform validation before the form closes to make sure users pressed that button. Here's rough code that'd do that (won't compile because I'm too lazy to look up sub/function exacts):

dim booleanIsCalculated

AXFormChange(Sender)
booleanIsCalculated = false
End

AXFormValidate(Sender)
if (not (booleanIsCalculated)) then
MsgBox "You must click Calculate before closing"
AXFormValidate = false
end if
End

cbPRClick(Sender)
booleanIsCalculated = true
End
[Repeat for each control in the calculation]

CalculateClick(Sender)
booleanIsCalculated = false
End

Your events are each control's OnChange, the form's OnChange and OnValidate routines, and your buttons OnClick event. The booleanIsCalculated variable is declared outside of any method so that it can be manipulated by each method in the form. Setting AXFormValidate to false (it may be true, I forget exactly) prevents the form from closing so your user will be stuck there until they click calculate. You could be nice and instead of calling a msgbox just call CalculateClick(Sender) but I like to let my users know when they're doing something wrong. Annoy them enough and they'll do it right eventually.
[Reply][Quote]
Ryan Farley
Posts: 2265
slxdeveloper.com Site Administrator
Top 10 forum poster: 2265 posts
 
Re: Making a Check Box checked by default, when connected to a null data recordYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 14 Aug 06 7:17 PM
fiogf49gjkf0d
The problem is all caused by the fact that the checkbox's "click" event fires whether the user clicked it or it was set by the binding engine. If the checkbox is bound, then as the control is populated on the OnChange event of the form, it's click event is fired. The same goes for setting the checkbox programatically.

In 6.2.3 there were some new form properties added so you can now monitor what is happening at the time the event occurs.

IsReading - means the data binding system is currently "active"
IsValidating - validate event is currently being evaluated/run
IsWriting - data is being saved to the DB
Modified - an edit has been made to the value of a data bound control

So, if you want to be sure that the click event was triggered by the user clicking the checkbox, and not that the event is just being raised it being set by the binding engine, then you could just do this:


Sub cbPRClick(Sender)
If Not IsReading
' do something here
MsgBox "The user clicked the checkbox"
End If
End Sub


This exact scenario is why these form properties were added in SP3. Makes for much cleaner code IMO.
[Reply][Quote]
Marc Johnson
Posts: 252
 
Re: Making a Check Box checked by default, when connected to a null data recordYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 18 Aug 06 10:19 AM
fiogf49gjkf0d
Ryan,

You rock. That was exactly what I was looking for. I haven't used it in the form I was working on when I asked this question but I was able to use it in a new one and it worked perfect. When I get around to working on 2.0 of my other form I'll have to use this.

Marc
[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 10:26:11 AM