DonationCoder.com forum
 
Read-only archive. This is a static copy of the DonationCoder.com forum. Reading and searching work as before; logging in, posting and private messages do not.
Archive of 2026-10-21 · About this archive · Main site

Author Topic: Visual Basic 6 App.s in need of a registry addition.  (Read 5,435 times)

OptimalDesigns

  • (retired) Mathematical Engineer
  • Supporting Member
  • Joined in 2018
  • **
  • Posts: 70
Visual Basic 6 App.s in need of a registry addition.
« on: May 11, 2023, 11:30 PM »
My code comes from another of my App's ... some code not working in my new app.s is as follows:
Code
Global Const RegODEkey = "Software\Optimal Designs Enterprise\" & ProgramName
ooo

' Set 'tPause' value in Registry
        If CheckRegistryKey(HKEY_CURRENT_USER, RegODEkey) = False Then
          CreateRegistryKey HKEY_CURRENT_USER, RegODEkey
'         SetRegistryValue HKEY_CURRENT_USER, RegODEkey, "tPause", REG_SZ, "20" ... seems ok to start/compile!
          SetRegistryValue RegODEkey, "tPause", tPause.Text
        End If
        tPause.Text = GetRegistryValue(RegODEkey, "tPause", REG_SZ)
        If tPause.Text = "" Then tPause = "20"
ooo

' Write / Create a Registry value.
' Use KeyName = "" for the default value.
' Supports only DWORD, SZ, and BINARY value types.
Sub SetRegistryValue(ByVal hKey As Long, ByVal KeyName As String, ByVal ValueName As String, ByVal KeyType As Integer, value As Variant)
    Dim handle As Long, lngValue As Long
    Dim strValue As String
    Dim binValue() As Byte, length As Long
    
    ' Open the key, exit if not found.
    If mdlRegistryAPI.RegOpenKeyEx(hKey, KeyName, 0, KEY_WRITE, handle) Then Exit Sub
    Select Case KeyType
        Case REG_DWORD
            lngValue = value
            RegSetValueEx handle, ValueName, 0, KeyType, lngValue, 4
        Case REG_SZ
            strValue = value
            RegSetValueEx handle, ValueName, 0, KeyType, ByVal strValue, Len(strValue)
        Case REG_BINARY
            binValue = value
            length = UBound(binValue) - LBound(binValue) + 1
            RegSetValueEx handle, ValueName, 0, KeyType, binValue(LBound(binValue)), length
    End Select
    
    ' Close the key.
    RegCloseKey handle
End Sub

Ideas where my problem is?  My app can be downloaded at goal-driven.net/download/ and choose "Match-n-Freq (v. 6.6) ... 4 mB" ... its free and has VB6 source code with it.

Original address: https://www.donationcoder.com/forum/index.php?topic=53431.0