|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
How Can I Do This?I have a Function that I would like to pass the form name and the textbox name to. ----------------------------------------- Function DoSomeThing(byref frmOBJ as Object, byref txtOBJ as TextBox) as integer frmOBJ.txtOBJ.text = "Some text goes here" DoSomeThing = 0 End Function ------------------------------------------ When I call this Function, I pass two objects, the FormName and the TextBox name. -------------------------------------- dim answ as integer = DoSomeThing(frmDisplay, txtDisplay) --------------------------------------- I get an error saying that frmDisplay.txtOBJ doesn't exist. Is there a way to pass two objects to the function and have both of them be replaceable? Thanks for any input Henry,
Why not just have a function that accepts a textbox? Kerry Moorman Show quoteHide quote "Henry Jones" wrote: > Using VB.NET 2005. > > I have a Function that I would like to pass the form name and the textbox > name to. > > ----------------------------------------- > Function DoSomeThing(byref frmOBJ as Object, byref txtOBJ as TextBox) as > integer > > frmOBJ.txtOBJ.text = "Some text goes here" > > DoSomeThing = 0 > > End Function > ------------------------------------------ > > > When I call this Function, I pass two objects, the FormName and the TextBox > name. > > -------------------------------------- > dim answ as integer = DoSomeThing(frmDisplay, txtDisplay) > --------------------------------------- > > > > > I get an error saying that frmDisplay.txtOBJ doesn't exist. > > Is there a way to pass two objects to the function and have both of them be > replaceable? > > Thanks for any input > > > I condensed the code for the example here, but there are more things going
on in the routine and the result gets passed to the textbox. I would like to call the function from many different forms and I thought I could pass the form and the textbox to it. Just wanted to see if it could be done. Yes, there are probably better ways of doing it, but hey, if it can be done, I am curious now. Thanks Show quoteHide quote "Kerry Moorman" <KerryMoor***@discussions.microsoft.com> wrote in message news:D0EDCFEE-A81D-4F1B-B52D-979DABE7742A@microsoft.com... > Henry, > > Why not just have a function that accepts a textbox? > > Kerry Moorman > > > "Henry Jones" wrote: > >> Using VB.NET 2005. >> >> I have a Function that I would like to pass the form name and the textbox >> name to. >> >> ----------------------------------------- >> Function DoSomeThing(byref frmOBJ as Object, byref txtOBJ as TextBox) as >> integer >> >> frmOBJ.txtOBJ.text = "Some text goes here" >> >> DoSomeThing = 0 >> >> End Function >> ------------------------------------------ >> >> >> When I call this Function, I pass two objects, the FormName and the >> TextBox >> name. >> >> -------------------------------------- >> dim answ as integer = DoSomeThing(frmDisplay, txtDisplay) >> --------------------------------------- >> >> >> >> >> I get an error saying that frmDisplay.txtOBJ doesn't exist. >> >> Is there a way to pass two objects to the function and have both of them >> be >> replaceable? >> >> Thanks for any input >> >> >> In this scenario, you do not have to use frmObj.
Just assign the string to txtObj. If you want to use frmObj, you have to use the real name of the textbox in the form, like ctype(frmObj.Controls(txtObj.Name),Textbox).text = ... Henry Jones wrote: Show quoteHide quote > Using VB.NET 2005. > > I have a Function that I would like to pass the form name and the textbox > name to. > > ----------------------------------------- > Function DoSomeThing(byref frmOBJ as Object, byref txtOBJ as TextBox) as > integer > > frmOBJ.txtOBJ.text = "Some text goes here" > > DoSomeThing = 0 > > End Function > ------------------------------------------ > > > When I call this Function, I pass two objects, the FormName and the TextBox > name. > > -------------------------------------- > dim answ as integer = DoSomeThing(frmDisplay, txtDisplay) > --------------------------------------- > > > > > I get an error saying that frmDisplay.txtOBJ doesn't exist. > > Is there a way to pass two objects to the function and have both of them be > replaceable? > > Thanks for any input > > Public Sub DoSometing(byref txt as TextBox)
txt.text = [YOUR VALUE] End Sub of public function DoSomething(byref frmObj as [Form Type I.e. frmMain], byref txtOBJ as TextBox) 'option 1 ctype(frmObj.Controls(txtOBJ.name),Textbox).text = [YOUR VALUE] 'option 2 txtObj.text = [YOUR VALUE] return 0 end function Show quoteHide quote "Henry Jones" <he***@yada.com> wrote in message news:u$jwZ8r$GHA.4496@TK2MSFTNGP02.phx.gbl... > Using VB.NET 2005. > > I have a Function that I would like to pass the form name and the textbox > name to. > > ----------------------------------------- > Function DoSomeThing(byref frmOBJ as Object, byref txtOBJ as TextBox) as > integer > > frmOBJ.txtOBJ.text = "Some text goes here" > > DoSomeThing = 0 > > End Function > ------------------------------------------ > > > When I call this Function, I pass two objects, the FormName and the > TextBox name. > > -------------------------------------- > dim answ as integer = DoSomeThing(frmDisplay, txtDisplay) > --------------------------------------- > > > > > I get an error saying that frmDisplay.txtOBJ doesn't exist. > > Is there a way to pass two objects to the function and have both of them > be replaceable? > > Thanks for any input >
Show quote
Hide quote
"Henry Jones" <he***@yada.com> wrote in message Something I do not understand is why you are passing both arguments by news:u$jwZ8r$GHA.4496@TK2MSFTNGP02.phx.gbl... > Using VB.NET 2005. > > I have a Function that I would like to pass the form name and the textbox > name to. > > ----------------------------------------- > Function DoSomeThing(byref frmOBJ as Object, byref txtOBJ as TextBox) as > integer > > frmOBJ.txtOBJ.text = "Some text goes here" > > DoSomeThing = 0 > > End Function > ------------------------------------------ > > > When I call this Function, I pass two objects, the FormName and the > TextBox name. > > -------------------------------------- > dim answ as integer = DoSomeThing(frmDisplay, txtDisplay) > --------------------------------------- > > > > > I get an error saying that frmDisplay.txtOBJ doesn't exist. > > Is there a way to pass two objects to the function and have both of them > be replaceable? > > Thanks for any input > reference? Since you are passing and object and a textbox (both are reference types) and you aren't "replacing" the actual object nor are you "replacing" the actual textbox instance, these do not need to be passed by reference. What I see you are trying to do is get the property of the form passed in. The property name is the name of the textbox being passed in. If you have an instance of the textbox (hence, you are passing it in via parameter), why do you need to access the property of the form (which supposedly returns the same instance as the textbox parameter, afaik)? Maybe your example is incorrect and you don't mean to be passing in an object and a textbox? HTH, Mythran No, that is not possible.
The reason is that the form doesn't have a name, so there is no way that you can identify it that way. What I think that you mean is the name of the class that the form was created from, but that can't be used to identify the instance of the form, as there can be more than one form that is created from the same class. What you need is a reference to the instance of the form, or even better, a reference to the textbox. Henry Jones wrote: Show quoteHide quote > Using VB.NET 2005. > > I have a Function that I would like to pass the form name and the textbox > name to. > > ----------------------------------------- > Function DoSomeThing(byref frmOBJ as Object, byref txtOBJ as TextBox) as > integer > > frmOBJ.txtOBJ.text = "Some text goes here" > > DoSomeThing = 0 > > End Function > ------------------------------------------ > > > When I call this Function, I pass two objects, the FormName and the TextBox > name. > > -------------------------------------- > dim answ as integer = DoSomeThing(frmDisplay, txtDisplay) > --------------------------------------- > > > > > I get an error saying that frmDisplay.txtOBJ doesn't exist. > > Is there a way to pass two objects to the function and have both of them be > replaceable? > > Thanks for any input > > Herny,
If I understand you well, than you can achieve it like this (although this goes only for owner forms).. \\\ 'This form holds two textboxes. Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles MyBase.Load Dim frm2 As New Form2 frm2.Owner = Me frm2.Show() End Sub End Class /// \\\ Public Class Form2 Private Sub Form2_Load(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles MyBase.Load useTextBox(DirectCast(Me.Owner, Form1).TextBox2) End Sub Private Sub useTextBox(ByVal txtBox As TextBox) txtBox.Text = "Some text goes here" End Sub End Class /// Show quoteHide quote "Henry Jones" <he***@yada.com> schreef in bericht news:u$jwZ8r$GHA.4496@TK2MSFTNGP02.phx.gbl... > Using VB.NET 2005. > > I have a Function that I would like to pass the form name and the textbox > name to. > > ----------------------------------------- > Function DoSomeThing(byref frmOBJ as Object, byref txtOBJ as TextBox) as > integer > > frmOBJ.txtOBJ.text = "Some text goes here" > > DoSomeThing = 0 > > End Function > ------------------------------------------ > > > When I call this Function, I pass two objects, the FormName and the > TextBox name. > > -------------------------------------- > dim answ as integer = DoSomeThing(frmDisplay, txtDisplay) > --------------------------------------- > > > > > I get an error saying that frmDisplay.txtOBJ doesn't exist. > > Is there a way to pass two objects to the function and have both of them > be replaceable? > > Thanks for any input > Henry Jones wrote:
> I have a Function that I would like to pass the form name and the textbox More likely (and usefully), you want to pass the objects themselves, > name to. /not/ their names. > Function DoSomeThing(byref frmOBJ as Object, byref txtOBJ as TextBox) as No; you're passing a Form (Type'd as Object) and a TextBox.> integer > frmOBJ.txtOBJ.text = "Some text goes here" > DoSomeThing = 0 > End Function > When I call this Function, I pass two objects, the FormName and the TextBox > name. > dim answ as integer = DoSomeThing(frmDisplay, txtDisplay) > I get an error saying that frmDisplay.txtOBJ doesn't exist. That's because the Type Object doesn't have a property/method called txtOBJ. > Is there a way to pass two objects to the function and have both of them be Yes, but in this case, you don't need to.> replaceable? Function DoSomeThing(ByVal txt As TextBox) _ As integer txt.Text = "Some text goes here" DoSomeThing = 0 End Function then call it using i = DoSomething( Form17.txtBox1 ) HTH, Phill W.
Q: Viewing an excel file
Get Calling Function Info DDE - is it available in .NET? GetChildRows error - what the f@&# ! Printing XML Formatted Report in Windows Application Diagnostic Information Collation math.round doesn't work Preferred file locations XmlDataDocument as a datasource for combobox? ListView Control |
|||||||||||||||||||||||