Faqts : Business : Programming : Shopping For You : Visual basic : Visual basic .NET

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

3 of 3 people (100%) answered Yes
Recently 3 of 3 people (100%) answered Yes

Entry

Visual Basic .net: Variable: Static: Application: Windows: How to create static variables?

Dec 22nd, 2003 14:20
Knud van Eeden,


----------------------------------------------------------------------
--- Knud van Eeden --- 22 December 2003 - 11:18 pm -------------------

Visual Basic .net: Variable: Static: Application: Windows: How to 
create static variables?

---

Steps: Overview:

 1. -Open a Microsoft Visual Studio Visual Basic window application

 2. -Put a button on the form

 3. -Double click on the button, and add the following text in between:

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e 
As System.EventArgs) Handles Button1.Click

        Static I As Integer

        I = I + 1

        MsgBox( I.ToString )

    End Sub

 4. -Run this application

 5. -When you repeatedly click on the button it will show
     the following numbers:

      1

      2

      3

      4

      5

      ...

 6. So it retains its value between procedure and function calls

---
---

book: see also:

[book: Utley, Craig - a programmer's introduction to Visual Basic.NET -
 ISBN 0-672-32203-X - p. 55 'Static not supported on subs or 
functions']

----------------------------------------------------------------------