|
-
May 1st, 2007, 05:31 PM
#1
Thread Starter
Hyperactive Member
[RESOLVED] for each list item in Listbox
I have a list box which displays the usernames on my computer. how do i use the for each statment to pass the usernames so the code can be repeated for each user.
Thanks in advance
Chris1990
If your question is answered then mark your thread RESOLVED and give credit to whoever answered it.
If you fail, try and try again, its the only way to success.
-
May 1st, 2007, 05:49 PM
#2
Re: for each list item in Listbox
I don't know how to do it with "For each" but you can use "List1.ListCount" to get the number of items in the listbox, then loop through it like you normally would...
This is what worked for me... might not be the best solution, i dont know... but hey :P
Code:
Dim i As Integer
Dim MyArray() As String
Dim lstcount As Integer
lstcount = List1.ListCount
ReDim MyArray(0 To lstcount)
For i = 0 To lstcount - 1
MyArray(i) = List1.List(i)
Next
Last edited by NickThissen; May 1st, 2007 at 05:55 PM.
-
May 2nd, 2007, 06:21 AM
#3
Re: for each list item in Listbox
What code do you need repeated for each username?
-
May 2nd, 2007, 03:52 PM
#4
Thread Starter
Hyperactive Member
Re: for each list item in Listbox
I am making this program to add this registry entry for every user on the pc:
SetKeyValue HKEY_LOCAL_MACHINE, "Software\My Apps\Security App\Users\StartUp\" & lblUsername.Caption & "\", REG_DWORD, "load", "0"
otherwise if i dont i get errors of an unsupported value when my program reads it
If your question is answered then mark your thread RESOLVED and give credit to whoever answered it.
If you fail, try and try again, its the only way to success.
-
May 2nd, 2007, 09:08 PM
#5
Frenzied Member
Re: for each list item in Listbox
vb Code:
For i = 0 To List.Count - 1
SetKeyValue HKEY_LOCAL_MACHINE, "Software\My Apps\Security App\Users\StartUp\" & List.Index(i) & "\", REG_DWORD, "load", "0"
Next
-
May 3rd, 2007, 09:54 AM
#6
Re: for each list item in Listbox
I would use
Code:
For i = 0 To List.Count - 1
SetKeyValue HKEY_LOCAL_MACHINE, "Software\My Apps\Security App\Users\StartUp\" & List.List(i) & "\", REG_DWORD, "load", "0"
Next
-
May 3rd, 2007, 10:03 AM
#7
Re: for each list item in Listbox
Keep in mind that the user is going to have to have administrative rights to write to that part of the registry.
-
May 7th, 2007, 03:22 AM
#8
Thread Starter
Hyperactive Member
Re: for each list item in Listbox
thanks,
it reads from the registry by the way
If your question is answered then mark your thread RESOLVED and give credit to whoever answered it.
If you fail, try and try again, its the only way to success.
-
May 7th, 2007, 03:36 AM
#9
Thread Starter
Hyperactive Member
Re: for each list item in Listbox
i get an error
"Wrong number of argurements or invalid propery assignment."
this is higlighted
If your question is answered then mark your thread RESOLVED and give credit to whoever answered it.
If you fail, try and try again, its the only way to success.
-
May 7th, 2007, 03:38 AM
#10
Hyperactive Member
Re: for each list item in Listbox
to get the value u need to use
Index is used when the array to list box is used...
-
May 7th, 2007, 03:43 AM
#11
Thread Starter
Hyperactive Member
Re: for each list item in Listbox
This is my code:
Code:
Private Declare Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
Dim SystemPath As String
Dim OS As String
Private Sub Form_Load()
' Get the name of the computer
str_Computer = CreateObject("WScript.Network").ComputerName
' Connect to the computer object
Set oMachine = GetObject("WinNT://" & str_Computer & ",computer")
' Set the filter to list users
oMachine.Filter = Array("user")
' For each user on the machine
For Each oUser In oMachine
' display the user name
lstUsers.AddItem oUser.Name
Next
'--------------------------Set Regkey
Dim lpBuffer As String
Dim nSize As Integer
Dim rc As Long
nSize = 255
lpBuffer = Space$(nSize)
rc = GetSystemDirectory(lpBuffer, nSize)
If (rc <> 0) Then
SystemPath = Left$(lpBuffer, InStr(lpBuffer, Chr$(0)) - 1)
Else
SystemPath = ""
End If
If (Len(SystemPath) = 17) Then
OS = 1 ' windows 98
Else
OS = 2
End If
'---------------------------------------Set RegKey END
'list reg keys
For i = 0 To lstUsers.ListCount - 1
SetKeyValue HKEY_LOCAL_MACHINE, "Software\My Apps\Security App\Users\StartUp\" & lstUsers.List(i) & "\", REG_DWORD, "load", "0"
Next
it still doesnt add keys to the registry
If your question is answered then mark your thread RESOLVED and give credit to whoever answered it.
If you fail, try and try again, its the only way to success.
-
May 7th, 2007, 04:23 AM
#12
Re: for each list item in Listbox
Try:
vb Code:
SetKeyValue HKEY_LOCAL_MACHINE, "Software\My Apps\Security App\Users\StartUp\" & lstUsers.List(i), REG_DWORD, "load", "0"
(Without the last "\")
-
May 7th, 2007, 04:37 AM
#13
Thread Starter
Hyperactive Member
Re: for each list item in Listbox
Thanks, it works now
Chris1990
If your question is answered then mark your thread RESOLVED and give credit to whoever answered it.
If you fail, try and try again, its the only way to success.
-
May 7th, 2007, 12:15 PM
#14
Re: [RESOLVED] for each list item in Listbox
Why not just use a default value (0, in this case?) when you read the key? Then, if the key doesn't exist, you'll get 0. Only write registry keys that are really needed.
The most difficult part of developing a program is understanding the problem.
The second most difficult part is deciding how you're going to solve the problem.
Actually writing the program (translating your solution into some computer language) is the easiest part.
Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.
Please Help Us To Save Ana
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|