Private Sub Command1_Click()
Dim sSection As String
Dim sKeyName As String
Dim sDefault As String
Dim sProfile As String
Dim lRetCode As Long
Dim lSize As Long
Dim Gs_SysName As String
sSection = "CONFIG"
sKeyName = "SysName"
sDefault = "0000000000000000000000000000000000000000000000000000000000000000000"
Gs_SysName = sDefault
lSize = Len(sDefault)
sProfile = App.Path & "\setup\Feq.ini"
lRetCode = GetPrivateProfileString(sSection, sKeyName, sDefault, Gs_SysName, lSize, sProfile)
Gs_SysName = Left(Trim(Gs_SysName), lRetCode)
If StrComp(Gs_SysName, sDefault) Then
MsgBox "请检查配置文件的参数值(Gs_SysName)!", vbInformation + vbOKOnly, "信息提示" End If
End Sub问题:Gs_SysName, sDefault两个字符串的长度都是67,而且又都是0,但不知道为什么就是不相等!困惑亚!谢谢了!
len(gs_sysname)
len(sdefault)
这两个值比较看看?
lRetCode = GetPrivateProfileString(sSection, sKeyName, sDefault, Gs_SysName, lSize, sProfile)
Gs_SysName = Left(Trim(Gs_SysName), lRetCode)
是不是有什么参数错了,再检查检查
这个步骤之后就从0变成了“空格”,不知道是为什么,还请各位多多帮忙,谢谢了!
Gs_SysName = Left(Trim(Gs_SysName), lRetCode) 这两句以后,Gs_SysName 还能是0000000..吗?
MsgBox "请检查配置文件的参数值(Gs_SysName)!", vbInformation + vbOKOnly, "信息提示"
End If
你的意思是上面为什么没有弹出对话框“请检查配置文件的参数值(Gs_SysName)!"是吗?,你的比较StrComp(Gs_SysName, sDefault)相等返回的是0,如果非0才会弹出对话框阿,StrComp(Gs_SysName, sDefault)比较小于返回-1、相等0、大于返回1,而if语句是0相当于false,其他的非0相当于true.
Dim sSection As String
Dim sKeyName As String
Dim sDefault As String
Dim sProfile As String
Dim lRetCode As Long
Dim lSize As Long
Dim Gs_SysName As String
sSection = "CONFIG"
sKeyName = "SysName"
sDefault = "0000000000000000000000000000000000000000000000000000000000000000000"
Gs_SysName = Space(250)
lSize = Len(Gs_SysName)
sProfile = App.Path & "\setup\Feq.ini"
Call GetPrivateProfileString(sSection, sKeyName, sDefault, Gs_SysName, lSize, sProfile)
lRetCode = InStr(1, Gs_SysName, Chr(0))
Gs_SysName = Left(Gs_SysName, lRetCode-1)
If StrComp(Gs_SysName, sDefault) Then
MsgBox "请检查配置文件的参数值(Gs_SysName)!", vbInformation + vbOKOnly, "信息提示" End If
End Sub