Option Compare Database
Private Declare PtrSafe Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Private Declare PtrSafe Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
'Получаем имя компьютера
Public Function FNCompName() As String
Dim r As Long
Dim sCompName As String
Dim slength As Long
slength = 255
sCompName = String$(slength, vbNullChar)
r = GetComputerName(sCompName, slength)
FNCompName = Left$(sCompName, InStr(sCompName, vbNullChar) - 1)
End Function
'=========================================================
Function fun_GetUserName() As String
fGetUserName = VBA.Environ("UserName")
End Function
'=========================================================
'Получаем имя пользователя
Public Function FnUserName() As String
Dim r As Long
Dim sUserName As String
Dim slength As Long
slength = 255
sUserName = String$(slength, vbNullChar)
r = GetUserName(sUserName, slength)
FnUserName = Left$(sUserName, InStr(sUserName, vbNullChar) - 1)
End Function
''функция LCase конвертирует строку в нижний регистр. UCase - в верхний.
''ф-я InStr возвращает позицию символа в строке.
''ф-я Left возвращает нужное кол-во символов с левой стороны строки.
'
'Dim SearchString As String, SearchChar As String, MyPos As Integer, Comp As String
'SearchString = "ПЕТЯ-ПК"
'SearchChar = "-"
'MyPos = InStr(SearchString, SearchChar)
'Comp = Left(SearchString, MyPos - 1)
'Comp = LCase(Comp)