在做项目的时候需要从ini文件中读取数据
现在ini文件中定义了
[USER]
ユーザ = 外注管理Gr 我在excel中的读取后
Dim lngResult As Long
    Dim strFileName
    Dim strResult As String * 255
    strFileName = ThisWorkbook.Path & "\sagyo.ini"
    
    lngResult = GetPrivateProfileString("USER", "ユーザ", "", strResult, Len(strResult), strFileName)
    If lngResult <> 0 Then
        G_USER = TRIM(Left(strResult, lngResult))
    End If
是这样的方式读取的
但是取的的G_USER 中的值却是“外注管理Gr....”后面好像是些小点
本来以为是空位。结果trim也不行。所以我想问下是什么问题?
各位有什么好方法解决么?
麻烦各位帮忙了
马上项目就的交了

解决方案 »

  1.   

    用以下语句:    If lngResult <> 0 Then 
            G_USER = Mid(strResult, 1, InStr(1, strResult, Chr(0)))
           '如果不行用这个语句:
           'G_USER = Mid(strResult, 1, InStr(1, strResult, Chr(32)))
        End If
      

  2.   


    '上面那样还是多一个字符.应该是下面这样
    '用以下语句:     If lngResult <> 0 Then 
            G_USER = Mid(strResult, 1, InStr(1, strResult, Chr(0))-1) 
          '如果不行用这个语句: 
          'G_USER = Mid(strResult, 1, InStr(1, strResult, Chr(32))-1) 
        End If