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里只显示出"黑色"? 是什么原因? 都显示出来 ..应该要怎样写?
VB中GetPrivateProfileString函数问题
因为你没把空字节去掉 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
温馨提示:答案为网友推荐,仅供参考