a VBscript version of sizeof() ?

Results 1 to 3 of 3

Thread: a VBscript version of sizeof() ?

  1. #1
    Raymond Guest

    Default a VBscript version of sizeof() ?

    Is there a sizeof() in vbscript? I need to use it to find out the size of an array, both in bytes, or in array units. Currently i am using a loop everytime i need to check the size which i find very redundunt. <BR>Another question. Is there a way to call a function (? sub?) from the "A HREF" tag? For example, in javascript, i can do this,<BR>a href="javascript:functionOne()". A VB version perhaps?<BR>Thanks in advance.<BR>Raymond

  2. #2
    Join Date
    Dec 1969
    Los Angeles, CA

    Default 2 questions in one huh

    R&D UBOUND(Arrarname)<BR><BR>with a small change to that it will give you the number of elements in an array...for bytes sorry never tried and dont know<BR><BR>WHY do you ONLY wnat to use VBS in client side why not just JS<BR><BR>If you MUST, call the function in the onclick event of the hyperlink

  3. #3
    Join Date
    Dec 1969

    Default Simple answer: No.

    You can find the number of elements of an array, as Akhilesh pointed out, but that&#039s about it.<BR><BR>If you did not know it already, VBS does *NOT* support contiguous structures, as found in C/C++. Instead, *everything* is some kind of COM object, and since a COM object typically has VTable pointers, etc., etc., as overhead, there is no reliable way to predict the size.<BR><BR>The exceptions are, of course, the "primitive" types.<BR><BR>EVERY value in VBS (and JS, incidentally) a COM VARIANT. Which, on an x86 machine, just happens to be 16 bytes in size. An array in VBS is actually a VARIANT that is a pointer to an "array of VARIANT". So I guess you could say that the size is 16 * ( 2 + UBound(arrayname) ).<BR><BR>BUT...that assumes that every element of the array is a numeric value! Arrays in VBS are *not* homogeneous. It is quite possible to do<BR><BR>myArray(0) = 17<BR>myArray(1) = #10/27/2000#<BR>myArray(2) = "This is a test"<BR>myArray(3) = Server.CreateObject("ADODB.RecordSet")<BR>myArray( 4) = Array("an array as an element of an array",myArray(3),99)<BR>...<BR><BR>See how complex it gets?<BR><BR>And how big is element 3 of that array? I have no idea.<BR><BR>Strings, incidentally, are 20 bytes + two times their length. (Because strings are always stored as Unicode, 2 bytes per character.) Of course, that applies on machines where a "wide character" is 2 bytes (x86, for example). But beware of other architectures, now or in the future, where that might be 4 bytes per character.<BR><BR>Not to ask stupid questions, but...<BR><BR>What *possible* use can this information be to you???<BR><BR>VBScript wastes memory like a broken water valve. Every time you concatenate two strings, you are throwing away memory, for example. Every expression you use probably consumes a bit of memory. Oh, sure, it all gets reclaimed (there are very, very few "leaks" in ASP nowadays), but still... If all you measure is the usage of an array, you aren&#039t really counting all the stuff that hits your perfomance, for example.<BR><BR>

Posting Permissions

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