Solved

VB.Net: Resuable code doubt

Posted on 2012-03-31
3
160 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
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 85

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

747 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now