Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.basic.visual.misc > #2168 > unrolled thread

StrConv(ByteArray, vbUnicode) raising an "Out of memory" error

Started byDeanna Earley <dee.earley@icode.co.uk>
First post2014-10-23 09:35 +0100
Last post2014-10-27 16:26 +0000
Articles 15 — 5 participants

Back to article view | Back to comp.lang.basic.visual.misc


Contents

  StrConv(ByteArray, vbUnicode) raising an "Out of memory" error Deanna Earley <dee.earley@icode.co.uk> - 2014-10-23 09:35 +0100
    Re: StrConv(ByteArray, vbUnicode) raising an "Out of memory" error Arne Saknussemm <motz001.20.wannabet@spamgourmet.com> - 2014-10-23 10:39 +0200
      Re: StrConv(ByteArray, vbUnicode) raising an "Out of memory" error Deanna Earley <dee.earley@icode.co.uk> - 2014-10-23 11:46 +0100
        Re: StrConv(ByteArray, vbUnicode) raising an "Out of memory" error Arne Saknussemm <es215.10.wannabet@spamgourmet.com> - 2014-10-23 15:09 +0200
          Re: StrConv(ByteArray, vbUnicode) raising an "Out of memory" error Deanna Earley <dee.earley@icode.co.uk> - 2014-10-23 14:28 +0100
    Re: StrConv(ByteArray, vbUnicode) raising an "Out of memory" error "Farnsworth" <nospam@nospam.com> - 2014-10-23 08:04 -0400
      Re: StrConv(ByteArray, vbUnicode) raising an "Out of memory" error "Farnsworth" <nospam@nospam.com> - 2014-10-23 08:35 -0400
    Re: StrConv(ByteArray, vbUnicode) raising an "Out of memory" error "Farnsworth" <nospam@nospam.com> - 2014-10-23 11:48 -0400
      Re: StrConv(ByteArray, vbUnicode) raising an "Out of memory" error Deanna Earley <dee.earley@icode.co.uk> - 2014-10-24 09:47 +0100
    Re: StrConv(ByteArray, vbUnicode) raising an "Out of memory" error Deanna Earley <dee.earley@icode.co.uk> - 2014-10-24 14:47 +0100
      Re: StrConv(ByteArray, vbUnicode) raising an "Out of memory" error Arne Saknussemm <es215.10.wannabet@spamgourmet.com> - 2014-10-27 12:32 +0100
        Re: StrConv(ByteArray, vbUnicode) raising an "Out of memory" error Deanna Earley <dee.earley@icode.co.uk> - 2014-10-27 12:14 +0000
          Re: StrConv(ByteArray, vbUnicode) raising an "Out of memory" error Arne Saknussemm <motz001.20.wannabet@spamgourmet.com> - 2014-10-28 11:22 +0100
      Re: StrConv(ByteArray, vbUnicode) raising an "Out of memory" error "Blue Planet" <sorry@nospamme.org> - 2014-10-27 12:11 -0400
        Re: StrConv(ByteArray, vbUnicode) raising an "Out of memory" error Deanna Earley <dee.earley@icode.co.uk> - 2014-10-27 16:26 +0000

#2168 — StrConv(ByteArray, vbUnicode) raising an "Out of memory" error

FromDeanna Earley <dee.earley@icode.co.uk>
Date2014-10-23 09:35 +0100
SubjectStrConv(ByteArray, vbUnicode) raising an "Out of memory" error
Message-ID<m2aelp$t5s$1@speranza.aioe.org>
I really hope that something has changed recently and that I'm not going 
crazy but...

Does anyone know if the handling of StrConv() to convert an ANSI/local 
code page byte array to a string has changed recently?

I have used it for years as a simple conversion:

Data = GetData()
Result = StrConv(Data, vbUnicode)

This works most of the time, but in the last month, I've now seen it 
raising error 7, Out of memory when the input byte array is empty (0 
length, 0 to -1)
I'd swear on my life this has worked for the last I don't know how many 
years...

I've recently had to rebuild my dev machine and is now 64-bit Windows 7 
(with VB6 SP6 of course) which could be the cause but another 32-bit 
machine does the same thing. Maybe a Windows Update?

Thanks

-- 
Deanna Earley (dee.earley@icode.co.uk)
iCatcher Development Team
http://www.icode.co.uk/icatcher/

iCode Systems

(Replies direct to my email address will be printed, shredded then fed 
to the rats. Please reply to the group.)

[toc] | [next] | [standalone]


#2169

FromArne Saknussemm <motz001.20.wannabet@spamgourmet.com>
Date2014-10-23 10:39 +0200
Message-ID<20141023103947.00003561@eternal-september.org>
In reply to#2168
On Thu, 23 Oct 2014 09:35:40 +0100
"Deanna Earley" wrote in
microsoft.public.vb.general.discussion,comp.lang.basic.visual.misc
<m2aelp$t5s$1@speranza.aioe.org>:

> Data = GetData()
> Result = StrConv(Data, vbUnicode)
> 
> This works most of the time, but in the last month, I've now seen it 
> raising error 7, Out of memory when the input byte array is empty (0 
> length, 0 to -1)

What do you mean with that "0 to -1" ? If that's the upper bound of the
array, I wonder if the strconv considers it "unsigned" so trying to
deal with an array whose upper bound is "ffff" (or something like that)

[toc] | [prev] | [next] | [standalone]


#2170

FromDeanna Earley <dee.earley@icode.co.uk>
Date2014-10-23 11:46 +0100
Message-ID<m2amal$ij4$1@speranza.aioe.org>
In reply to#2169
On 23/10/2014 09:39, Arne Saknussemm wrote:
> On Thu, 23 Oct 2014 09:35:40 +0100
> "Deanna Earley" wrote in
> microsoft.public.vb.general.discussion,comp.lang.basic.visual.misc
> <m2aelp$t5s$1@speranza.aioe.org>:
>
>> Data = GetData()
>> Result = StrConv(Data, vbUnicode)
>>
>> This works most of the time, but in the last month, I've now seen it
>> raising error 7, Out of memory when the input byte array is empty (0
>> length, 0 to -1)
>
> What do you mean with that "0 to -1" ? If that's the upper bound of the
> array, I wonder if the strconv considers it "unsigned" so trying to
> deal with an array whose upper bound is "ffff" (or something like that)

A 0 length array has bounds of 0 to -1 (as 0 to 0 is 1 item).
You can easily create a 0 length byte array by assigning an empty string 
to it.
That is a possibility though, but begs the question of has this changed?
I still swear this used to work...

-- 
Deanna Earley (dee.earley@icode.co.uk)
iCatcher Development Team
http://www.icode.co.uk/icatcher/

iCode Systems

(Replies direct to my email address will be printed, shredded then fed 
to the rats. Please reply to the group.)

[toc] | [prev] | [next] | [standalone]


#2173

FromArne Saknussemm <es215.10.wannabet@spamgourmet.com>
Date2014-10-23 15:09 +0200
Message-ID<20141023150941.00007a5e@eternal-september.org>
In reply to#2170
:: On Thu, 23 Oct 2014 11:46:16 +0100
:: (microsoft.public.vb.general.discussion,comp.lang.basic.visual.misc)
:: <m2amal$ij4$1@speranza.aioe.org>
:: Deanna Earley <dee.earley@icode.co.uk> wrote:

> A 0 length array has bounds of 0 to -1 (as 0 to 0 is 1 item).
> You can easily create a 0 length byte array by assigning an empty
> string to it.

Hey !! Stop biting, I was just trying to make a guess :) !

> That is a possibility though, but begs the question of has this
> changed? I still swear this used to work...

I don't know; but then, why don't you write your own "ConvStr" function
with error trapping and all that and use find/replace to use it in
place of the vanilla one :) ?

-- 
WARNING: The Law of Large Numbers also applies to assholes. The number
of assholes of any given form is never zero, nor can you make it so.

[toc] | [prev] | [next] | [standalone]


#2174

FromDeanna Earley <dee.earley@icode.co.uk>
Date2014-10-23 14:28 +0100
Message-ID<m2avr2$bhv$1@speranza.aioe.org>
In reply to#2173
On 23/10/2014 14:09, Arne Saknussemm wrote:
> :: On Thu, 23 Oct 2014 11:46:16 +0100
> :: (microsoft.public.vb.general.discussion,comp.lang.basic.visual.misc)
> :: <m2amal$ij4$1@speranza.aioe.org>
> :: Deanna Earley <dee.earley@icode.co.uk> wrote:
>
>> A 0 length array has bounds of 0 to -1 (as 0 to 0 is 1 item).
>> You can easily create a 0 length byte array by assigning an empty
>> string to it.
>
> Hey !! Stop biting, I was just trying to make a guess :) !
>
>> That is a possibility though, but begs the question of has this
>> changed? I still swear this used to work...
>
> I don't know; but then, why don't you write your own "ConvStr" function
> with error trapping and all that and use find/replace to use it in
> place of the vanilla one :) ?

I can do, it was more annoyance that it's only recently started 
happening, and the same code has been in use for years, and now, 
suddenly, I'm getting tens of errors a day.
As far as I can tell, the source data is the same as it's always been...

Oh well :)

-- 
Deanna Earley (dee.earley@icode.co.uk)
iCatcher Development Team
http://www.icode.co.uk/icatcher/

iCode Systems

(Replies direct to my email address will be printed, shredded then fed 
to the rats. Please reply to the group.)

[toc] | [prev] | [next] | [standalone]


#2171

From"Farnsworth" <nospam@nospam.com>
Date2014-10-23 08:04 -0400
Message-ID<m2aqsc$u84$1@speranza.aioe.org>
In reply to#2168
I was able to duplicate the error with VB6 with SP5 applied, but with SP6 
runtime files on Windows XP+SP2. I haven't applied any OS updates for a long 
time. Here is the code I used:

Option Explicit

Private Sub Form_Load()
    Dim Data() As Byte
    Dim Result As String

    Data = ""
    Debug.Print LBound(Data), UBound(Data)
    Result = StrConv(Data, vbUnicode)

End Sub

Output:

 0            -1

If you use it in many places, you can write your own DoStrConv() function 
that takes care of that special case. 

[toc] | [prev] | [next] | [standalone]


#2172

From"Farnsworth" <nospam@nospam.com>
Date2014-10-23 08:35 -0400
Message-ID<m2asm4$3bn$1@speranza.aioe.org>
In reply to#2171
"Farnsworth" <nospam@nospam.com> wrote in message 
news:m2aqsc$u84$1@speranza.aioe.org...
>I was able to duplicate the error with VB6 with SP5 applied, but with SP6 
>runtime files on Windows XP+SP2. I haven't applied any OS updates for a 
>long time. Here is the code I used:
>
> Option Explicit
>
> Private Sub Form_Load()
>    Dim Data() As Byte
>    Dim Result As String
>
>    Data = ""
>    Debug.Print LBound(Data), UBound(Data)
>    Result = StrConv(Data, vbUnicode)
>
> End Sub
>
> Output:
>
> 0            -1
>
> If you use it in many places, you can write your own DoStrConv() function 
> that takes care of that special case.

If I use "Dim Data As Variant", the error goes away.

[toc] | [prev] | [next] | [standalone]


#2175

From"Farnsworth" <nospam@nospam.com>
Date2014-10-23 11:48 -0400
Message-ID<m2b801$1jc$1@speranza.aioe.org>
In reply to#2168
"Deanna Earley" <dee.earley@icode.co.uk> wrote in message 
news:m2aelp$t5s$1@speranza.aioe.org...
> I have used it for years as a simple conversion:
>
> Data = GetData()
> Result = StrConv(Data, vbUnicode)
>

What's the declaration for Data and GetData?

[toc] | [prev] | [next] | [standalone]


#2176

FromDeanna Earley <dee.earley@icode.co.uk>
Date2014-10-24 09:47 +0100
Message-ID<m2d3oa$tot$1@speranza.aioe.org>
In reply to#2175
On 23/10/2014 16:48, Farnsworth wrote:
> "Deanna Earley" <dee.earley@icode.co.uk> wrote in message
> news:m2aelp$t5s$1@speranza.aioe.org...
>> I have used it for years as a simple conversion:
>>
>> Data = GetData()
>> Result = StrConv(Data, vbUnicode)
>>
>
> What's the declaration for Data and GetData?

Sorry, a byte array:
Dim Data() As Byte
Function GetData() As Byte()
(The later isn't what's actually in use but the type matches)

-- 
Deanna Earley (dee.earley@icode.co.uk)
iCatcher Development Team
http://www.icode.co.uk/icatcher/

iCode Systems

(Replies direct to my email address will be printed, shredded then fed 
to the rats. Please reply to the group.)

[toc] | [prev] | [next] | [standalone]


#2177

FromDeanna Earley <dee.earley@icode.co.uk>
Date2014-10-24 14:47 +0100
Message-ID<m2dlas$a3h$1@speranza.aioe.org>
In reply to#2168
On 23/10/2014 09:35, Deanna Earley wrote:
> I really hope that something has changed recently and that I'm not going
> crazy but...
>
> Does anyone know if the handling of StrConv() to convert an ANSI/local
> code page byte array to a string has changed recently?
>
> I have used it for years as a simple conversion:
>
> Data = GetData()
> Result = StrConv(Data, vbUnicode)
>
> This works most of the time, but in the last month, I've now seen it
> raising error 7, Out of memory when the input byte array is empty (0
> length, 0 to -1)
> I'd swear on my life this has worked for the last I don't know how many
> years...
>
> I've recently had to rebuild my dev machine and is now 64-bit Windows 7
> (with VB6 SP6 of course) which could be the cause but another 32-bit
> machine does the same thing. Maybe a Windows Update?

It turns out I'd accidentally introduced a Data = "" in the source 
function that triggered the error as opposed to the original 
undimensioned array which correctly returns an empty string.
It must have been pure luck that I've not noticed it breaks with an 
explicitly empty array until now...
Thanks for everyone's comments.

-- 
Deanna Earley (dee.earley@icode.co.uk)
iCatcher Development Team
http://www.icode.co.uk/icatcher/

iCode Systems

(Replies direct to my email address will be printed, shredded then fed 
to the rats. Please reply to the group.)

[toc] | [prev] | [next] | [standalone]


#2178

FromArne Saknussemm <es215.10.wannabet@spamgourmet.com>
Date2014-10-27 12:32 +0100
Message-ID<20141027123252.000033ae@eternal-september.org>
In reply to#2177
:: On Fri, 24 Oct 2014 14:47:44 +0100
:: (microsoft.public.vb.general.discussion,comp.lang.basic.visual.misc)
:: <m2dlas$a3h$1@speranza.aioe.org>
:: Deanna Earley <dee.earley@icode.co.uk> wrote:


> It turns out I'd accidentally introduced a Data = "" in the source 
> function that triggered the error as opposed to the original 
> undimensioned array which correctly returns an empty string.

Oh well, the Earley bird catches the bug :) !

-- 
WARNING: The Law of Large Numbers also applies to assholes. The number
of assholes of any given form is never zero, nor can you make it so.

[toc] | [prev] | [next] | [standalone]


#2179

FromDeanna Earley <dee.earley@icode.co.uk>
Date2014-10-27 12:14 +0000
Message-ID<m2lcvo$7to$1@speranza.aioe.org>
In reply to#2178
On 27/10/2014 11:32, Arne Saknussemm wrote:
> :: On Fri, 24 Oct 2014 14:47:44 +0100
> :: (microsoft.public.vb.general.discussion,comp.lang.basic.visual.misc)
> :: <m2dlas$a3h$1@speranza.aioe.org>
> :: Deanna Earley <dee.earley@icode.co.uk> wrote:
>> It turns out I'd accidentally introduced a Data = "" in the source
>> function that triggered the error as opposed to the original
>> undimensioned array which correctly returns an empty string.
>
> Oh well, the Earley bird catches the bug :) !

*groan* :p

-- 
Deanna Earley (dee.earley@icode.co.uk)
iCatcher Development Team
http://www.icode.co.uk/icatcher/

iCode Systems

(Replies direct to my email address will be printed, shredded then fed 
to the rats. Please reply to the group.)

[toc] | [prev] | [next] | [standalone]


#2182

FromArne Saknussemm <motz001.20.wannabet@spamgourmet.com>
Date2014-10-28 11:22 +0100
Message-ID<20141028112218.000017e0@eternal-september.org>
In reply to#2179
On Mon, 27 Oct 2014 12:14:17 +0000
"Deanna Earley" wrote in
microsoft.public.vb.general.discussion,comp.lang.basic.visual.misc
<m2lcvo$7to$1@speranza.aioe.org>:

> > Oh well, the Earley bird catches the bug :) !
 
> *groan* :p

forgive me, it was a bad day :)

[toc] | [prev] | [next] | [standalone]


#2180

From"Blue Planet" <sorry@nospamme.org>
Date2014-10-27 12:11 -0400
Message-ID<m2lqr8$dcb$1@speranza.aioe.org>
In reply to#2177
"Deanna Earley" <dee.earley@icode.co.uk> wrote in message 
news:m2dlas$a3h$1@speranza.aioe.org...
> On 23/10/2014 09:35, Deanna Earley wrote:
>
> It turns out I'd accidentally introduced a Data = "" in the source 
> function that triggered the error as opposed to the original undimensioned 
> array which correctly returns an empty string.
> It must have been pure luck that I've not noticed it breaks with an 
> explicitly empty array until now...
> Thanks for everyone's comments.

Glad you found it.

This is one of the downsides of the "empty" vs. "unallocated" dynamic Byte 
array.  It would be nice if this didn't occur, however the "assignment of an 
empty String" trick itself was probably an unintended (those otherwise quite 
handy) side-effect.

If we ever got a VB 7.0 we'd be at risk of the trick being broken.  But then 
again a new VB might have addressed all of these issues through broader 
support for arrays, Strings, character encodings, etc.

Just one more thing the stubborn VB6 programmer needs to be aware of! ;) 

[toc] | [prev] | [next] | [standalone]


#2181

FromDeanna Earley <dee.earley@icode.co.uk>
Date2014-10-27 16:26 +0000
Message-ID<m2lrnn$f8p$1@speranza.aioe.org>
In reply to#2180
On 27/10/2014 16:11, Blue Planet wrote:
> "Deanna Earley" <dee.earley@icode.co.uk> wrote in message
> news:m2dlas$a3h$1@speranza.aioe.org...
>> On 23/10/2014 09:35, Deanna Earley wrote:
>>
>> It turns out I'd accidentally introduced a Data = "" in the source
>> function that triggered the error as opposed to the original
>> undimensioned array which correctly returns an empty string.
>> It must have been pure luck that I've not noticed it breaks with an
>> explicitly empty array until now...
>> Thanks for everyone's comments.
>
> Glad you found it.
>
> This is one of the downsides of the "empty" vs. "unallocated" dynamic
> Byte array.  It would be nice if this didn't occur, however the
> "assignment of an empty String" trick itself was probably an unintended
> (those otherwise quite handy) side-effect.

True.
I settled for replacing all StrConv(..., vb(From)Unicode) with two 
custom functions that range check the input(both for undimensioned and 
zero length) that call MultiByteToWidechar() and WideCharToMultiByte().
This also allows me to force them to latin1, UTF-8, etc where required.

-- 
Deanna Earley (dee.earley@icode.co.uk)
iCatcher Development Team
http://www.icode.co.uk/icatcher/

iCode Systems

(Replies direct to my email address will be printed, shredded then fed 
to the rats. Please reply to the group.)

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.basic.visual.misc


csiph-web