# GetRegistryValueType
{: .no_toc }

Returns the data type of a named registry value without reading its data.

Syntax: *object*.**GetRegistryValueType**( *hKey*, *subKey*, *valueName* ) **As REGTYPES**

*hKey*
: *required* A **Long** holding a key handle, usually a predefined root key. Pass a [**RegKeyspace**](/tB/Packages/Contributed/WinReg/RegKeyspace.md) constant such as `HKEY_CURRENT_USER` or `HKEY_LOCAL_MACHINE`.

*subKey*
: *required* A **String** specifying the path to the registry key beneath *hKey*, for example `"Software\MyApp"`.

*valueName*
: *required* A **String** naming the value whose type is queried.

**GetRegistryValueType** opens *subKey* under *hKey* with `KEY_QUERY_VALUE` access, calls `RegQueryValueEx` to retrieve the type code without reading the value data, then closes the key. It returns a `REGTYPES` member identifying the data type stored under *valueName*---for example `REG_SZ`, `REG_DWORD`, or `REG_BINARY`.

If the key cannot be opened or the value query fails, the function returns `REGTYPES.REG_NONE`.

> [!WARNING] 1.0.1.1
> The function returns `REG_NONE` for every value that holds data. It asks `RegQueryValueEx` for the type with a data pointer and a size of zero, and the call fails with error 234 (*more data*) when the value has any data. Only a value of zero length, such as an empty `REG_BINARY`, gets its type. A program that needs the type of a value calls `RegQueryValueEx` itself.

> [!NOTE] 1.0.1.1
> *hKey* is declared as **Long**, not as **RegKeyspace**. The two types are assignment-compatible in twinBASIC, so passing a `RegKeyspace` constant works without an explicit cast.

### Example

This example reads the data type of the `UserName` value under `HKEY_CURRENT_USER\Software\MyApp` and displays a message describing the type.

```tb
Dim reg As New RegCls
Dim t As REGTYPES

t = reg.GetRegistryValueType(HKEY_CURRENT_USER, "Software\MyApp", "UserName")

Select Case t
    Case REGTYPES.REG_SZ, REGTYPES.REG_EXPAND_SZ
        MsgBox "UserName is a string value."
    Case REGTYPES.REG_DWORD
        MsgBox "UserName is a DWORD value."
    Case REGTYPES.REG_NONE
        MsgBox "Value not found or key could not be opened."
    Case Else
        MsgBox "UserName has type code " & CStr(t) & "."
End Select
```

### See Also

- [ReadString](/tB/Packages/Contributed/WinReg/RegCls/ReadString.md) method
- [ReadDWORD](/tB/Packages/Contributed/WinReg/RegCls/ReadDWORD.md) method
- [ValueExists](/tB/Packages/Contributed/WinReg/RegCls/ValueExists.md) method
