Private Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As LongPrivate Sub Command1_Click()
Dim n As String * 20
GetComputerName n, 20
MsgBox n
End Sub

解决方案 »

  1.   


    Public Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Longprivate form_load()
     ComputerName = Space(1024)
    lsize& = 100
    Call GetComputerName(ComputerName, lsize&)
    ComputerName = Left(ComputerName, lsize&)
    text1.text=ComputerName
    end if
      

  2.   


     用这段代码,微软的:
    Public Function StripTerminator(ByVal sInput As String) As String
        Dim ZeroPos As Integer
        ZeroPos = InStr(1, sInput, vbNullChar)
        If ZeroPos > 0 Then
            StripTerminator = Left$(sInput, ZeroPos - 1)
        Else
            StripTerminator = sInput
        End If
    End Function