Using code across subs/functions?

  • Thread starter Thread starter Tony
  • Start date Start date
T

Tony

Hi All,

I'm fairly new to using VBS and have created a contact form that does some
validation, mails the content, etc. What I'm interested to know is if there
is a way to use 'common' snippets of code for several subs/functions. For
example, I would like to enter something like the following such that any
sub/function in the code can use it. Basically, I'm trying to pare down the
amount of code.

Set myInspector=Item.GetInspector
Set currentPage=myInspector.ModifiedFormPages("General")
Set txtInspectedBy=currentPage.Controls("txtInspectedBy")
Set txtProject=currentPage.Controls("txtProject")

Any help you can offer is appreciated.

Thanks & Ciao,

Tony
 
You can put the code below at the top of your VBScript code. This in effect
makes the variables global. Then you can use txtProject and those variables
anywhere in your code.
 
Thanks, Patricia. This is a lot simpler than I thought it would be. I'll
give it shot.

Thanks,

Tony
 
Hi Patricia,

I can't seem to make this work, and I'm sure it's something simple that I'm
missing. When written like this, things work:

Sub Item_CustomPropertyChange(ByVal Name)
Set myInspector = Item.GetInspector
Set currentPage = myInspector.ModifiedFormPages("General")
Set txtOtherOperation = currentPage.Controls("txtOtherOperation")
<CODE W/REFERENCE TO txtOtherOperation>
End Sub

At this point, I can use txtOtherOperation. But when written like this,
things don't:

Set myInspector = Item.GetInspector
Set currentPage = myInspector.ModifiedFormPages("General")
Set txtOtherOperation = currentPage.Controls("txtOtherOperation")

Sub Item_CustomPropertyChange(ByVal Name)
<CODE W/REFERENCE TO txtOtherOperation>
End Sub

At this point, I can't seem to access txtOtherOperation.

Any help you can offer is much appreciated.

Thanks,

Tony
 
PMJI. Try it this way:

Dim txtOtherOperation

Sub Item_CustomPropertyChange(ByVal Name)
Set myInspector = Item.GetInspector
Set currentPage = myInspector.ModifiedFormPages("General")
Set txtOtherOperation = currentPage.Controls("txtOtherOperation")
<CODE W/REFERENCE TO txtOtherOperation>
End Sub

Sub Item_CustomPropertyChange(ByVal Name)
<CODE W/REFERENCE TO txtOtherOperation>
End Sub

--
Sue Mosher, Outlook MVP
Outlook and Exchange solutions at http://www.slipstick.com
Author of
Microsoft Outlook Programming: Jumpstart
for Administrators, Power Users, and Developers
 
Hi Sue,

Don't know if you're following this thread, but your suggestion worked out
well.

Many Thanks & Ciao,

Tony


PMJI. Try it this way:

Dim txtOtherOperation

Sub Item_CustomPropertyChange(ByVal Name)
Set myInspector = Item.GetInspector
Set currentPage = myInspector.ModifiedFormPages("General")
Set txtOtherOperation = currentPage.Controls("txtOtherOperation")
<CODE W/REFERENCE TO txtOtherOperation>
End Sub

Sub Item_CustomPropertyChange(ByVal Name)
<CODE W/REFERENCE TO txtOtherOperation>
End Sub

--
Sue Mosher, Outlook MVP
Outlook and Exchange solutions at http://www.slipstick.com
Author of
Microsoft Outlook Programming: Jumpstart
for Administrators, Power Users, and Developers
 
Back
Top