Click to See Complete Forum and Search --> : Int to DWORD


slcotten
September 6th, 2001, 08:58 AM
How do I convert an integer value to a DWORD value?

DSJ
September 6th, 2001, 09:52 AM
In VB a Long is the equivelent of a DWORD so use:



Dim I as int
dim L as long

I = 10
L = Clng(i)

slcotten
September 6th, 2001, 10:15 AM
Ok Say I = 0 and we add it to the registry as a DWORD value. The decimal value of the DWORD is now 48. Now we want to retrieve it from the regsitry as long and then convert it to Integer using CInt. The value is still 48. What am I doing wrong?

DSJ
September 6th, 2001, 11:15 AM
0 should = 0 no matter if it's an int, long, or any other numeric data type. Are you sure you are writing the correct value to the registry? Could you post the code?

slcotten
September 6th, 2001, 12:24 PM
' These are the basic funcions that write to the
' registry... additional functions are used to open keys
' Where ValueName = the registry value name and
' Setting = the value we are writing to the registry.

' Result is the result of previously opening a key

public Function SetDWORDValue(ValueName as string, Setting as Long) as Long
Dim RetVal as Long

RetVal = RegSetValueEx(Result, ValueName, 0&, REG_DWORD, Setting, 4&)
SetDWORDValue = RetVal
End Function

public Function GetDWORDValue(ValueName as string) as Long
Dim RetVal as Long
Dim lBuffData as Long

RetVal = RegQueryValueEx(Result, ValueName, 0&, REG_DWORD, lBuffData, 4&)
GetDWORDValue = lBuffData
End Function

' This goes in Form_QueryUnload
SetDWORDValue "UseGlobal", CLng(chkGlobal.Value)

' and this in Form_Load
chkGlobal.Value = CInt(GetDWORDValue("UseGlobal"))





Thanks for your help DSJ

DSJ
September 6th, 2001, 01:19 PM
This code is working for me as expected...????


option Explicit
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 Const REG_DWORD = 4
private Const HKEY_CURRENT_USER = &H80000001
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

public Function SetDWORDValue(ValueName as string, Setting as Long) as Long
Dim RetVal as Long
RetVal = RegSetValueEx(HKEY_CURRENT_USER, ValueName, 0&, REG_DWORD, Setting, len(Setting))

SetDWORDValue = RetVal
End Function

public Function GetDWORDValue(ValueName as string) as Long
Dim RetVal as Long
Dim lBuffData as Long

RetVal = RegQueryValueEx(HKEY_CURRENT_USER, ValueName, 0&, REG_DWORD, lBuffData, len(lBuffData))
GetDWORDValue = lBuffData
End Function


private Sub Command1_Click()
chkGlobal.Value = CInt(GetDWORDValue("UseGlobal"))
End Sub

private Sub Command2_Click()
SetDWORDValue "UseGlobal", CLng(chkGlobal.Value)
End Sub





Don't know what to tell you...?????

John G Duffy
September 6th, 2001, 03:43 PM
48 is the ascii value for a Numeric 0 so maybe that came into play in your first complaint.
If you passed it a numeric 0 instead of CHR(0), this would account for the error.

John G