By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,640 Members | 1,331 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,640 IT Pros & Developers. It's quick & easy.

How Can I Do This?

P: n/a
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
Nov 2 '06 #1
Share this Question
Share on Google+
8 Replies


P: n/a
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
Nov 2 '06 #2

P: n/a
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:
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

Nov 2 '06 #3

P: n/a
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

"Kerry Moorman" <Ke**********@discussions.microsoft.comwrote in message
news:D0**********************************@microsof t.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

Nov 2 '06 #4

P: n/a
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

"Henry Jones" <he***@yada.comwrote in message
news:u$**************@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
Nov 2 '06 #5

P: n/a


"Henry Jones" <he***@yada.comwrote in message
news:u$**************@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
Something I do not understand is why you are passing both arguments by
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


Nov 3 '06 #6

P: n/a
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:
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

Nov 6 '06 #7

P: n/a
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
///
"Henry Jones" <he***@yada.comschreef in bericht
news:u$**************@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

Nov 6 '06 #8

P: n/a
Henry Jones wrote:
I have a Function that I would like to pass the form name and the textbox
name to.
More likely (and usefully), you want to pass the objects themselves,
/not/ their names.
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)
No; you're passing a Form (Type'd as Object) and a TextBox.
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
replaceable?
Yes, but in this case, you don't need to.

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.
Nov 6 '06 #9

This discussion thread is closed

Replies have been disabled for this discussion.