Option Explicit
Dim path As String * 255
Private Declare Function GetCurrentDirectoryA Lib "kernel32" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As LongPrivate Sub Form_Load()
    
    Dim i As String
    i = GetCurrentDirectoryA(Len(path), path)
    path = path & "\config.txt"
    MsgBox path
    
End Sub
msgbox里怎么显示不出来\config.txt,而只显示当前路径,拜托

解决方案 »

  1.   

    path 是保留字
    将path = path & "\config.txt"
        MsgBox path
    改为
     MsgBox path & "\config.txt"
      

  2.   

    API 返回的字符有个结束符0x00,必须删掉它,才能在后面加新的字符串
      

  3.   

    left$(path,instring(path,chr(0),1)-1) & "\config.txt"凭记忆写的,不知参数格式是否对。但道理就是这样的。从左读到chr(0)的位置。
      

  4.   

    Option Explicit
    Dim path As String * 255
    Private Declare Function GetCurrentDirectoryA Lib "kernel32" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As LongPrivate Sub Form_Load()
        
        path = Left$(path, GetCurrentDirectoryA(Len(path), path)) & "\config.txt"
        MsgBox RTrim$(path)
        
    End Sub
      

  5.   

    path 被声明为长度是255的字符串。当第一次给它赋值时,即使没有被长度正好是255的字符串填充,那么也会被Chr(0)填满。但是你还要在让它存储另外的字符,它当然“吃”不下了。
      

  6.   

    Option Explicit
    Dim path As String * 255
    Private Declare Function GetCurrentDirectoryA Lib "kernel32" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As LongPrivate Sub Form_Load()
        
        Dim i As Long
        i = GetCurrentDirectoryA(Len(path), path)
        path =  Left(path, Instr(1, path, chr(0)) -1) & "\config.txt"
        MsgBox path
        
    End Sub
      

  7.   

    同意VertyNew,直接用app.path不是更方便吗?