I'm looking for a way to empty a global variable, declared as an array of a user-defined type, and this several times in the program
Example:
Type BSCSCustomer
customer_id As Long
MatchCustomerNumber As Integer
MatchInvoice As Integer
MatchExternalReference As Integer
MatchGSMNumber As Integer
MatchAccountNumber As Integer
MatchName As Integer
MatchAddress As Integer
End Type
Global PossibleCust (0 To 200) As BSCSCustomer
I already tried REDIM PRESERVE, but I get the compile error 'Array already Dimensioned'. The goal is to be sure that the variable is empty before I re-use it.
I have to correct myself (sorry James, you were correct )
You can erase a fixed dimensioned array, but it doesn't have the same effect as erasing a dynamic array. Erase reinitializes the elements of fixed-size arrays and releases dynamic-array storage space.
When the array is declared as:
Global PossibleCust (0 To 200) As BSCSCustomer
Erase PossibleCust
This will reset all elements to the defaults for it's variabletype (integers to 0, strings to "" etc.) , but the array is still dimensioned from 0 to 200
But when the array is declared like this:
Global PossibleCust () As BSCSCustomer
ReDim PossibleCust(0 to 200)
Erase PossibleCust
Now the array is completely empty, you have to redimension it before you can use it.
String arrays go fully empty, but with numeric datatype arrays the values are made zero. This is actually what happens to string arrays as well, but with strings zeros are treated as null strings. By default the actual string array value for an item is a pointer to the actual string data in memory. You just can't see this directly in VB6.
If you are to handle numeric data, then you should retain the numeric datatype you use. If you use numbers as strings, you'll get unexpected problems in some cases.
Attached is a very simple vb project which highlights my problem. Can someone please explain why the two variables get treated differently and how I can get them all to operate in the same way.
Hope it's not just the version of VB6.0 that I'm using.
One variable gets emptied while the other sets to 0.
Wierd thing is that when I remove all the other arrays and just leave the two then they both get set to 0.
Last edited by sgrya1; Sep 25th, 2006 at 05:14 AM.