Solved

VB.Net: Resuable code doubt

Posted on 2012-03-31
3
164 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 500 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to limit User Input 2 34
How to get a Powershell script to launch from Visual Studio 20 67
Need help with a query 14 39
How can I add google maps in vb.net. 2 22
Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
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…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

730 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