473,718 Members | 2,046 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

passing a textbox as argument to a sub

I want to have a sub that would format my textbox based on the file
status. Since it applies to all textboxes, I would like to do a sub
with a textbox as argument

Like

sub FormatTextbox(T argetTextbox as textbox)

....

End Sub

That part is OK, but I do not know how to pass the textbox to the sub

sub a

FormatTextBox(m e.mytextbox)

end sub

does not work because it sends the default property .value.

What is the proper way to pass the textbox as the argument to the sub?

Michel
Nov 13 '05 #1
4 11197
Br
alvb <mi*******@roge rs.com> wrote:
I want to have a sub that would format my textbox based on the file
status. Since it applies to all textboxes, I would like to do a sub
with a textbox as argument

Like

sub FormatTextbox(T argetTextbox as textbox)

...

End Sub

That part is OK, but I do not know how to pass the textbox to the sub

sub a

FormatTextBox(m e.mytextbox)

end sub

does not work because it sends the default property .value.

What is the proper way to pass the textbox as the argument to the sub?

Michel

Maybe try.....

Public Sub FormatTextbox(B yRef pMyTextBox as Control)
'
End Sub

Dim MyControl as Control
Set MyControl = Me![txtMyTextBox]
FormatTextBox MyControl

My question would be why? Why not just pass the value as text and return
it formatted?

eg.

Public Function FormatText(ByVa l pText As String) As String

FormatText = Format(">", pText) 'convert to uppercase

End Function

Me![MyTextBox] = FormatText(Me![MyTextBox]

--
regards,

Bradley

A Christian Response
http://www.pastornet.net.au/response
Nov 13 '05 #2
In article <KV************ ****@news-server.bigpond. net.au>,
"Br@dley" <n0****@4u.co m> wrote:
alvb <mi*******@roge rs.com> wrote:
I want to have a sub that would format my textbox based on the file
status. Since it applies to all textboxes, I would like to do a sub
with a textbox as argument

Like

sub FormatTextbox(T argetTextbox as textbox)

...

End Sub

That part is OK, but I do not know how to pass the textbox to the sub

sub a

FormatTextBox(m e.mytextbox)

end sub

does not work because it sends the default property .value.

What is the proper way to pass the textbox as the argument to the sub?

Michel


My question would be why? Why not just pass the value as text and return
it formatted?

Actually, it is the textbox itself that I want to format, not the value
of the textbox. I want to alter things like the background color, the
font, font color, etc. All properties that belongs to a textbox.

I can copy over and over the same code for each textbox, but thought
that there must be a cleaner way to do this.

Michel
Nov 13 '05 #3
The two suggestions of declaring your argument ByRef and as Control (not
Textbox) should take care of it. You'll probably still see its .Value
property if you try to evaluate it (e.g. in the Immediate Window), but you
should be able to access properties like ForeColor, BackColor, etc.

HTH

"alvb" <mi*******@REMr ogers.com> wrote in message
news:mi******** *************** ******@news.isp .giganews.com.. .
In article <KV************ ****@news-server.bigpond. net.au>,
"Br@dley" <n0****@4u.co m> wrote:
alvb <mi*******@roge rs.com> wrote:
I want to have a sub that would format my textbox based on the file
status. Since it applies to all textboxes, I would like to do a sub
with a textbox as argument

Like

sub FormatTextbox(T argetTextbox as textbox)

...

End Sub

That part is OK, but I do not know how to pass the textbox to the sub

sub a

FormatTextBox(m e.mytextbox)

end sub

does not work because it sends the default property .value.

What is the proper way to pass the textbox as the argument to the sub?

Michel


My question would be why? Why not just pass the value as text and return
it formatted?

Actually, it is the textbox itself that I want to format, not the value
of the textbox. I want to alter things like the background color, the
font, font color, etc. All properties that belongs to a textbox.

I can copy over and over the same code for each textbox, but thought
that there must be a cleaner way to do this.

Michel

Nov 13 '05 #4
Br
alvb <mi*******@REMr ogers.com> wrote:
In article <KV************ ****@news-server.bigpond. net.au>,
"Br@dley" <n0****@4u.co m> wrote:
alvb <mi*******@roge rs.com> wrote:
I want to have a sub that would format my textbox based on the file
status. Since it applies to all textboxes, I would like to do a sub
with a textbox as argument

Like

sub FormatTextbox(T argetTextbox as textbox)

...

End Sub

That part is OK, but I do not know how to pass the textbox to the
sub

sub a

FormatTextBox(m e.mytextbox)

end sub

does not work because it sends the default property .value.

What is the proper way to pass the textbox as the argument to the
sub?

Michel


My question would be why? Why not just pass the value as text and
return it formatted?

Actually, it is the textbox itself that I want to format, not the
value of the textbox. I want to alter things like the background
color, the font, font color, etc. All properties that belongs to a
textbox.

I can copy over and over the same code for each textbox, but thought
that there must be a cleaner way to do this.

Michel


Ah missed that:)

The first suggestion (you've snipped it) would havestill helped wouldn't
it?

Public Sub FormatTextbox(B yRef pMyTextBox as Control)
With pMyTextBox
.BackColor = 0
End With
End Sub

Dim MyControl as Control
Set MyControl = Me![txtMyTextBox]
FormatTextBox MyControl
--
regards,

Bradley

A Christian Response
http://www.pastornet.net.au/response
Nov 13 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1737
by: mrambil | last post by:
Hi, I'm using PHP 4.3.3 in CLI on Win XP SP1. I use the _experimental_ w32api. It seems to work quite fine yet I cannot pass a string argument to any of my dll functions : 1) Load the w32api extension : if (!dl("php_w32api.dll")) { echo "Erreur : Impossible de chager le module php_w32api (php_w32api.dll)."; exit;
16
1639
by: Michael G | last post by:
I have an api that uses reference as arguments. void function(double z, short &x, short &y){} some calculations are done on z and then the results are being passed back out in x and y. The values the i need to pass to this function are pointer to shorts. short * x1; short * y1;
2
1425
by: Rudy Moore | last post by:
Is this valid c++? f()'s argument is a reference, but has a default value. It compiles with gcc 3.3.3 class A {}; void f(const A& a = A()) {} int main() { f(); return 0;
3
6779
by: Scott | last post by:
What is the proper syntax for sending an argument from a form contol to a subroutine in a module? For instance, from a textbox on a form I call a module subroutine from the textbox's OnUpdate event. I want to pass the form's name to the the Module subroutine. What is the proper syntax for the textbox event to pass the form name and what is the correct syntax in the module subroutine to accept the form name as an argument? Thanks Scott
1
2946
by: sofakingfree | last post by:
I keep getting an invalid property assignment error when tring to reference a subform. All I am trying to do is substitute this: Forms!!.SetFocus for this: FormAndSubForm.SetFocus
1
2023
by: Parasyke | last post by:
Please forgive this newbie, but can someone help with what is sure to be simple for the veterans of VB.net: I have a form with TextBox1 and a button, Button1. I need to pass the value of the textbox (in this case a URL) into the string which controls the opening of Internet Explorer and going to the typed site. I can get as far as opening Internet Explorer and opening a hard-coded
5
8336
by: Nicholas | last post by:
Hello, i need to pass an argument to window.open but it seems it wont work. What am i doing wrong? This in in head: <SCRIPT LANGUAGE="JavaScript"> <!-- function nw(a,b){ myWindow = window.open("", "Window", 'toolbar,width=a,height=b') //-->
2
2043
by: ruk | last post by:
Hi all, I have craeated a windows service in C# which monitors the user's request to the server. It should display the username and the Loggeddatetime of the user who all are loggedin to the server for the every fifteen minutes.. Its working .But am giving the username as hotcoded one. Now what i want to know is how to pass the username as an argument to the service.Should i use the command line arguments.
1
4197
by: KayC | last post by:
Hi I am using Access2002 I have a form with 5 text boxes which are parameters to a function 3 parameters are optional in the function How do I pass the empty textbox values to a optional parameter? Completely stumped on how to do this Any ideas? Regards KC
1
7206
by: tina2626 | last post by:
how can i pass textbox value to gridview using C#.net at runtime not using database values. i m hving textbox1 and gridview1. can anyone suggest me to do this coding in ASP.NET(C# language).
0
8826
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8722
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9204
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9115
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6648
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5971
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4481
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4740
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2122
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.