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!
|
|
Counting controls on a form
Posted: 08 Aug 06 9:57 AM
|
fiogf49gjkf0d anyone have a hint how I can count the number of controls on a form. I would like to loop through them setting certain fields based on conditions, better than going and typing everysingle one
|
|
|
| |
| |
|
Re: Counting controls on a form
Posted: 08 Aug 06 1:49 PM
|
fiogf49gjkf0d Ryan,
Getting an error about needing an Object in this piece of code.. am I missing something..
*********** CODE ********************* Dim i, frm, cName, z
For i = 0 to Application.Forms.Count - 1 If Application.Forms(i).Name = "frmGCSDistributions" Then Set frm = Application.Forms(i) For z = 0 to frm.ControlCount - 1
If frm.Controls(z).Parent.Name = "pnlBetaTop" Then 'Clean the form cName = frm.Controls(z).Name If Instr(1, Left(cName,3), "pkl") or Instr(1, Left(cName,2), "ed") or Instr(1, Left(cName,2), "cb") Then cName.Text = "" End If
Else If frm.Controls(z).Parent.Name = "pnlBetaBottom" Then cName = frm.Controls(z).Name If Instr(1, Left(cName,3), "pkl") or Instr(1, Left(cName,2), "ed") or Instr(1, Left(cName,2), "cb") Then Set cName.Text = "" End If End If End If Next End If Next
Thanks
Rich |
|
|
| |
|
Re: Counting controls on a form
Posted: 08 Aug 06 2:32 PM
|
fiogf49gjkf0d Originally posted by RJ Eaton
Set cName.Text = ""
|
|
Change it to just cName.Text in your Else statement. The set threw it off. |
|
|
|
Re: Counting controls on a form
Posted: 09 Aug 06 2:06 PM
|
fiogf49gjkf0d Also, if you're on 6.1 or higher, you don't have to loop through the forms collection any more. You can do this now:
Set frm = Application.Forms["System:MyForm"]
Originally, that didn't work (when I wrote the article on this site). But as of 6.1 it was fixed. |
|
|
|
Re: Counting controls on a form
Posted: 09 Aug 06 5:01 PM
|
fiogf49gjkf0d I place a "dim oAXForm" outside of any method in the script then in the OnCreate event I call "set oAXForm = Sender". Then its oAXForm.Whatever for the life of the form. I do this for literally every form customization I've had since 6.1. I had a habit in the beginning of naming my forms incorrectly and this saved my butt at the time. I don't claim ownership of the technique. I got it from the ITToolbox discussion group which probably got it from somewhere else, like the BP newsgroup. |
|
|
|
Re: Counting controls on a form
Posted: 09 Aug 06 5:26 PM
|
fiogf49gjkf0d I dont like this approach because you lose intellisense. For this same reason I also dislike how the stock product does
set oBF = Application.BasicFunctions (or something similar)
It is challenging enough as it is working in VBScript. I will take any intellisense I can get.
Timmus |
|
|
|
Re: Counting controls on a form
Posted: 09 Aug 06 5:41 PM
|
fiogf49gjkf0d There's that late binding crap again.
I'd be content with AXForm or some kind of keyword that points to the form the script is tied to. We have Form.Script which links to the script but there is no Form property linking from the script back. That would solve the intellisense problem, and keep me from doing the set oAXForm = Sender every time. |
|
|
|
Re: Counting controls on a form
Posted: 09 Aug 06 5:49 PM
|
fiogf49gjkf0d I agree. Having a "me" or "this" or whatever that references the current form would be nice.
Timmus |
|
|
|
Re: Counting controls on a form
Posted: 09 Aug 06 5:57 PM
|
fiogf49gjkf0d I guess I am missing something. When I need to reference controls on a form, properties of the form, script subs & functions tied to the form (talking current form here), I just use the form name (or omit it altoghether)
ie:
If my form's name is "MyForm", then you could access things on the form like this (with intellisense)
val = MyForm.Edit1.Text MyForm.Caption = "New caption" MyForm.Scripts.SomeSub ' redundant since you could just call SomeSub directly
You can also omit the form name completely
val = Edit1.Text Caption = "New caption" Scripts.SomeSub ' redundant since you could just call SomeSub directly
The form name is your "this" or "Me".
You can use it to pass a form reference to some other script too (to save the need to grab it from the forms collection)
Set cls = New SomeClass Set cls.Form = MyForm cls.DoSomething
So, what am I missing from this conversation? |
|
|
|
Re: Counting controls on a form
Posted: 09 Aug 06 6:00 PM
|
fiogf49gjkf0d Correct, but it would be nice to have generic code that doesnt have to know the current form name. Not a big deal by any means.
Timmus |
|
|
| |
|
Re: Counting controls on a form
Posted: 09 Aug 06 6:16 PM
|
fiogf49gjkf0d Originally posted by Timmus Agersea
Epiphany: I am going to rename all the forms in the system to "me". |
|
Hehe. That is great. |
|
|
|
Re: Counting controls on a form
Posted: 10 Aug 06 11:10 AM
|
fiogf49gjkf0d re: dim oAXForm That was my invention in SLX v6.0/v6.1 days. Ryan Farley, myself and others were frustrated with the lack of a "me" or "this" reference and this was a compromise. I don't use this as religiously as I used to... not sure why.
|
|
|
|
Re: Counting controls on a form
Posted: 14 Aug 06 1:27 PM
|
fiogf49gjkf0d Originally posted by Timmus Agersea
Epiphany: I am going to rename all the forms in the system to "me". |
|
Humm.. now if you do that.. how do we tell one form from another? -- rjl |
|
|
|
Re: Counting controls on a form
Posted: 14 Aug 06 1:35 PM
|
fiogf49gjkf0d Originally posted by Bob (RJ)Ledger
Humm.. now if you do that.. how do we tell one form from another? -- rjl |
|
By plugin name. |
|
|
|
Re: Counting controls on a form
Posted: 14 Aug 06 4:50 PM
|
fiogf49gjkf0d I was thinking about making each form's background color unique. Once I run out of colors I will just have to tell the customer that they exceeded the supported number of forms.
Timmus |
|
|
|
Re: Counting controls on a form
Posted: 14 Aug 06 5:15 PM
|
fiogf49gjkf0d Unfortunately for your idea, you would still be able to create over 16 million forms since you can put this code in the form load event.
form.color = rgb(0,0,0) thru form.color = rgb(255,255,255)
|
|
|
|
Re: Counting controls on a form
Posted: 14 Aug 06 5:24 PM
|
fiogf49gjkf0d I am way too lazy for that. I will only support the colors in the properties pane drop down.
Timmus |
|
|
|
Re: Counting controls on a form
Posted: 14 Aug 06 6:54 PM
|
fiogf49gjkf0d I'd just place a routine that keeps the form from staying open if one with a similar name is present in the Forms collection. That way when SalesLogix goes to cache the form it'll see that one is already present, making sure users will only have access to one screen of one customization at any given time until they log back in (since Ctrl-F5 or F5 will refresh the cache).
A typical tech support call: "When I go to click on X a screen pops up then mysteriously closes every time, what gives?" "We have placed a usage restriction on your screens so that you can only do one thing at a given time because SalesLogix is a man. You can pay extra for the extended 'Put on a pretty dress' package that only costs an additional $199 per user to give you all of the functionality you want." "Does this mean I'm a little girl?" "Yep. Thank you sir and have a nice day!" |
|
|
|