Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to declare a global static variable that will not loose the initial values? 1

Status
Not open for further replies.

WomanPro

Programmer
Nov 1, 2012
180
0
0
GR
Hello everyone.
It's like I'm in big trouble again.
I need a globar static variable...
I have an array of checkers. Checker is a class created by me with properties.
Well during Runtime some elements of UsrCheckers array change their values properties.
For example UsrChecker(0).xLocation= 400 UsrChecker(0).yLocation= 100 and after User moves it in a new possition
these values change. ex UsrChecker(0).xLocation= 650 UsrChecker(0).yLocation= 350
The what I want to do is to have a variable that keeps the initial values of the specified element each time, in my example
these are initial values UsrChecker(0).xLocation= 400 UsrChecker(0).yLocation= 100
I tried
Public PlngChckr As New Checker ' general declarations of the form I tried too, shared instead of public
Public Function HoldInitialValuesPlayingChecker(ByVal PlayingChckr As Checker) As Checker
Static CrntPlayingChecker As Checker
CrntPlayingChecker = PlayingChckr
Return CrntPlayingChecker
End Function
Public Sub Undo(ByVal chckr As Checker)
Static CrntPlayingChecker As New Checker
CrntPlayingChecker = chckr
end sub

Public Sub UsrCheckersClickHandler(ByVal Sender As Object, ByVal e As System.EventArgs)
Dim UsrI As Byte
For UsrI = 0 To UsrCheckers.Length - 1
If strName = UsrCheckers(UsrI).Name Then
Instance = UsrCheckers(UsrI)
PlngChckr = Me.BrdPB.HoldInitialValuesPlayingChecker(UsrCheckers(UsrI))
exit for
End If
Next
End Sub

Private Sub UndoBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UndoBtn.Click
Dim chckr As New Checker
Me.BrdPB.Undo(PlngChckr)
End Sub

No effect :(
Vb.net 2005 doesn't allow to declare public Static variables even to general declaration of a form, even to module.
Variabe CrntPlayingChecker holds the updated latest values. So PlngChckr doesn't keep initial values :( but updated...
Any help please????

Any help will be much appreciated.
Thank you very much in advanced.
 
Would you not simply create those properties of the class Checker?
.xLocation
.ylocation
.initialXlocation
.initialYlocation
 
OMG sure I would!!! I haven't think something that. I was wondering. I ran it for integer variables without the use of static type and ran!!! I can't believe how it can't work for classe's properties.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top