Public Function GetCName(Val) As Boolean On Error GoTo Function_Err Dim sComputerName As String 'the name of computer Dim lResult As Long 'the return value of API function "GetComputerName" Dim RV As Boolean Dim lComputerNameLen As Long 'the length of computer name
lResult = GetComputerName(sComputerName, lComputerNameLen) If lResult <> 0 Then Val = Left$(sComputerName, lComputerNameLen) RV = True Else RV = False End If GetCName = RV
Exit Function Function_Exit: GetCName = False Exit Function Function_Err: MsgBox Err.Description Resume Function_Exit End Function
On Error GoTo Function_Err
Dim sComputerName As String 'the name of computer
Dim lResult As Long 'the return value of API function "GetComputerName"
Dim RV As Boolean
Dim lComputerNameLen As Long 'the length of computer name
lComputerNameLen = 256
sComputerName = Space(lComputerNameLen)
lResult = GetComputerName(sComputerName, lComputerNameLen)
If lResult <> 0 Then
Val = Left$(sComputerName, lComputerNameLen)
RV = True
Else
RV = False
End If
GetCName = RV
Exit Function
Function_Exit:
GetCName = False
Exit Function
Function_Err:
MsgBox Err.Description
Resume Function_Exit
End Function