申明API啊!Private Declare Function GetEnvironmentVariable Lib "kernel32" Alias "GetEnvironmentVariableA" (ByVal lpName As String, ByVal lpBuffer As String, ByVal nSize As Long) As Long

解决方案 »

  1.   

    sComputerName = GetEnvironmentVariable("COMPUTERNAME")
    代码是错误的。
      

  2.   

    代码应写成:Dim sComputerName As String
    Dim StrLen as LongStrLen=256
    sComputerName=Space$(StrLen)If GetEnvironmentVariable("COMPUTERNAME",sComputerName,StrLen) Then
       sComputerName=Left$(sComputerName,StrLen)
    End If
      

  3.   

    Private Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
    Private Sub Form_Load()
        'KPD-Team 1998
        'URL: http://www.allapi.net/
        'E-Mail: [email protected]
        Dim strString As String
        'Create a buffer
        strString = String(255, Chr$(0))
        'Get the computer name
        GetComputerName strString, 255
        'remove the unnecessary chr$(0)'s
        strString = Left$(strString, InStr(1, strString, Chr$(0)))
        'Show the computer name
        MsgBox strString
    End Sub
      

  4.   

    Private Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
    Private Sub Form_Load()
        'KPD-Team 1998
        'URL: http://www.allapi.net/
        'E-Mail: [email protected]
        Dim strString As String
        'Create a buffer
        strString = String(255, Chr$(0))
        'Get the computer name
        GetComputerName strString, 255
        'remove the unnecessary chr$(0)'s
        strString = Left$(strString, InStr(1, strString, Chr$(0)))
        'Show the computer name
        MsgBox strString
    End Sub