Results 1 to 5 of 5

Thread: Sizeof in C++. what is that in VB ?

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2000
    Posts
    12

    Thumbs up

    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.
    David

  2. #2
    Frenzied Member
    Join Date
    Aug 2000
    Location
    O!
    Posts
    1,177
    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

  3. #3
    Guest
    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:

    Code:
    Dim lngExample As Long
    
    MsgBox Len("Hello World!")  '  Would return 12.
    MsgBox Len(lngExample)      '  Would return 4.
    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.

    Good luck,
    Paul

  4. #4

    Thread Starter
    New Member
    Join Date
    Nov 2000
    Posts
    12

    Sizeof in C++. what is that in VB ?


    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
    David

  5. #5
    Frenzied Member
    Join Date
    Aug 2000
    Location
    O!
    Posts
    1,177
    Use sBufferOUT.dwStructSize = LenB(sBufferOUT)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width