Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

VB.Net: Resuable code doubt

Posted on 2012-03-31
3
Medium Priority
?
168 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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

609 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