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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Set Array to zero after intializing it 3

Status
Not open for further replies.

coffeysm

MIS
Oct 7, 2004
571
US
I created an HTA that when a button is pressed it creates an array with some numbers. Then it passes it to another function to sort the numbers in order. I have everything on that working. However, when the user clicks the button again it loops and keeps the old data. So, if I have an array with 100 elements it gets increased to 200. Is there anyway to set unset an array if it has a value already?
 
PHV,

Thanks for the response I read up on the solution you provided me and it doesn't work. I am using a Dynamic Array and it is suppose to destroy it, but apparently it does not. Here is the part of the code I am having problems with maybe you can take a look and see if something pops out at you.

Code:
Sub Generate_ID
Dim UID()

int Size = 0

txtUserID.Value = "" 'Textbox on my HTA

Set ObjOU = GetObject("LDAP://OU=SCIUsers,dc=domain,dc=name,dc=com")

    ObjOU.Filter = Array("User")

   For Each ObjUser in ObjOU
      If Not ObjUser.uidNumber = "" Then
          ReDim Preserve UID(Size)
          UID(Size) = ObjUser.uidNumber
          Size = Size + 1
      End If
   Next

  Msgbox LBOUND(UID) & " " & UBOUND(UID) & UID(UBOUND(UID))

  Call Sort(UID)

 Erase UID
 
You wanted this ?
ReDim UID(0)

What is the unexpected behaviour you experience ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
I don't see anywhere that UID is being populated again unless it is being populated the second time by Generate_ID being called a second time in which case UID should be wiped out anyway. I would personally need to see more of your code so I understand the context that the code is being run in before I would be able to figure it out. PHV is better at this than me though so maybe he will see it right off.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
PHV,

I tried that as well and it just kept the same value. It is weird I have to refresh the HTA application in order to get it to clear out the array.

EBGreen,
UID gets populated at this point:
Code:
For Each ObjUser in ObjOU
      If Not ObjUser.uidNumber = "" Then
          ReDim Preserve UID(Size)
          UID(Size) = ObjUser.uidNumber
          Size = Size + 1
      End If
Next

My if statement is what starts populating the array. What I am doing is pulling out all my UNIX User ID's from my AD Schema, if it has a value that is not empty. I run Vintela and this is code to get the next available user id for a new user. I get the next available user when I click it the first time, however, it is when I click it a second time I get errors. It is keeping the original data in the array and then repopulating it afterwards. It simply ignores the Erase UID statement I have in my code.

Do you think it is possible it could be the actual HTA program and not my code itself?
 
For me, the more likely is that you don't get a refreshed AD Schema in ObjOU.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Trollacious that was the problem! I want to thank all of you for helping me out though.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top