Re: VBScript OCX receive and supply a safeArray of type VT_UI1- problem

Newyana2 <[email protected]>
Newsgroups alt.comp.os.windows-xp,alt.windows7.general,comp.os.ms-windows.programmer.win32
Organization A noiseless patient Spider
Message-ID <[email protected]>
On 5/22/2024 11:52 AM, R.Wieser wrote:

>> If you declare Dim A2()
> 
> Which I have not done and, in the current case, have no intention to.

   You have no choice in VBScript. I wasn't suggesting sample code.
I was pointing out that if you're not specifying a datatype then it's
variant.  A1() as byte is a byte array, but that's only possible
in VB. In VBS you can only declare A1(). Or you declare A1 and
use that to receive an array variable.

   It's true that you can do some funky things around the edges.
Maybe you're managing to read a byte array as string. Whatever.
That's not valid code in VBS.

>> I assumed you were working in VB6, using VB6 strings.
> 
> Whut ?  I specifically mentioned VBScript in the subjectline and the first
> post, as well as thruout my replies ...
> 
     I meant the language you're writing the OCX in. You're
not writing the OCX is VBS, right? (Please tell me that you
didn't take that on as an interesting challenge. :)

   If you write the OCX in VB then the VB function can return
a string:

Function GetBlah() as Variant
   s = "blahblahblah"
   GetBlah = "CVar(s)
End Function

VBS will have no problem with that. So you can send a
cahracter-delimited string and let VBS turn that into an
array. Otherwise you'll ned to explicitly convert each array
member to variant:

Function GetBytes() As Variant
   Dim A1(2) as variant
   A1(0) = cvar(120)
   A1(1) = CVar(12)
   A1(2) = cvar(33)
   GetBytes = A1
End Function

>> A safearray is a variant. The data may be other datatypes.
> 
> No, it isn't.  What you are referring to is a Variant which contains (a
> pointer to) a SafeArray.
> 
   An array is a variant. Yes, it's a pointer-type variable. The
variable itself, though, is a variant.

>> I can then reference each character as an integer in the array, without
>> any string handling. It's just memory addresses, after all.
>>
>>   For i = 0 to UBound(ArrayThatsAString)
>>    Select Case i
> 
> Are you trying to pull my leg ?   The only thing there you are using
> "ArrayThatsAString" for is to get its length.
> 
     Sorry. Maybe this went over your head. My example
was showing how data in an array is structured. It was
a sample of VB code, not VBS.

> In VBS you cannot access memory directly, ever.
> 

Yes. As I said in the line you snipped but addressed:

"You can't do anything like that in VBS because each array member is
always a variant and there's no direct access to memory addresses"

   I'm going to give you the benefit of the doubt and assume that you
read my post hastily and didn't follow the logic, but it sounds like you're
just looking to argue again.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.