Jump to content

Why doesnt this code work v.Arrays...


fly
 Share

Recommended Posts

$removeArray = _ArrayCreate("LocalService", "NetworkService", "systemprofile", "Administrator"); These are accounts to not show
        _ArraySort ($aArray);Sorts the array so that it can be searched
        For $count = 0 To UBound($removeArray) -1; Cycle through the remove array
            $index = _ArrayBinarySearch($aArray, $removeArray[$count])
            If @error = 0 Then _ArrayDelete($aArray, $index); If $index found something, do the delete
        Next

I don't remember changing anything in this section of code. It worked yesterday and now it doesn't...

Am I even doing this right? LOL

Link to comment
Share on other sites

  • Developers

$removeArray = _ArrayCreate("LocalService", "NetworkService", "systemprofile", "Administrator"); These are accounts to not show
        _ArraySort ($aArray);Sorts the array so that it can be searched
        For $count = 0 To UBound($removeArray) -1; Cycle through the remove array
            $index = _ArrayBinarySearch($aArray, $removeArray[$count])
            If @error = 0 Then _ArrayDelete($aArray, $index); If $index found something, do the delete
        Next

I don't remember changing anything in this section of code. It worked yesterday and now it doesn't...

Am I even doing this right? LOL

What is the contents of $aArray ?

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

$removeArray = _ArrayCreate("LocalService", "NetworkService", "systemprofile", "Administrator"); These are accounts to not show
        _ArraySort ($aArray);Sorts the array so that it can be searched
        For $count = 0 To UBound($removeArray) -1; Cycle through the remove array
            $index = _ArrayBinarySearch($aArray, $removeArray[$count])
            If @error = 0 Then _ArrayDelete($aArray, $index); If $index found something, do the delete
        Next

I don't remember changing anything in this section of code. It worked yesterday and now it doesn't...

Am I even doing this right? LOL

How should $aArray be declared to have your script running?
Link to comment
Share on other sites

Here is the entire function. Someone else here posted it, and I hacked it up for my own purposes (so the comments really aren't true). This obviously shows how $aArray gets defined. Sorry, I would have included this originally, but I figured it was just an error in that loop...

;===============================================================================
; Function Name:    _UserSID()
;
; Description:      Return a 2 dimensional array first username second SID.
;
; Syntax:             _UserSID ( [$s_UserName, $s_RemoteComputer] )
;
; Parameter(s):     $s_UserName = Username to get SID.
;                  $s_RemoteComputer = ComputerName on the network
;               
; Requirement(s):     External:   = None.
;                     Internal:   = None.
;
; Return Value(s):  On Success: = Returns 2 dimensional array with UserName, SID and sets @error to 0.
;                     On Failure: = Returns "" and sets @error to 1.
;
; Author(s):        Dan Colón
;
; Note(s):          Don't currently use Remote option, but could be implemented later
;                   And a lot of this crap isn't used.  Thanks tho Dan!
;
; Example(s):
;   _UserSID("DColon") it will return DColon SID
;   _UserSID() it will return every user SID
;===============================================================================

Func _UserSID($s_UserName = "All", $s_RemoteComputer = '')
    If $s_UserName = '' Then $s_UserName = 'All'
    If $s_RemoteComputer <> '' Then
        If StringMid($s_RemoteComputer, 1, 1) <> '\' Or StringMid($s_RemoteComputer, 2, 1) <> '\' Or StringRight($s_RemoteComputer, 1) <> '\' Then
            $s_RemoteComputer = '\\' & StringReplace($s_RemoteComputer, '\', '') & '\'
        EndIf
    EndIf
    
    Local $line, $var, $ProfilePath, $i = 1
    Local Const $regkey = $s_RemoteComputer & "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\"
    Local Const $regkeyval1 = "ProfilesDirectory"
    Local Const $regkeyval2 = "ProfileImagePath"
        
    $ProfilePath = RegRead($regkey, $regkeyval1)    
    While 1
        $line = RegEnumkey($regkey, $i)
        $var = RegRead ( $regkey & $line, $regkeyval2)
        If @error = 1 Or @error = -1 Then ExitLoop
        If $s_UserName == "All" Then
            If Not IsDeclared("aArray") Then Dim $aArray[1]
            ReDim $aArray[UBound($aArray) + 1]
            $aArray[UBound($aArray) - 1] = StringMid($var, StringInStr($var, '\', 0, -1) + 1)
            $aArray[0] = UBound($aArray) - 1
        ElseIf StringLower($var) == StringLower($ProfilePath & "\" & $s_UserName) Then
            If Not IsDeclared("aArray") Then Dim $aArray[1][1]
            ReDim $aArray[UBound($aArray) + 1][UBound($aArray) + 1]
            $aArray[0][UBound($aArray) - 1] = StringMid($var, StringInStr($var, '\', 0, -1) + 1)
            $aArray[1][UBound($aArray) - 1] = $line 
            $aArray[0][0] = UBound($aArray) - 1
        EndIf
        $i = $i + 1
    WEnd
    If Not IsDeclared("aArray") Then
        SetError(1)
        Return("")
    Else
        $removeArray = _ArrayCreate("LocalService", "NetworkService", "systemprofile", "Administrator"); These are accounts to not show
        _ArraySort ($aArray);Sorts the array so that it can be searched
        For $count = 0 To UBound($removeArray) -1; Cycle through the remove array
            $index = _ArrayBinarySearch($aArray, $removeArray[$count])
            If @error = 0 Then _ArrayDelete($aArray, $index); If $index found something, do the delete
        Next        
        SetError(0) 
        Return($aArray)
    EndIf
EndFunc
Link to comment
Share on other sites

^ anyone?

Okay, I narrowed it down. The code WORKS in autoit-v3.1.1.84-beta, but NONE of the others since then.

.85 - I get a blank combo box

.86 - I get a blank combo box

.87 - I get a FULL combo box, meaning the $removeArray part didn't work.

EDIT: My script also crashes on Windows 2000 boxes (the 2 I tested so far). Is there something that needs to be installed on them for it to work?

Edited by fly
Link to comment
Share on other sites

BTW, I cleaned up that $removeArray code posted in the first post (learned about For ... In) to this:

$removeArray = _ArrayCreate("LocalService", "NetworkService", "systemprofile", "Administrator"); These are accounts to not show
        _ArraySort ($aArray);Sorts the array so that it can be searched     
        For $count In $removeArray; Cycle through the remove array
            $index = _ArrayBinarySearch($aArray, $count)
            If Not @error Then _ArrayDelete($aArray, $index); If $index found something, do the delete
        Next

Still works fine in .84, but fails to work in .87. Is there a changelog somewhere? According to my MsgBox tests, it seems something changed in either _ArrayBinarySearch or _ArrayDelete.

Edited by fly
Link to comment
Share on other sites

^ anyone?

Okay, I narrowed it down. The code WORKS in autoit-v3.1.1.84-beta, but NONE of the others since then.

.85 - I get a blank combo box

.86 - I get a blank combo box

.87 - I get a FULL combo box, meaning the $removeArray part didn't work.

EDIT: My script also crashes on Windows 2000 boxes (the 2 I tested so far). Is there something that needs to be installed on them for it to work?

I don't see any combobox in the script you post.

Can I have a complete reproduction script so I can test the same?

Thanks

Link to comment
Share on other sites

Its long, and probably has a bunch of non-optimzed code, as I'm just learning this stuff. B)

I skrink your code to demonstrate how to correct your code.

1. For $count in $user

is not code because the first entry contain the number of item and you don't want to add entry with it.

Perhaps it is working by luck the combo control not being really updated.

2. I don't think a version of autoit ever display something by default in the combo as nowhere soeme code specify the default value.

The UDF extension are great for some special case but you can achieve the desired result with the GUICtrlSetData($usercombo, ...)

you will define the default as the 3rd parameter.

see the attached file

Link to comment
Share on other sites

I skrink your code to demonstrate how to correct your code.

1. For $count in $user

is not code because the first entry contain the number of item and you don't want to add entry with it.

Perhaps it is working by luck the combo control not being really updated.

2. I don't think a version of autoit ever display something by default in the combo as nowhere soeme code specify the default value.

The UDF extension are great for some special case but you can achieve the desired result with the GUICtrlSetData($usercombo, ...)

you will define the default as the 3rd parameter.

see the attached file

Thanks! I'll check out on Monday, as I'm leaving. Enjoy your weekend.
Link to comment
Share on other sites

Thanks for the help. Worked great! Solved the problem of the program crashing on Windows 2000 boxes as well.

One more quick question that didn't need another thread...

Is there a way to search an array and delete items using wildcards? I want to remove everything that starts 'SMS' Thanks again guys!

Edited by fly
Link to comment
Share on other sites

Thanks for the help. Worked great! Solved the problem of the program crashing on Windows 2000 boxes as well.

One more quick question that didn't need another thread...

Is there a way to search an array and delete items using wildcards? I want to remove everything that starts 'SMS' Thanks again guys!

An array is an array no deletion of a specific entry unless you move every think one up. you will need to have a counter indicating the last usable entry unless you redim.

All that is very costly but depending how often you delete/search it can be usefull.

Good learning in programming B)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...