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

x
?
Solved

Static variable?

Posted on 2006-10-27
8
Medium Priority
?
256 Views
Last Modified: 2010-04-23
'Is okay
 Private _HasStandardRights As Boolean = True
'Is okay
Private _SpecialRightsLogic As Boolean = True
'Cannot do this?
Static _HasBeenMadeVisibleOnce As Boolean = False


How do I properly declare a static variable in VB .NET?
0
Comment
Question by:Tom Knowlton
[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
  • 5
  • 2
8 Comments
 
LVL 17

Assisted Solution

by:ZeonFlash
ZeonFlash earned 800 total points
ID: 17821999
Assuming that you are trying to create a static class member, no that is not valid.  Class members are "static" throughout the life of the class object.  You can only declare a static variable inside of a Sub/Function.

Public Class Form1
    Inherits System.Windows.Forms.Form

      'NOT valid
      Static _HasBeenMadeVisibleOnce As Boolean = False

      Private Sub MySub()
            'Valid
            Static _HasBeenMadeVisibleOnce As Boolean = False
      End Sub

End Class
0
 
LVL 30

Accepted Solution

by:
Alexandre Simões earned 1200 total points
ID: 17822048
Hi...

Take a look: http://msdn2.microsoft.com/en-us/library/z2cty7t8.aspx

Is this what you're looking for? Or are you trying to do recreate the Static behavior of C#?
If so, c# 'static' is named 'Shared' in VB.

Alex
0
 
LVL 5

Author Comment

by:Tom Knowlton
ID: 17822083
Okay...got it, I think:


Protected Overrides Sub OnVisibleChanged(ByVal e As System.EventArgs)

        'Tom Knowlton
        'To fix bug 152
       
        Static _bHasBeenMadeVisibleOnce As Boolean = False
   

        If Me.Visible = True And _bHasBeenMadeVisibleOnce = False  Then
          SearchEquipment()
          _bHasBeenMadeVisibleOnce = True
        End If
    End Sub




My intent is that SearchEquipment   ONLY   fires the first time the form is made visible.


If my approach is not best-practice, I welcome suggestions!!  


Thanks,

Tom
0
Independent Software Vendors: 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!

 
LVL 5

Author Comment

by:Tom Knowlton
ID: 17822099
Alex:

Yeah, it's different in C#.


Yes, I had in mind to duplicate the same functionality in VB .NET, but it's not a matter of life-and-death that I do so.  I can live with declaring the static variable inside the function as long as it works pretty much like a static variable would in C#.

Using "Shared" sounds like it is closer to what I had in mind  (  originally  )
0
 
LVL 5

Author Comment

by:Tom Knowlton
ID: 17822178
Ummm....I think I want the variable to be  Shared  after all.
0
 
LVL 30

Expert Comment

by:Alexandre Simões
ID: 17822185

If that's what you want to do just:

Shared _HasBeenMadeVisibleOnce As Boolean = False

It will behave as expected.
Static on VB is a whole different thing as you can read from the link
0
 
LVL 5

Author Comment

by:Tom Knowlton
ID: 17822186
Thank you, both.
0
 
LVL 5

Author Comment

by:Tom Knowlton
ID: 17822208
>>>Static on VB is a whole different thing as you can read from the link


Agreed!
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
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…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
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