Accessing system property is pretty easy with VB6 code. This can be useful when programmers need to refer the system name in the code.
Steps
- Declare the GetComputerNameA function which resides in the kernel32 library.
- Create function to fetch the Computer Name.
- Use the function
The Kernel functions
Declare Function GetComputerNameA Lib “kernel32” (ByVal lpBuffer As String, nSize As Long) As Long
Get the computer name
Define a new function to do the rest of the task. So you can reuse the code.
Public Function GetComputerName() As String
Dim sResult As String * 255
GetComputerNameA sResult, 255
GetComputerName = Left$(sResult, InStr(sResult, Chr$(0)) - 1)
End Function
Calling the function
Just invoke the function and place values to a Text Box
Text1.Text = GetComputerName