I downloaded the sample code in thread222-760425; however, when I try to use Trim$(hostname), nothing happens, the variable still contain vbNullChar characters. How do I remove vbNullChar characters in a string. Here is sample code.
Because as you can see hostname was declare as a 256 character string. How do I remove the excess characters. The Trim$(hostname) did not remove the excess characters.
I tried,
but this just remove the vbNullChar and left a lot of spaces.
TIA
Mike
Code:
Private Declare Function gethostname Lib "WSOCK32.DLL" (ByVal hostname$, _
ByVal HostLen As Long) As Long
Private Const SOCKET_ERROR = -1
Dim hostname As String * 256
If gethostname(hostname, 256) = SOCKET_ERROR Then
'output error
Exit Function
Else
hostname = Trim$(hostname)
End If
I tried,
Code:
hostname = replace(hostname, vbNullChar, "")
TIA
Mike