|
-
Nov 15th, 2003, 08:40 AM
#1
Thread Starter
Fanatic Member
Function doesn't work in my program. [SOLVED]
Here is a function I found on the internet:
VB Code:
'I put the function inside a module.
Public Sub DoEnumSubKeys(ByVal inMainKey As Long, ByVal inSubKey As String)
Dim mKey As Long
Dim mBuffer As String * 256
Dim mBufSize As Long
Dim mClassBuffer As String * 256
Dim mClassBufSize As Long
Dim typLastWriteTime As FILETIME
Dim mSubKeyName As String
Dim mSubKeyValue As String
Dim mValType As Long
Dim mIndex As Integer
Set colSubKeys = New Collection
If RegOpenKeyEx(inMainKey, inSubKey, 0&, KEY_ALL_ACCESS, mKey) <> 0 Then
MsgBox "Unable to open a subkey"
Exit Sub
End If
mIndex = 0
Do
mClassBuffer = ""
mClassBufSize = 0
mBufSize = 256
mSubKeyName = Space$(mBufSize)
mResult = RegEnumKeyEx(mKey, mIndex, mSubKeyName, mBufSize, 0, mClassBuffer, mClassBufSize, typLastWriteTime)
If mResult <> ERR_MORE_DATA And mResult <> 0 Then
Exit Do
End If
mSubKeyName = Left$(mSubKeyName, InStr(mSubKeyName, Chr$(0)) - 1)
colSubKeys.Add mSubKeyName
mIndex = mIndex + 1
Loop
RegCloseKey mKey
For i = 1 To colSubKeys.Count
DoEvents
If mStopFlag Then
Exit For
End If
Next i
Set colSubKeys = Nothing
End Sub
'This is in another form.
Private Sub Form_Load()
DoEnumSubKeys HKEY_LOCAL_MACHINE, "SOFTWARE\Gitmail\Profiles"
CenterForm Me
If Profiles.ListCount > 0 Then Delete.Enabled = True
If colSubKeys.Count > 0 Then Profiles.AddItem colSubKeys(i)
End Sub
The function was working fine last night, now it refuses to work in my program, yet it will work in any other program. I know I didn't set the colSubKeys variable, but I don't get any errors; just the message box that says it can't open the subkey, and like I said before, it worked great last night. What's wrong?
Last edited by hothead; Nov 15th, 2003 at 09:36 AM.
-
Nov 15th, 2003, 09:01 AM
#2
Thread Starter
Fanatic Member
The function works when I put it in the form along with the Form_Load code. If I were to use the same function in different dialog boxes, wouldn't it slow my program down though?
I was always taught that it was bad programming practice.
-
Nov 15th, 2003, 09:36 AM
#3
Thread Starter
Fanatic Member
Nevermind, turns out that was the best thing I could've done. I can display different messages now, depending on the situation.
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
|