| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 957 人关注过本帖
标题:两个字符串为什么不能等于?版主帮看看什么原因啊!
只看楼主 加入收藏
wxflw
Rank: 6Rank: 6
等 级:侠之大者
帖 子:325
专家分:435
注 册:2012-1-29
结帖率:87.21%
收藏
已结贴  问题点数:20 回复次数:11 
两个字符串为什么不能等于?版主帮看看什么原因啊!
A=3B98E2DFFC6CB06A89DCB0D5C60A02069D3D9048DB16A7EEE539E93E3618CBE7AA53CA0B650DFD85C4F59FA156F7A2CC  '这个是MD5加密后写入注册表后取出的值长度96位,REG_SZ类型存的
B=3B98E2DFFC6CB06A89DCB0D5C60A02069D3D9048DB16A7EEE539E93E3618CBE7AA53CA0B650DFD85C4F59FA156F7A2CC  '这个是MD5加密后直接得到的值,也是96位,而且看上去都一样
为什么我这样判断会出问题:
 if A <> B then
    text1.text=1
    else
   text1.text=2
end  if
我的出的结果是 1 而不是 2  为什么?


[ 本帖最后由 wxflw 于 2012-12-3 17:13 编辑 ]
搜索更多相关主题的帖子: MD5加密 字符串 注册表 
2012-12-03 00:01
bczgvip
Rank: 14Rank: 14Rank: 14Rank: 14
等 级:贵宾
威 望:66
帖 子:1310
专家分:5312
注 册:2009-2-26
收藏
得分:5 
数据后面还有些多余数据。
2012-12-03 04:34
wxflw
Rank: 6Rank: 6
等 级:侠之大者
帖 子:325
专家分:435
注 册:2012-1-29
收藏
得分:0 
什么多余数据?能解释一下吗?不懂,我看过了,生成的数据就是这么多


[ 本帖最后由 wxflw 于 2012-12-3 09:44 编辑 ]

学习--------------学习-------------------学习--------------------!!
2012-12-03 09:42
yz1025
Rank: 8Rank: 8
等 级:蝙蝠侠
威 望:6
帖 子:491
专家分:919
注 册:2012-10-26
收藏
得分:5 
图片附件: 游客没有浏览图片的权限,请 登录注册

不要投我
2012-12-03 09:52
wxflw
Rank: 6Rank: 6
等 级:侠之大者
帖 子:325
专家分:435
注 册:2012-1-29
收藏
得分:0 
A== QueryValue(HKEY_CURRENT_USER, "Software\AAAAAA\setfil", "set")'从注册表中提取键值
’也就是A=3B98E2DFFC6CB06A89DCB0D5C60A02069D3D9048DB16A7EEE539E93E3618CBE7AA53CA0B650DFD85C4F59FA156F7A2CC  '这个是MD5加密后写入注册表后取出的值长度96位,REG_SZ类型存的
B=Md5_Srg_Cc("CC")  'CC是提取的网卡地址,然后把网卡地址加密
’也就是B=3B98E2DFFC6CB06A89DCB0D5C60A02069D3D9048DB16A7EEE539E93E3618CBE7AA53CA0B650DFD85C4F59FA156F7A2CC  '这个是MD5加密后直接得到的值,也是96位,而且看上去都一样
'我用
text3.text=A
text4.text=B
'上面两个文本框显示他们的值都正确可是下面为什么还是判断为<>?
if A <> B then
     text1.text=1
     else
    text1.text=2
 end  if
还是返回的1

学习--------------学习-------------------学习--------------------!!
2012-12-03 11:44
Artless
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:103
帖 子:4211
专家分:28888
注 册:2009-4-8
收藏
得分:5 
读写过程?

无知
2012-12-03 12:54
wxflw
Rank: 6Rank: 6
等 级:侠之大者
帖 子:325
专家分:435
注 册:2012-1-29
收藏
得分:0 


Option Explicit
Global Const REG_SZ As Long = 1
Global Const REG_DWORD As Long = 4
Global Const HKEY_CLASSES_ROOT = &H80000000
Global Const HKEY_CURRENT_USER = &H80000001
Global Const HKEY_LOCAL_MACHINE = &H80000002
Global Const HKEY_USERS = &H80000003

Global Const ERROR_NONE = 0
Global Const ERROR_BADDB = 1
Global Const ERROR_BADKEY = 2
Global Const ERROR_CANTOPEN = 3
Global Const ERROR_CANTREAD = 4
Global Const ERROR_CANTWRITE = 5
Global Const ERROR_OUTOFMEMORY = 6
Global Const ERROR_INVALID_PARAMETER = 7
Global Const ERROR_ACCESS_DENIED = 8
Global Const ERROR_INVALID_PARAMETERS = 87
Global Const ERROR_NO_MORE_ITEMS = 259

Global Const KEY_ALL_ACCESS = &H3F

Global Const REG_OPTION_NON_VOLATILE = 0

Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
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, ByVal lpSecurityAttributes As Long, phkResult As Long, lpdwDisposition As Long) As Long
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
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
Declare Function RegQueryValueExLong Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Long, lpcbData As Long) As Long
Declare Function RegQueryValueExNULL Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, ByVal lpData As Long, lpcbData As Long) As Long
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
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
Private Declare Function RegDeleteKey& Lib "advapi32.dll" Alias "RegDeleteKeyA" (ByVal hKey As Long, ByVal lpSubKey As String)
Private Declare Function RegDeleteValue& Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal hKey As Long, ByVal lpValueName As String)

Public Function DelKey(lKey As Long, sKeyName As String)
    Dim lVal As Long
    Dim hKey As Long
    lVal = RegOpenKeyEx(lKey, sKeyName, 0, KEY_ALL_ACCESS, hKey)
    lVal = RegDeleteKey(lKey, sKeyName)
    RegCloseKey (hKey)
End Function

Public Function DelVal(lKey As Long, sKeyName As String, sValueName As String)
    Dim lVal As Long
    Dim hKey As Long
    lVal = RegOpenKeyEx(lKey, sKeyName, 0, KEY_ALL_ACCESS, hKey)
    lVal = RegDeleteValue(hKey, sValueName)
    RegCloseKey (hKey)
End Function

Public Function SetVal(ByVal hKey As Long, sValueName As String, lType As Long, vValue As Variant) As Long
    Dim lValue As Long
    Dim sValue As String
    Select Case lType
    Case REG_SZ
        sValue = vValue
        SetVal = RegSetValueExString(hKey, sValueName, 0&, lType, sValue, Len(sValue))
    Case REG_DWORD
        lValue = vValue
        SetVal = RegSetValueExLong(hKey, sValueName, 0&, lType, lValue, 4)
    End Select
End Function

Function QueryValueEx(ByVal lhKey As Long, ByVal szValueName As String, vValue As Variant) As Long
    Dim cch As Long
    Dim lrc As Long
    Dim lType As Long
    Dim lValue As Long
    Dim sValue As String
    On Error Resume Next
    lrc = RegQueryValueExNULL(lhKey, szValueName, 0&, lType, 0&, cch)
    If lrc <> ERROR_NONE Then Error 5
    Select Case lType
    Case REG_SZ
        sValue = String(cch, 0)
        lrc = RegQueryValueExString(lhKey, szValueName, 0&, lType, sValue, cch)
        If lrc = ERROR_NONE Then
            vValue = Left$(sValue, cch)
        Else
            vValue = Empty
        End If
    Case REG_DWORD
        lrc = RegQueryValueExLong(lhKey, szValueName, 0&, lType, lValue, cch)
        If lrc = ERROR_NONE Then vValue = lValue
    Case Else
        lrc = -1
    End Select
    QueryValueEx = lrc
End Function

Public Function CreateNewKey(lKey As Long, sNewKeyName As String)
    Dim hNewKey As Long
    Dim lVal As Long
    lVal = RegCreateKeyEx(lKey, sNewKeyName, 0&, vbNullString, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, 0&, hNewKey, lVal)
    RegCloseKey (hNewKey)
End Function

Public Function SetKeyValue(lKey As Long, sKeyName As String, sValueName As String, vValueSetting As Variant, lValueType As Long)
    Dim lVal As Long
    Dim hKey As Long
    lVal = RegOpenKeyEx(lKey, sKeyName, 0, KEY_ALL_ACCESS, hKey)
    lVal = SetVal(hKey, sValueName, lValueType, vValueSetting)
    RegCloseKey (hKey)
End Function

Public Function QueryValue(lKey As Long, sKeyName As String, sValueName As String)
    Dim lVal As Long
    Dim hKey As Long
    Dim vValue As Variant
    lVal = RegOpenKeyEx(lKey, sKeyName, 0, KEY_ALL_ACCESS, hKey)
    lVal = QueryValueEx(hKey, sValueName, vValue)
    QueryValue = vValue
    RegCloseKey (hKey)
End Function

'写
SetKeyValue HKEY_CURRENT_USER, "Software\AAAAAA\setfil", "set", ZCle, REG_SZ  ’ZCle是楼上A的值
'读
QueryValue(HKEY_CURRENT_USER, "Software\AAAAAA\setfil", "set")'因为刚学这个注册表的东西好多都看不懂,只能一样一样来通过测试去理解每个函数的意思,我一直都是这么学起来的


[ 本帖最后由 wxflw 于 2012-12-3 13:18 编辑 ]

学习--------------学习-------------------学习--------------------!!
2012-12-03 13:15
wxflw
Rank: 6Rank: 6
等 级:侠之大者
帖 子:325
专家分:435
注 册:2012-1-29
收藏
得分:0 

我这样做通过了,什么原因?求解释!!我不懂

if CStr(A) <> CStr(B) then
      text1.text=1
      else
     text1.text=2
 end  if

学习--------------学习-------------------学习--------------------!!
2012-12-03 17:53
wxflw
Rank: 6Rank: 6
等 级:侠之大者
帖 子:325
专家分:435
注 册:2012-1-29
收藏
得分:0 
又出现新问题
我在标准模块中把A B都设为全局变量
Public A ,B
为什么在模块中用楼上方法通过了,在另一个窗体中用
if CStr(A) <> CStr(B) then
       text1.text=1
       else
      text1.text=2
 end  if
又不行了呢?改成
if A <> B then
      text1.text=1
      else
     text1.text=2
 end  if
也不行返回的都是 1  郁闷都搞糊涂了!

学习--------------学习-------------------学习--------------------!!
2012-12-03 18:34
wxflw
Rank: 6Rank: 6
等 级:侠之大者
帖 子:325
专家分:435
注 册:2012-1-29
收藏
得分:0 
晕!!我彻底搞晕了
if CStr(A) = CStr(B) then
if val(A) = val(B) then
A 和 B 的值不一样都成立了全部判断A=B我郁闷了!搞不明白了!头晕

学习--------------学习-------------------学习--------------------!!
2012-12-03 18:58
快速回复:两个字符串为什么不能等于?版主帮看看什么原因啊!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.037194 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved