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!
|
|
Concatenate controls/commands to handle multiple controls with one function
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? |
|
|
| |
| |
| |
| |
|
Re: Concatenate controls/commands to handle multiple controls with one function
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 |
|
|
| |
| |
|
Re: Concatenate controls/commands to handle multiple controls with one function
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? |
|
|
|