Results 1 to 7 of 7

Thread: Declaring Variables?

  1. #1

    Thread Starter
    Member JesusFreak's Avatar
    Join Date
    Feb 2003
    Location
    Headed for Heaven
    Posts
    57

    Question Declaring Variables?

    How Can I declare a variable in a sub that all subs can use?
    That if you confess with your mouth, "Jesus is Lord," and believe in your heart that God raised him from the dead, you will be saved.

  2. #2
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    You can create a class-level variable by declaring your variable outside of any methods, at the top of your class definition.

  3. #3

    Thread Starter
    Member JesusFreak's Avatar
    Join Date
    Feb 2003
    Location
    Headed for Heaven
    Posts
    57
    That won't work because I need to load the value of the variable from a file.
    That if you confess with your mouth, "Jesus is Lord," and believe in your heart that God raised him from the dead, you will be saved.

  4. #4
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390
    ?? why not?
    Just Declare the variable outside of all subs (at the top)

    then set the variable when needed?


    Dim X as integer

    .
    .
    .
    .

    X = whatever from your file
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  5. #5
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    Initialize the variable in the constructor.

  6. #6
    New Member
    Join Date
    Mar 2003
    Location
    Chicago, Illinois
    Posts
    9
    Declare it as a module level variable, just below the Windows Form Designer generated code.

    examples.

    For a module or Class level variable:

    Private msinNumOne as Single
    Private mbln As Boolean
    Private mdblTotal As Double

    For Procedure Level Variables:

    Dim psinNumOne as Single
    Dim pbln As Boolean
    Dim pdblTotal As Double

    Hopefully, this helps you.
    Last edited by LFJ; Mar 6th, 2003 at 05:31 PM.
    I am the Code King

  7. #7

    Thread Starter
    Member JesusFreak's Avatar
    Join Date
    Feb 2003
    Location
    Headed for Heaven
    Posts
    57
    Originally posted by [LGS]Static
    ?? why not?
    Just Declare the variable outside of all subs (at the top)

    then set the variable when needed?


    Dim X as integer

    .
    .
    .
    .

    X = whatever from your file
    I was going to make it a constant but I guess that dons't really mater.
    That if you confess with your mouth, "Jesus is Lord," and believe in your heart that God raised him from the dead, you will be saved.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width