Sign in to follow this  
Followers 0
redfive19

Adding to an array

6 posts in this topic

Hi guys,

So what I'm trying to do is enumerate all of the user's that have logged onto a pc. I'm doing this by listing all of the files in the documents and settings folder:

$useridarray = _FileListToArray('D:\Documents and Settings\', '*', 2)

In my GUI, I'm populating that information (minus a few profiles I don't want to include) in a Combo-dropdown box like so:

$userid_input = GUICtrlCreateCombo("", 92, 135, 185, 21, $CBS_DROPDOWNLIST)
For $z = 1 to $useridarray[0]
    If $useridarray[$z] <> 'Administrator' And $useridarray[$z] <> 'All Users' And  And $useridarray[$z] <> 'Default User' And $useridarray[$z] <> 'LocalService' And $useridarray[$z] <> 'My Documents' And $useridarray[$z] <> 'NetworkService' And $useridarray[$z] <> 'Temp' Then
        GUICtrlSetData(-1, $useridarray[$z], @UserName)
    EndIf
Next

I want them to be able to input a userID that's not prepopluated so I thought to add an element to the FileList array like such:

$useridarray = _FileListToArray('D:\Documents and Settings\', '*', 2)
_ArrayAdd ($useridarray,  '<ENTER USERID>')

But _ArrayAdd doesn't update the element count ($useridarray[0]) so it's not working.

My 2nd problem is is that when they select <ENTER USERID>, I want all of the other fields on the form to blank out. I am sure this is an OnEvent thing but to be honest, I never really understood OnEvent mode so if someone can point me in the correct direction, I'd really appreciate it. Thanks!!!

- redfive

Share this post


Link to post
Share on other sites



Hi guys,

So what I'm trying to do is enumerate all of the user's that have logged onto a pc. I'm doing this by listing all of the files in the documents and settings folder:

$useridarray = _FileListToArray('D:\Documents and Settings\', '*', 2)

In my GUI, I'm populating that information (minus a few profiles I don't want to include) in a Combo-dropdown box like so:

$userid_input = GUICtrlCreateCombo("", 92, 135, 185, 21, $CBS_DROPDOWNLIST)
For $z = 1 to $useridarray[0]
    If $useridarray[$z] <> 'Administrator' And $useridarray[$z] <> 'All Users' And  And $useridarray[$z] <> 'Default User' And $useridarray[$z] <> 'LocalService' And $useridarray[$z] <> 'My Documents' And $useridarray[$z] <> 'NetworkService' And $useridarray[$z] <> 'Temp' Then
        GUICtrlSetData(-1, $useridarray[$z], @UserName)
    EndIf
Next

I want them to be able to input a userID that's not prepopluated so I thought to add an element to the FileList array like such:

$useridarray = _FileListToArray('D:\Documents and Settings\', '*', 2)
_ArrayAdd ($useridarray,  '<ENTER USERID>')

But _ArrayAdd doesn't update the element count ($useridarray[0]) so it's not working.

My 2nd problem is is that when they select <ENTER USERID>, I want all of the other fields on the form to blank out. I am sure this is an OnEvent thing but to be honest, I never really understood OnEvent mode so if someone can point me in the correct direction, I'd really appreciate it. Thanks!!!

- redfive

_ArrayAdd doesn't increment the zero element so you need to do that yourself if the function succeeds.

If _ArrayAdd ($useridarray,  '<ENTER USERID>') <> -1 then
 $useridarray[0] = UBound($useridarray) - 1
endif

or

$result = _ArrayAdd ($useridarray,  '<ENTER USERID>')
if $result <> -1 then $useridarray[0] = $result

I don't know what the other fields are so I can't say much about that, but if you want something to be hidden then you can hide controls with GuiCtrlSetState($id,$GUI_HIDE)


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

Thanks Martin, the first solution you posted works perfectly! I'm still trying to figure out how to blank the form if <ENTER USER ID> is chosen but you've certainly helped me with the biggest hurdle!!

Share this post


Link to post
Share on other sites

Thanks Martin, the first solution you posted works perfectly! I'm still trying to figure out how to blank the form if <ENTER USER ID> is chosen but you've certainly helped me with the biggest hurdle!!

That's good.

I don't know what you mean by blank the form though. Do you mean remove or hide all the controls?


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

What I mean is blank out the values that are already in there.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

What I mean is blank out the values that are already in there.

I'm not very good at this game. :D

"in there" doesn't mean much to me. In what? what values in where? Do you mean all the other names in the combobox list? Or are you talking about some part of your code I don't know about? I need a few more nouns, and verbs and adjectives. Maybe a diagram or a nice video on YouTube. Or bring your PC round to my house and show me. But no, I expect the mains lead won't be long enough.

Edited by martin

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
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
Sign in to follow this  
Followers 0