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?