Why is this happening? Why don't I get what has been saved?
Set a breakpoint on the first line of code in the GetSettingString function and when the code gets there press F8 to step through the code line by line so that you can look at the variables and see what is happening.
Sorry, but I don't like to fool with projects that modify the registry so I haven't run your project.
Do you know how to set a breakpoint? If so what happens after you set the breakpoint on the first line of code in the GetSettingString function and you press F8?
ok. I set the preakpoint to the getSettingString function in the module
I press F8 once and it goes to the first if statement. This bit is there only to determine if one of the optional parameters are filled in. It isn't so it goes past this making GetSettingString="".
Then into the actual code, lRegResult becomes 2. Then after another F8 it becomes 1010.
Then comes this line:
VB Code:
If lRegResult = ERROR_SUCCESS Then
Obiously it fails that, so it skips the whole block. That's why it doesn't do anything. I'll post the function
VB Code:
Public Function GetSettingString(hKey As Long, strPath As String, strValue As String, Optional Default As String) As String
Originally posted by rotcrules what version of windows are you using?
one thing you might want to try is insted of using a your function use the SaveSettings and GetSettings function see if that works first.
I'm using Win98.
Could you give me some quick code to test those two functions. They won't work for my program because I need to edit another string which they can't access. But I could still test them out, just to see if they work.
edit: never mind. I'm using the code from the link in martins code.
2nd edit That code worked fine. But as I said that won't work for this project.
Here is what the API Guide says about the return code from both RegOpenKey and RegQueryValueEx.
VB Code:
If the function succeeds, the return value is ERROR_SUCCESS.
If the function fails, the return value is a nonzero error code defined in WINERROR.H. You can use the FormatMessage function with the FORMAT_MESSAGE_FROM_SYSTEM flag to get a generic description of the error.
Here is a FormatMessage example.
VB Code:
Const FORMAT_MESSAGE_ALLOCATE_BUFFER = &H100
Const FORMAT_MESSAGE_FROM_SYSTEM = &H1000
Const LANG_NEUTRAL = &H0
Const SUBLANG_DEFAULT = &H1
Const ERROR_BAD_USERNAME = 2202&
Private Declare Function GetLastError Lib "kernel32" () As Long
Private Declare Sub SetLastError Lib "kernel32" (ByVal dwErrCode As Long)
Private Declare Function FormatMessage Lib "kernel32" Alias "FormatMessageA" (ByVal dwFlags As Long, lpSource As Any, ByVal dwMessageId As Long, ByVal dwLanguageId As Long, ByVal lpBuffer As String, ByVal nSize As Long, Arguments As Long) As Long
right. I'm off for the night. I'll keep trying to figure this out tomorrow. Thanks for all the help guys. I know helping a noob is really boring and frustrating.
Private Declare Function GetLastError Lib "kernel32" () As Long
Private Declare Function FormatMessage Lib "kernel32" Alias "FormatMessageA" (ByVal dwFlags As Long, lpSource As Any, ByVal dwMessageId As Long, ByVal dwLanguageId As Long, ByVal lpBuffer As String, ByVal nSize As Long, Arguments As Long) As Long
Public Function GetSettingString(hKey As Long, strPath As String, strValue As String, Optional Default As String) As String
OK. All the code you posted I shoved in a module in a new project. I then called the function the same way i did before. and I get this error:
"ByRef Argument Type Mismatch"
and it highlights the button like this:
Although this thread is abit old, meh!! Was trying to use the code posted above and I found it wouldn't work while I started strPath parameter with a \, removing it solved the problem.