实在不行用Replace(str," ","")去掉空格好了
解决方案 »
- 咨询个VB控件问题,谢谢!
- 问大家一个关于excel宏的简单问题啊
- 如果是在微软操作系统下开发软件,大家一般用的是微软的哪个操作系统开发软件的?如何才能使自己开发出来的软件能在微软的各种操作系统下
- WINSOCK方法怎样通过防火墙,去连接另一台开发机
- 用友软件的表格是用什么做的。
- 求助啊
- WM_LBUTTONDOWN的值是多少?
- 一个愚蠢的API调用问题----如何重起计算机。
- 怎样编写免费通过icq网关发短信的程序? 说具体点,连接那个ip,?udp还是tcp?端口是什么?发送信息的格式时什么样的?
- VB利用驱动读内存死机
- 为什么在我的vb这找不到EXCEl的控件?
- 我遇到的怪事(关于pictureBox的),但我不知道怎么解决,请兄不令指教,谢谢!
Const HKEY_LOCAL_MACHINE = &H80000002
Const REG_SZ = 1&
Const KEY_QUERY_VALUE = &H1&
Const KEY_ENUMERATE_SUB_KEYS = &H8&
Const KEY_NOTIFY = &H10&
Const READ_CONTROL = &H20000
Const STANDARD_RIGHTS_READ = READ_CONTROL
Const KEY_READ = STANDARD_RIGHTS_READ Or KEY_QUERY_VALUE Or KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY
Const HKEY_USERS = &H80000003Function GetStringValue(ByVal MainKeyHandle As Long, ByVal Subkey As String, entry As String)
rtn = RegOpenKeyEx(MainKeyHandle, Subkey, 0, KEY_READ, hkey) 'open the key
If rtn = ERROR_SUCCESS Then 'if the key could be opened then
sBuffer = Space(255) 'make a buffer
lBufferSize = Len(sBuffer)
rtn = RegQueryValueEx(hkey, entry, 0, REG_SZ, sBuffer, lBufferSize) 'get the value from the registry
If rtn = ERROR_SUCCESS Then 'if the value could be retreived then
rtn = RegCloseKey(hkey) 'close the key
sBuffer = Trim(sBuffer)
GetStringValue = Left(sBuffer, Len(sBuffer) - 1) 'return the value to the user
Else 'otherwise, if the value couldnt be retreived
GetStringValue = "" 'return Error to the user
End If
Else 'otherwise, if the key couldnt be opened
GetStringValue = "" 'return Error to the user
End IfEnd Function SysIcon = GetStringValue(HKEY_CURRENT_USER, "Software\Microsoft\Windows\CurrentVersion\Explorer\CLSID\{20D04FE0-3AEA-1069-A2D8-08002B30309D}\DefaultIcon", "")
Private Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExW" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, ByVal lpData As String, lpcbData As Long) As Long
注意上面定义的Alias是RegQueryValueExW而不是通常的RegQueryValueExA
然后对获得的结果进行strConv转换:
sysicon = GetStringValue(HKEY_CURRENT_USER, "Software\Microsoft\Windows\CurrentVersion\Explorer\CLSID\{645FF040-5081-101B-9F08-00AA002F954E}\DefaultIcon", "")
Debug.Print StrConv(sysicon, vbFromUnicode)
到了win2000下就没辙了……
Function CutSpace(Str as string) as string
if not instr(str," ") then _
cutspace=str: _
exit function
dim s() as string,i as integer,return_str as string
s=split(str," ")
for i= 0 to ubound(s)
return_str=return_str+s(i)
next
erase s
CutSpace=return_str
End Function
返回的字符串用Debug命令print出来是
abcde d e
若设置成abcdefg则返回
abcdefg e f g
而用MsgBox "返回字符串"则显示为abcde和abcdefg
但用MsgBox "返回字符串"&"1"则还是显示为abcde和abcdefg而不是abcde1和abcdefg1
Private Function TrimNull(ByVal szNull As String) As String
Dim m%
m = InStr(szNull, Chr$(0))
If (m) Then ' Win95 puts adds a null value
TrimNull = Mid$(szNull, 1, m - 1)
Else
TrimNull = "" ' WinNT does not add a nullchar
End If
End Function把这句话
sBuffer = Trim(sBuffer)
换成
sBuffer = TrimNull(sBuffer)