Solved

Storing the Variable value in vb.net

Posted on 2004-10-25
152 Views
Last Modified: 2010-05-18
Hi expert,

 In the PreRender Sub, iam getting one value(example: date) then I assigned to some variable .  While I try to use the date in the another Sub , nothing is there in the variable.
How can I get the variable value from one sub to another Sub.

Your help is much appreciated.

Regards,
Raju.
0
Question by:kbraju76
    2 Comments
     
    LVL 85

    Expert Comment

    by:Mike Tomlinson
    Declare a variable at the class level to hold the value so it can be accessed from any function/sub within the class:

    Public Class Form1
        Inherits System.Windows.Forms.Form

        Private someDate As Date

        Private Sub firstSub(ByVal d As Date)
            someDate = d
        End Sub

        Private Sub secondSub()
            ' do something with somedate
            MsgBox(someDate)
        End Sub

    End Class
    0
     
    LVL 7

    Accepted Solution

    by:
    Or pass it to the second sub as an argument:

    Public Class Form1
        Inherits System.Windows.Forms.Form

        Private Sub firstSub(ByVal d As Date)
            someDate = d
            call secondSub(somedate)
        End Sub

        Private Sub secondSub(someDate as date)
            ' do something with somedate
            MsgBox(someDate)
        End Sub

    End Class
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Course: JavaScript Coding - Massive 12-Part Bundle

    Regardless of your programming skill level, you'll go from basics to advanced concepts in a vast array of JavaScript subjects including Sammy.js, Agility.js, Ember.js, Node.js, jQuery, AJAX, Extjs, AngularJS, Knockout.js, and JSON.

    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…
    Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

    913 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

    17 Experts available now in Live!

    Get 1:1 Help Now