Home | Forums | Contact | Search | Syndication  
 
 [login] [create account]   Wednesday, November 27, 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: Concatenate controls/commands to handle multiple controls with one function
Henk
Posts: 5
 
Concatenate controls/commands to handle multiple controls with one functionYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 23 Jan 07 10:44 AM
fiogf49gjkf0d
Hi. I'm not sure if it is possible but here's the code I want to use;


Sub CheckBoxVisibility(sControlName)

Dim checkbox, editbox, picklist

checkbox = "chk" & sControlName & ".state"
editbox = "edb" & sControlName & ".Visible"
picklist = "pkl" & sControlName & ".Visible"

if checkbox = cbChecked then

editbox = True
picklist = False

elseif checkbox = cbUnchecked then

editbox = False
picklist = True

end if

end sub

Sub chkSM1Click(Sender)

Dim sControlName
sControlName = Right(Sender.name, 3)

Call CheckboxVisibility(sControlName)

End Sub


In short, I have controls like edbSM1 (editbox), edbSM2, edbSM3, chkSM1 (checkbox), chkSM1, pklSM1 (picklist), pklSM2. It would save time to use a functions as above to use dynamic controls. But it doesn't recognize

  checkbox = "chk" & sControlName & ".state"    


as a control and its attribute, so the if doesn't work and always returns false. It should return

  chkSM1.state  


which is obviously the state of the checkbox ()chChecked or cbUnchecked.

So is it possible to concatenate controls or commands??? And if yes, how?
[Reply][Quote]
Timmus Agersea
Posts: 328
 
Re: Concatenate controls/commands to handle multiple controls with one functionYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 23 Jan 07 1:24 PM
fiogf49gjkf0d
You can access controls via their name through the Form.Controls collection.

set oCheckbox = frmAccountDetail.Controls("chk" & sControlName)
msgbox oCheckbox.State

Timmus
[Reply][Quote]
Jeremy Brayton
Posts: 491
Top 10 forum poster: 491 posts
 
Re: Concatenate controls/commands to handle multiple controls with one functionYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 23 Jan 07 6:45 PM
fiogf49gjkf0d
Ryan tipped me off to the Eval() function. Either accomplishes the same thing but Eval is useful in classes where a form isn't necessarily present.

objectControl = Eval("checkBox" + sControlName)
objectControl.Visible = true
[Reply][Quote]
Henk
Posts: 5
 
Re: Concatenate controls/commands to handle multiple controls with one functionYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 24 Jan 07 1:11 AM
fiogf49gjkf0d
Great guys, this is exactly what I was looking for!
[Reply][Quote]
RJ Eaton
Posts: 234
 
Re: Concatenate controls/commands to handle multiple controls with one functionYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 26 Jan 07 1:54 PM
fiogf49gjkf0d
Jeremy do you have a little more on the eval function.. I know .. I'm being lazy and didn't look it up just a quick use of.. such as Can I use it to loop through controls etc..

Thanks
[Reply][Quote]
Timmus Agersea
Posts: 328
 
Re: Concatenate controls/commands to handle multiple controls with one functionYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 26 Jan 07 2:02 PM
fiogf49gjkf0d
Here is some sample code that loops through all the controls, checks the type of control, and sets the appropriate properties to make them readonly:

For iControl = 0 To ControlCount - 1
Select Case (TypeName(Controls(iControl)))
Case "Edit","PickList","Memo"
Controls(iControl).ReadOnly = True
Controls(iControl).Color = Application.BasicFunctions.StringToColor("BtnFace")

Case "CheckBox"', "DataGrid"
Controls(iControl).Enabled = False

Case "ComboBox"
Controls(iControl).Enabled = False
Controls(iControl).Color = Application.BasicFunctions.StringToColor("BtnFace")

Case "LookupEdit","PopupEdit","DateTimeEdit"
Controls(iControl).ReadOnly = True
Controls(iControl).ButtonVisible = False
Controls(iControl).Color = Application.BasicFunctions.StringToColor("BtnFace")

Case "Button","Label","LinkEdit","Panel"
' Do Nothing

Case Else
'MsgBox Controls(iControl).Name & vbCrLf & TypeName(Controls(iControl))

End Select

Next


Hope that helps!

Timmus
[Reply][Quote]
RJ Eaton
Posts: 234
 
Re: Concatenate controls/commands to handle multiple controls with one functionYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 26 Jan 07 2:16 PM
fiogf49gjkf0d
Timmus, Thanks.. this is what I do now.. was looking to see if the Eval function he described above would be easier or better.. But thanks anyway

[Reply][Quote]
Jeremy Brayton
Posts: 491
Top 10 forum poster: 491 posts
 
Re: Concatenate controls/commands to handle multiple controls with one functionYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 26 Jan 07 2:56 PM
fiogf49gjkf0d
Ryan explained the Eval and Execute functions in this post: http://www.slxdeveloper.com/devhome/forum.aspx?forumid=2000&postid=4227

Eval's technical definition: http://www.devguru.com/technologies/vbscript/QuickRef/eval.html
Execute's: http://www.devguru.com/technologies/vbscript/QuickRef/execute.html

Here's how Eval helped me:

select case stringProperty
case "Text"
stringVoid = objectControl.Text
case "Enabled"
stringVoid = objectControl.Enabled
case "ReadOnly"
stringVoid = objectControl.ReadOnly
case else
Err.Raise 8
end select

is changed to this

stringVoid = Eval("objectControl." + stringProperty)

Now instead of adding a new case statement for every new property I want to trap, all I have to do is pass in the correct stringProperty parameter. It changed a potentially large switch statement (had I placed in every possible property) to a 1-liner. I would probably have more examples if I took the time to look deeper into my code base, this was just what stood out the most when the lightbulb went off.
[Reply][Quote]
Ryan Farley
Posts: 2265
slxdeveloper.com Site Administrator
Top 10 forum poster: 2265 posts
 
Re: Concatenate controls/commands to handle multiple controls with one functionYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 26 Jan 07 6:29 PM
fiogf49gjkf0d
Basically, Eval and Execute allow you to take a string of VBScript code and "run" it at runtime, just like it was part of your script.

Eval is value returning. You could check some property for example of an unknown control:

If Eval("txtSomeTextBox.Enabled") Then
'...
End If


While Execute is used to simply execute or run a string of code:

Execute "txtSomeTextBox.Enabled = False"

' or...

Execute "MsgBox txtSomeTextBox.Text"
' which could also be written as...
MsgBox Eval("txtSomeTextBox.Text")


Make sense?
[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/27/2024 2:43:14 AM