6/17/2025 11:29:31 PM
|
|
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!
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.
|
|
|
|
Fire code from checkbox checked using space bar - Bizzaro
Posted: 11 Apr 07 4:06 PM
|
fiogf49gjkf0d I am running some validation code when a user clicks a checkbox. If they use the mouse, no problem. If they tab into the field and check the box with the space bar, the validation routine doesn't evaluate properly unless you uncheck the box again with the space bar. This is obviously no good.
However, If I uncomment this line ['msgbox cbapproved.Text] in the CheckValidateCodeName sub the routine evaluates properly on the first press of the space bar.. Wierd or what.. Any thoughts? Thanks
Here is the code: Sub cbApprovedMouseUp(Sender, Button, X, Y) CheckValidateCodeName End Sub
Sub cbApprovedKeyPress(Sender, ByRef Key) CheckValidateCodeName End Sub
Sub CheckValidateCodeName '*************************************************** 'Following code moved from cbApprovedMouseUp to allow it to be 'called from cbApprovedKeyPress also '*************************************************** 'Validates that Code Name is a unique value when 'this opportunity is approved. '*************************************************** 'msgbox cbapproved.Text if cbapproved.Text = "T" then cbapproved.Text = ValidateCodeName(txtcodename.Text) if cbapproved.Text = "T" then txtcodename.ReadOnly = true txtcodename.Color = cl3DLight else txtcodename.ReadOnly = false txtcodename.Color = clWindow end if else txtcodename.ReadOnly = false txtcodename.Color = clWindow end if End Sub |
|
|
|
Re: Fire code from checkbox checked using space bar - Bizzaro
Posted: 11 Apr 07 6:19 PM
|
Couple of suggestions: 1) Pass Sender to CheckValidateCodeName. Hardcoding cbApproved works but you could just use CheckValidateCodeName Sender and replace cbapproved in CheckValidateCodeName with Sender. You can then move your routine to any form as long as you hook up the proper events. 2) If(cbApproved.Text = "T") is used twice. Do something like stringTemp = cbApproved.Text then check the value of stringTemp. Hooking to the control and then performing certain operations multiple times can yield weird results. 3) I just realized why #2 exists. Set cbApproved.Text last. Changing it mid-routine and then using an if statement to evaluate the remaining value is difficult to debug. Use a temporary variable if necessary then update the control last. 4) You can evaluate the Key parameter in OnKeyPress to be the spacebar (whatever the Ascii equivalent is) and then do further processing only if spacebar was pressed. In fact, it might not be a bad idea to isolate the problem to that routine instead of the shared one.
There's a pattern to my suggestions: controls are finicky and it's best to alter their states RARELY. Using temp variables creates added complexity but you are almost guaranteeing control behavior. I used to code this way in Legacy-land and it was far less forgiving than VBScript. I didn't think it was necessary when I first started working in 6.1 but I quickly found that temp variables made things far easier. |
|
|
|
Re: Fire code from checkbox checked using space bar - Bizzaro
Posted: 12 Apr 07 8:19 AM
|
Thanks Jeremy. Actually, the code behaves the same like this (this was how it was originally coded - notice the keypress event calling the sub directly and the msgbox that causes the code to work correctly in the keypress sub):
Sub cbApprovedKeyPress(Sender, ByRef Key) 'msgbox cbapproved.Text Sub cbApprovedMouseUp(Sender, 4, 4, 4) 'not sure what values actually where here, but they called the sub as expected CheckValidateCodeName End Sub
Sub cbApprovedMouseUp(Sender, Button, X, Y) '*************************************************** 'Validates that Code Name is a unique value when 'this opportunity is approved. '*************************************************** if cbapproved.Text = "T" then cbapproved.Text = ValidateCodeName(txtcodename.Text) if cbapproved.Text = "T" then txtcodename.ReadOnly = true txtcodename.Color = cl3DLight else txtcodename.ReadOnly = false txtcodename.Color = clWindow end if else txtcodename.ReadOnly = false txtcodename.Color = clWindow end if End Sub
I think I am going to take the checkbox out of the tab order as it is at the very end of it anyway.. |
|
|
|
Re: Fire code from checkbox checked using space bar - Bizzaro
Posted: 13 Apr 07 11:35 AM
|
If you wanted to simply disable KeyPress doing anything you can always set Key = 0. That stops the current key from being consumed so you can do things like block alphanumeric characters when you want an integer only textbox. I'm not entirely sure how it'd work with a checkbox but I would think that it would prevent it from changing state.
Basically what you're saying is that originally the MouseUp event had all of the logic. All KeyPress did was call that sub. The current code you pasted behaves exactly the same as the original? If that's the case then at least you know your logic is correct. That would mean that whatever problem you're having lies in the specific KeyPress/MouseUp events. Sometimes they can get tricky as I remember certain controls when .Text would change, it would also fire off subsequent UI events like OnClick. |
|
|
|
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!
|
|
|
|
|
|
|
|