UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Stack, Wiki Talk    
 
   
post Feb 1 2014, 10:15 AM
Post#1



Posts: 0
Joined: --



This topic is designated for discussion of the article: Stack.
Go to the top of the page
 
Keith Mueller
post Feb 1 2014, 10:21 AM
Post#2



Posts: 607
Joined: 2-July 10



I get a subscript out of range error when "Pop'n" the last item in the Stack ( lol , do you guys test this stuff ? ... j/k ... please let me know if the fix I made is appropriate or if there is a better one )
The error occurs in Public Sub Pop()
Ochanged the code
CODE
If Index > -1 Then
   Index = Index - 1
   Value = Stack(Index)
End If

to
CODE
If Index > -1 Then
   Index = Index - 1
   If Index = -1 Then Value = "" Else Value = Stack(Index)
End If
Go to the top of the page
 
jleach
post Feb 1 2014, 06:01 PM
Post#3


UtterAccess Editor
Posts: 9,852
Joined: 7-December 09
From: Staten Island, NY, USA


Probably the value ought to be set to null rather than a ZLS, seeing as the stack items are variants.
'll update the class accordingly. Thanks for the catch.
Go to the top of the page
 
Keith Mueller
post Feb 4 2014, 03:06 PM
Post#4



Posts: 607
Joined: 2-July 10



J,
YI, During development I like to run with "Break On All Errors" on. I do this because trapping errors is an indicator to me that I may be "going down a wrong road".
In your class you use error trapping when checking if the Stack array is "initialized".
Just to be clear, your method is perfectly fine except for my development style.
Oreplaced your IsInit() function with the following:
CODE
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDst As Any, pSrc As Any, ByVal ByteLen As Long)
Private Function ArrayNotEmpty(checkArray) As Boolean
  Dim Ret As Long
  CopyMemory Ret, ByVal VarPtr(checkArray) + 8, ByVal 4
  CopyMemory Ret, ByVal Ret, ByVal 4
  ArrayNotEmpty = (Ret <> 0)
End Function
Go to the top of the page
 
BananaRepublic
post Feb 4 2014, 04:00 PM
Post#5


Dungeon Cleaner
Posts: 1,504
Joined: 16-June 07
From: Banana Republic


To be honest, Keith, I think that is actually more dangerous than trapping for Error #9. For one, you are assuming that the adjacent region of memory is actually part of the array but it could be allocated for an entirely different use and has nothing to do with any array and therefore, could return a non-zero value and therefore a false positive. You are also assuming that it's of a certain size/offset (e.g. it's 4 bytes big and offset by 8 bytes) which MIGHT work in some scenario but not all (e.g. if the array's data type is changed, that might be no longer true. Ditto on a 64-bit platform).
It would be more appropriate to use something like this or similar, but I don't know if it's feasible to call them via VBA using API declare.
Go to the top of the page
 
Keith Mueller
post Feb 4 2014, 04:57 PM
Post#6



Posts: 607
Joined: 2-July 10



Well, works fine ( here )
Go to the top of the page
 


Custom Search
RSSSearch   Top   Lo-Fi    18th January 2018 - 08:43 PM