|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hi all i am usiing this code to write mulitiple values to registery but it only write one value. could any one help me make this code so that it write multiple values to registery. Currently it only writes nickname but not pwd value!!
I tried this but gave me error : Code:
'Save the value to the registry
SaveString HKEY_CURRENT_USER, "Software\xyz\" + Text6.Text, "nickname",+Text7.Text "pwd", strString
complete code : Code:
Const REG_SZ = 1 ' Unicode nul terminated string
Const REG_BINARY = 3 ' Free form binary
Const HKEY_CURRENT_USER = &H80000001
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Private Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal hKey As Long, ByVal lpValueName As String) As Long
Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long
Private Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpData As Any, ByVal cbData As Long) As Long
Sub SaveString(hKey As Long, strPath As String, strValue As String, strData As String)
Dim Ret
'Create a new key
RegCreateKey hKey, strPath, Ret
'Save a string to the key
RegSetValueEx Ret, strValue, 0, REG_SZ, ByVal strData, Len(strData)
'close the key
RegCloseKey Ret
End Sub
Sub SaveStringLong(hKey As Long, strPath As String, strValue As String, strData As String)
Dim Ret
'Create a new key
RegCreateKey hKey, strPath, Ret
'Set the key's value
RegSetValueEx Ret, strValue, 0, REG_BINARY, CByte(strData), 4
'close the key
RegCloseKey Ret
End Sub
Private Sub Command14_Click()
'Dim strString As String
Dim strString As String
'Ask for a value
'strString = InputBox("Please enter a value to be saved as a binary value in the registry.", App.Title)
'Save the value to the registry
SaveString HKEY_CURRENT_USER, "Software\xyz\" + Text6.Text, "nickname", strString
' SaveString HKEY_CURRENT_USER, "Software\xyz\" + Text6.Text, "nickname",+Text7.Text, "pwd", strString ===> did not work
End Sub
|
|
#2
|
|||
|
|||
|
Hey,
Your first problem is that your function call does not match the signature. You need to remove the commas because they are breaking the string up into seperate parameters. From the looks of what you've provided, the code you want in your Command4_Click() event should be: Code:
Private Sub Command14_Click()
Dim strPwd As String
'Ask for a value
strPwd = InputBox("Please enter a value", App.Title)
'Save the values to the registry
SaveString (HKEY_CURRENT_USER, "Software\xyz\" +
Text6.Text, "nickname", Text7.Text)
SaveString (HKEY_CURRENT)USER, "Software\xyz\" +
Text6.Text, "pwd", strPwd)
End Sub
Which I believe should save the two pieces of information. The biggest problem with your original code is the following line: Code:
SaveString HKEY_CURRENT_USER, "Software\xyz\" + Text6.Text, "nickname",+Text7.Text "pwd", strString You seem to be a little confused about how to call a function and what the parameters are. SaveString is a function. The items in brackets that follow the function declaration are its parameters. Each parameter is seperated by a comma, so in the following function specification: Code:
Sub SaveString(hKey As Long, strPath As String, strValue As String, strData As String) A function is created called SaveString which expects to be passed the following items every time it is called:
Your function call is the line: Code:
SaveString HKEY_CURRENT_USER, "Software\xyz\" + Text6.Text, "nickname",+Text7.Text, "pwd", strString SaveString identifies the function, and then each item following is a parameter. Every comma denotes a new parameter, and these parameters must match exactly the ones specified in teh function declaration. It may help when starting out for you to copy the function declaration and paste it in wherever you are planning on calling the function from, then replace each parameter with the value you wish to take. This will ensure that you are sending the information that the function needs. The SaveString function is only designed to save one string at a time, so to create two entries you need to call the function twice, like I did in the code listing at the beginning. I know it's a long post, but it should provide you with the information you need to solve your problem It seems to me that you don't have a lot of experience in VB, so you may be better off starting with a couple of introductory tutorials from somewhere on the 'net instead of jumping straight into registry coding.Good luck with everything! |
![]() |
| Viewing: ASP Free Forums > Programming > Visual Basic Programming > Problem writing multiple values to registery |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|