Jump to content

Hostname: Difference between revisions

→‎=={{header|Visual Basic}}==: added Visual Basic example
(Added Rust)
(→‎=={{header|Visual Basic}}==: added Visual Basic example)
Line 961:
=={{header|Vim Script}}==
<lang vim>echo hostname()</lang>
 
=={{header|Visual Basic}}==
{{works with|Visual Basic|5}}
{{works with|Visual Basic|6}}
{{works with|VBA|Access 97}}
{{works with|VBA|6.5}}
{{works with|VBA|7.1}}
<lang vb>Option Explicit
 
Private Declare Function GetComputerName Lib "kernel32.dll" Alias "GetComputerNameW" _
(ByVal lpBuffer As Long, ByRef nSize As Long) As Long
Private Const MAX_COMPUTERNAME_LENGTH As Long = 31
Private Const NO_ERR As Long = 0
 
Private Function Hostname() As String
Dim i As Long, l As Long, s As String
s = Space$(MAX_COMPUTERNAME_LENGTH)
l = Len(s) + 1
i = GetComputerName(StrPtr(s), l)
Debug.Assert i <> 0
Debug.Assert l <> 0
Hostname = Left$(s, l)
End Function
 
Sub Main()
Debug.Assert Hostname() = Environ$("COMPUTERNAME")
End Sub</lang>
 
=={{header|zkl}}==
Cookies help us deliver our services. By using our services, you agree to our use of cookies.