VB中GetPrivateProfileString函数问题

PrivateDeclareFunctionGetPrivateProfileStringLib"kernel32"Alias"GetPrivateProfileStri... Private Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpString As String, ByVal lpFileName As String) As Long Private Sub command1_Click() Dim msg As String,msg2 as string msg = Space(255) GetPrivateProfileString "se1", "Name", "", msg, 255, App.Path + "\001.ini" MsgBox msg msg2 = space (255) GetPrivateProfileString "se2", "Name", "", msg2, 255, App.Path + "\001.ini" text1.text = msg & msg2 End Sub 001.ini文件的内容为 [se1] Name = 黑色 [se2] Name = 红色 上面程序text1应该要显示出 "黑色红色"才对啊 为什么在text1里只显示出"黑色"? 是什么原因? 都显示出来 ..应该要怎样写? 展开
 我来答
手机用户87629
2014-06-17 · 超过67用户采纳过TA的回答
知道答主
回答量:127
采纳率:0%
帮助的人:127万
展开全部
因为你没把空字节去掉 Private Sub command1_Click() Dim msg As String, msg2 As String msg = Space(255) GetPrivateProfileString "se1", "Name", "", msg, 255, App.Path + "\001.ini" '这里去掉空字节 msg = Left$(msg, InStr(1, msg, Chr(0)) - 1) MsgBox msg msg2 = Space(255) GetPrivateProfileString "se2", "Name", "", msg2, 255, App.Path + "\001.ini" '这里去掉空字节 msg2 = Left$(msg2, InStr(1, msg2, Chr(0)) - 1) Text1.Text = msg & msg2 End Sub
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式