|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Set textbox1.enabled = false inside a module?Ok I have form1 and lets say it has a textbox on it called textbox1.text. Now in that form1_load sub I have a command that says: my_custom_set_txt_box_properties.disabletextbox. Now I have a module called my_custom_set_txt_box_properties and in that module I have a sub that follows: sub disabletextbox textbox1.enabled = false end sub Why cant I call that module in the form1_load sub and get it to disable the textbox? I am somewhat new to module's at this stage and would greatly appreciate any help. (And keep you posted on my results ;-) ) Thanks All Dave. try this in the module:
sub disabletextbox dim myform as new form1 myform.textbox1.enabled = false end sub -- Show quoteHide quoteDaniel MCSE, MCP+I, MCP in Windows 2000/NT -------------------------------------- remove the 2nd madrid from my mail address to contact me. "David Eadie" <hack***@hotmail.com> wrote in message news:da1009c8.0504060529.35d7a284@posting.google.com... > G'Day all, > > Ok I have form1 and lets say it has a textbox on it called > textbox1.text. > > Now in that form1_load sub I have a command that says: > > my_custom_set_txt_box_properties.disabletextbox. > > Now I have a module called my_custom_set_txt_box_properties and in > that module I have a sub that follows: > > sub disabletextbox > textbox1.enabled = false > end sub > > Why cant I call that module in the form1_load sub and get it to > disable the textbox? > I am somewhat new to module's at this stage and would greatly > appreciate any help. (And keep you posted on my results ;-) ) > Thanks All > > Dave. That will just create a new Form1 and not change the textbox on the
existing Form1. A form is an object just as any other. In order to change the properties of an object, you must have a reference to that object. Inside your module sub, you say: textbox1.enabled = false Which textbox are you trying to disable? What if you had two forms each with a textbox called textbox1? How would that sub know which textbox to disable? It would be better to write the sub to take a textbox as an argument: Module MyModule Public Sub DisableTextBox(tb As TextBox) tb.Enabled = False End Sub End Module Then in your form load: MyModule.DisableTextBox(Me.TextBox1) If you need to manipulate other controls and properties of the form, you might wish to make a global variable in your module to hold a reference to your form and then in the form load, assign that variable: Module MyModule Public MyFormRef As Form1 End Module Then in Form Load: MyModule.MyFormRef = Me That way any sub in the module has access to the form and it's properties and controls. Chris Holy Wow!! Great replies from both. (I was looking at both of the
problems identified Daniel and Chris.) Many thanks!! Dave. :-) Doh! Hadn't had my Ready Brek by then. I was looking at it backwards.
Sorry. :-( -- Show quoteHide quoteDaniel MCSE, MCP+I, MCP in Windows 2000/NT -------------------------------------- remove the 2nd madrid from my mail address to contact me. "Chris Dunaway" <dunaw***@gmail.com> wrote in message news:1112795820.797298.83020@l41g2000cwc.googlegroups.com... > That will just create a new Form1 and not change the textbox on the > existing Form1. > > A form is an object just as any other. In order to change the > properties of an object, you must have a reference to that object. > > Inside your module sub, you say: > > textbox1.enabled = false > > Which textbox are you trying to disable? What if you had two forms > each with a textbox called textbox1? How would that sub know which > textbox to disable? > > It would be better to write the sub to take a textbox as an argument: > > Module MyModule > Public Sub DisableTextBox(tb As TextBox) > tb.Enabled = False > End Sub > End Module > > Then in your form load: > > MyModule.DisableTextBox(Me.TextBox1) > > If you need to manipulate other controls and properties of the form, > you might wish to make a global variable in your module to hold a > reference to your form and then in the form load, assign that variable: > > Module MyModule > Public MyFormRef As Form1 > > End Module > > Then in Form Load: > > MyModule.MyFormRef = Me > > > That way any sub in the module has access to the form and it's > properties and controls. > > Chris >
Microsoft not content with "dissing" just the Classic VB Developer Army....
Where to find good icons? In-place Updating in Datagrid not working Why doesn't timer tick Setup project registery values with app install folder in them modify HTML in code behind Event for PgUp and PgDn on Form How to get current free physical memory ? Datagrid problem How to expose a structure to VB6 from VB.NET? |
|||||||||||||||||||||||