I found this code on these boards, and am at a loss here because for some strange reason I cannot compile this code. I can however run it normally error free. This is in a module by itself btw. The exact error given is.. Type-Declaration character does not match declared data type. What the heck? I've tried different variation, including the sister function Right$. But still no luck. The part that is highlighted is shown in bold in the code below. Any Ideas would be helpful. Sorry for the long code Registry w/ the API isn't real fun is it! Oh and BTW I searched through the first few pages of relevent information. Did multiple searches too.

VB Code:
  1. ' Possible registry data types
  2. Public Enum InTypes
  3.    ValNull = 0
  4.    ValString = 1
  5.    ValXString = 2
  6.    ValBinary = 3
  7.    ValDWord = 4
  8.    ValLink = 6
  9.    ValMultiString = 7
  10.    ValResList = 8
  11. End Enum
  12. ' Registry value type definitions
  13. Public Const REG_NONE As Long = 0
  14. Public Const REG_SZ As Long = 1
  15. Public Const REG_EXPAND_SZ As Long = 2
  16. Public Const REG_BINARY As Long = 3
  17. Public Const REG_DWORD As Long = 4
  18. Public Const REG_LINK As Long = 6
  19. Public Const REG_MULTI_SZ As Long = 7
  20. Public Const REG_RESOURCE_LIST As Long = 8
  21. ' Registry section definitions
  22. Public Const HKEY_CLASSES_ROOT = &H80000000
  23. Public Const HKEY_CURRENT_USER = &H80000001
  24. Public Const HKEY_LOCAL_MACHINE = &H80000002
  25. Public Const HKEY_USERS = &H80000003
  26. Public Const HKEY_PERFORMANCE_DATA = &H80000004
  27. Public Const HKEY_CURRENT_CONFIG = &H80000005
  28. Public Const HKEY_DYN_DATA = &H80000006
  29. ' Codes returned by Reg API calls
  30. Private Const ERROR_NONE = 0
  31. Private Const ERROR_BADDB = 1
  32. Private Const ERROR_BADKEY = 2
  33. Private Const ERROR_CANTOPEN = 3
  34. Private Const ERROR_CANTREAD = 4
  35. Private Const ERROR_CANTWRITE = 5
  36. Private Const ERROR_OUTOFMEMORY = 6
  37. Private Const ERROR_INVALID_PARAMETER = 7
  38. Private Const ERROR_ACCESS_DENIED = 8
  39. Private Const ERROR_INVALID_PARAMETERS = 87
  40. Private Const ERROR_NO_MORE_ITEMS = 259
  41.  
  42. Private Declare Function RegQueryValueExString Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, ByVal lpData As String, lpcbData As Long) As Long
  43. Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As Long
  44. Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, ByVal lpData As String, lpcbData As Long) As Long
  45. Declare Function RegEnumValue Lib "advapi32.dll" Alias "RegEnumValueA" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpValueName As String, lpcbValueName As Long, ByVal lpReserved As Long, lpType As Long, ByVal lpData As String, lpcbData As Long) As Long
  46. Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
  47. Declare Function RegCreateKeyEx Lib "advapi32.dll" Alias "RegCreateKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal Reserved As Long, ByVal lpClass As String, ByVal dwOptions As Long, ByVal samDesired As Long, lpSecurityAttributes As Any, phkResult As Long, lpdwDisposition As Long) As Long
  48. Declare Function RegSetValueExString Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, ByVal lpValue As String, ByVal cbData As Long) As Long
  49. Declare Function RegSetValueExLong Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpValue As Long, ByVal cbData As Long) As Long
  50. Declare Function RegFlushKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
  51. Declare Function RegEnumKey Lib "advapi32.dll" Alias "RegEnumKeyA" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpName As String, ByVal cbName As Long) As Long
  52. Declare Function RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" (ByVal hKey As Long, ByVal lpSubKey As String) As Long
  53. Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal hKey As Long, ByVal lpValueName As String) As Long
  54. 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
  55. Declare Function GetLastError Lib "kernel32" () As Long
  56. Declare Sub SetLastError Lib "kernel32" (ByVal dwErrCode As Long)
  57. Const FORMAT_MESSAGE_ALLOCATE_BUFFER = &H100
  58. Const FORMAT_MESSAGE_FROM_SYSTEM = &H1000
  59. Const LANG_NEUTRAL = &H0
  60. Const SUBLANG_DEFAULT = &H1
  61. Const REG_OPTION_BACKUP_RESTORE = 4     ' open for backup or restore
  62. Const REG_OPTION_VOLATILE = 1           ' Key is not preserved when system is rebooted
  63. Const REG_OPTION_NON_VOLATILE = 0       ' Key is preserved when system is rebooted
  64. Const STANDARD_RIGHTS_ALL = &H1F0000
  65. Const SYNCHRONIZE = &H100000
  66. Const READ_CONTROL = &H20000
  67. Const STANDARD_RIGHTS_READ = (READ_CONTROL)
  68. Const STANDARD_RIGHTS_WRITE = (READ_CONTROL)
  69. Const KEY_CREATE_LINK = &H20
  70. Const KEY_CREATE_SUB_KEY = &H4
  71. Const KEY_ENUMERATE_SUB_KEYS = &H8
  72. Const KEY_NOTIFY = &H10
  73. Const KEY_QUERY_VALUE = &H1
  74. Const KEY_SET_VALUE = &H2
  75. Const KEY_READ = ((STANDARD_RIGHTS_READ Or KEY_QUERY_VALUE Or KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY) And (Not SYNCHRONIZE))
  76. Const KEY_WRITE = ((STANDARD_RIGHTS_WRITE Or KEY_SET_VALUE Or KEY_CREATE_SUB_KEY) And (Not SYNCHRONIZE))
  77. Const KEY_EXECUTE = (KEY_READ)
  78. Const KEY_ALL_ACCESS = ((STANDARD_RIGHTS_ALL Or KEY_QUERY_VALUE Or KEY_SET_VALUE Or KEY_CREATE_SUB_KEY Or KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY Or KEY_CREATE_LINK) And (Not SYNCHRONIZE))
  79.  
  80.  
  81. ' This routine allows you to get values from anywhere in the Registry, it currently
  82. ' only handles string and double word values.
  83.  
  84. Public Function ReadRegistry(ByVal Group As Long, ByVal Section As String, ByVal Key As String) As String
  85. Dim lResult As Long, lKeyValue As Long, lDataTypeValue As Long, lValueLength As Long, sValue As String, td As Double
  86.   On Error Resume Next
  87.     lResult = RegOpenKeyEx(ByVal Group, ByVal Section, ByVal &O0, &H1, lKeyValue)
  88. '    If lResult > 0 Then
  89. '      Dim Buffer As String
  90. '      'Create a string buffer
  91. '      Buffer = Space(200)
  92. '      'Set the error number
  93. '      SetLastError lResult
  94. '      'Format the message string
  95. '      FormatMessage FORMAT_MESSAGE_FROM_SYSTEM, ByVal &O0, GetLastError, LANG_NEUTRAL, Buffer, 200, ByVal 0&
  96. '      'Show the message
  97. '      MsgBox Buffer
  98. ' End If
  99.  sValue = Space$(2048)
  100.  lValueLength = Len(sValue)
  101.  lResult = RegQueryValueEx(ByVal lKeyValue, ByVal Key, ByVal 0&, ByVal lDataTypeValue, ByVal sValue, lValueLength)
  102.  If (lResult = 0) And (Err.Number = 0) Then
  103.    If lDataTypeValue = REG_DWORD Then
  104.       td = Asc(Mid$(sValue, 1, 1)) + &H100& * Asc(Mid$(sValue, 2, 1)) + &H10000 * Asc(Mid$(sValue, 3, 1)) + &H1000000 * CDbl(Asc(Mid$(sValue, 4, 1)))
  105.       sValue = Format$(td, "000")
  106.    End If
  107.    sValue = [b]Left$[/b](sValue, lValueLength - 1)
  108. Else
  109.   sValue = ""
  110. End If
  111. On Error GoTo 0
  112. lResult = RegCloseKey(lKeyValue)
  113. ReadRegistry = sValue
  114. End Function
  115.  
  116. ' This routine allows you to write values into the entire Registry, it currently
  117. ' only handles string and double word values.
  118. Public Sub WriteRegistry(ByVal Group As Long, ByVal Section As String, ByVal Key As String, ByVal ValType As InTypes, ByVal Value As Variant)
  119. Dim lResult As Long
  120. Dim lKeyValue As Long
  121. Dim InLen As Long
  122. Dim lNewVal As Long
  123. Dim sNewVal As String
  124. On Error Resume Next
  125.  RegCreateKeyEx Group, Section, 0, "REG_SZ", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, ByVal 0&, lKeyValue, lResult
  126.  If ValType = ValDWord Then
  127.    lNewVal = CLng(Value)
  128.    InLen = 4
  129.    lResult = RegSetValueExLong(lKeyValue, Key, 0&, ValType, lNewVal, InLen)
  130.  Else
  131.    sNewVal = Value
  132.    InLen = Len(sNewVal)
  133.    lResult = RegSetValueExString(lKeyValue, Key, 0&, 1&, sNewVal, InLen)
  134.  End If
  135.  lResult = RegFlushKey(lKeyValue)
  136.  lResult = RegCloseKey(lKeyValue)
  137. End Sub