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 can I check the emptyness of a stack element array?? 1

Status
Not open for further replies.

WomanPro

Programmer
Nov 1, 2012
180
0
0
GR
Hello everybody, I need a little help.
I have a structure
Public Structure GatesPositions
Public pos As Integer
Public stack As Stack
End Structure

and an array of the defined type
Public UsrCheckerGates() As GatesPositions

That means that every element of UsrCheckerGates is composed from a stack and an integer.
And the what I want to do is to check if the stack is empty but I don't know the way to do it.
The elements count of UsrCheckerGates is changeable, because I have to add elements, without loosing the already stored.
So...
ReDim Preserve UsrCheckerGates(UsrCheckerGates.Length + 1) 'it increases the size of UsrCheckerGates at 1
Dim tmpStack As New Stack
tmpStack.Push(UsrCheckers(i))
Dim iSt As Byte
For iSt = 0 To UsrCheckerGates.Length - 2
[highlight #EF2929] If UsrCheckerGates(iSt).stack.Count = 0 Then[/highlight] here is the error and i need your help
UsrCheckerGates(iSt).stack = tmpStack
UsrCheckerGates(iSt).pos = Rd1 + 1
Exit For
End If
Next

The error is NullReferenceException was unhadled and I want to find a way just to check the null value of stack, which means the emptyness.
Any suggestions please??? Any help will be much appreciated.

Thank you so much
in advanced.
 
You are getting the NullRefenceException because you never instantiate the Stack object in your structure. I think you only need to do this - Public stack As New Stack - in the structure to get rid of the error message. If you don't want to do that for some reason, you can check if stack is Nothing (i.e., not instantiated) like this: If UsrCheckerGates(iSt).stack Is Nothing Then.

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
Thank you jebenson. Exactly that I was looking for, the "is nothing" statement because I have to check if the value is nothing and after then to use the new stack statement ;)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top