What is a buffer?
Posted on 2003-03-11
This question is mostly academic.
A developer that left our company wrote a function using the GetComputerName API:
Public Function GetServerName()
Dim strbuffer As String * 250
Dim lngSize As Long
'--- Get the computer name
lngSize = Len(strbuffer) + 1
GetComputerName strbuffer, lngSize
GetServerName = Mid(strbuffer, 1, lngSize)
It works fine, but I just want to know what's going on here.
First, when you declare a variable as string * 250, what's going on? Are you limiting the size of that variable to 250 characters?
Second, "lngSize = Len(strbuffer) + 1". Len(strbuffer) is equal to 250 when I view in the immediate window, but lngSize is equal to 13 the Length of the Computer Name. What is going on here? How does 250 + 1 = 13?