?
Solved

VB.Net: Resuable code doubt

Posted on 2012-03-31
3
Medium Priority
?
166 Views
Last Modified: 2012-03-31
Hi, i am using vb.net

I use to declare some variables. And i declare them again and again in many methods.

For example

dim strName as string
dim strNumber as Number
dim active as Boolean
.
.
.many more

What i am asking is, now it is possible to invoke a single method from multiple classes. Like wise is it possible to keep these variables declared on a single location and the use them in other methods and classes, so that i dont have to retype the variable declarations again and again on each and every method or class.

Hope my question was clear.

Thanks in advance
0
Comment
Question by:baabaa_nl
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 30

Expert Comment

by:IanTh
ID: 37790880
so are you using them as a global variable or a local variable in the function

you have not made that clear
0
 

Author Comment

by:baabaa_nl
ID: 37790972
well, it is a local variable in the function
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 2000 total points
ID: 37790993
Either:
(1) Declare them as Public in a Module.

(2) Make them Shared variables:
Public Class Form1
    Public Shared strName As String
End Class

Open in new window

Then you can use Form1.strName from anywhere

(3) Create a Class to hold the values and pass that around.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses
Course of the Month10 days, 2 hours left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question