Hi, it is about the syntax key SIZEOF(...) in C++.
I am looking for a VB predefined method which does the same as SIZEOF in C++.
e.g Num1 = SizeOf(Array1) //return the size of the Array1
How to write this in VB.
Printable View
Hi, it is about the syntax key SIZEOF(...) in C++.
I am looking for a VB predefined method which does the same as SIZEOF in C++.
e.g Num1 = SizeOf(Array1) //return the size of the Array1
How to write this in VB.
In C and C++, sizeof is resolved in the pre-compile stage along with #define, #include, etc. When the source is passed to the compiler, the statement "Num1 = SizeOf(Array1);" will have been replaced with "Num1 = 100;" (or whatever the byte size is for Array1). The size is obtained from the symbols table. All that sizeof does is eliminate the need for a runtime call.
I don't know that VB has a similar functionality. If it does, I would too be interested in knowing what it is. In the mean while, I will continue to use the LenB function.
HTH
I don't think there is a similar function in VB (but I could be mistaken, you might be able to do it with API calls or something). In VB you can use the Len() function to return either the length of a string or the number of bytes required to store a non-string like:
You could possibly combine Len() with the LBound() and UBound() functions to determine the size of an array. LBound() returns an arrays lower bounds and UBound() gives its upper.Code:Dim lngExample As Long
MsgBox Len("Hello World!") ' Would return 12.
MsgBox Len(lngExample) ' Would return 4.
Good luck,
Paul
Thanks to CCoder and PWNettle.
However I am using wininet API function and structure type
of Microsoft example. The following code is in a VB module.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Public Type INTERNET_BUFFERS
dwStructSize As Long ' used for API versioning.
' Set to sizeof
(INTERNET_BUFFERS)
Next As Long
lpcszHeader As Long
dwHeadersLength As Long
dwHeadersTotal As Long
lpvBuffer As Long
dwBufferLength As Long
dwBufferTotal As Long
dwOffsetLow As Long
dwOffsetHigh As Long
End Type
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
In a VB function, I initiate a variable of this INTERNET_BUFFERS type. as:
Dim sBufferOUT AS INTERNET_BUFFERS
sBufferOUT.dwHeaderLength = 0
sBufferOUT.dwHeaderTotal = 0
sBufferOUT.dwBufferLength = 0
sBufferOUT.dwOffsetLow = 0
...etc , but then
sBufferOUT.dwStructSize = ?? sizeof something ??
I dont know how to assign it a value, like the above Microsoft instruction
Thanks for help
Use sBufferOUT.dwStructSize = LenB(sBufferOUT)