Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > Error 16: Expression too Complex - problem with Dynamic Array


Reply
 
Thread Tools Display Modes
  #1  
Old 10-01-2004, 02:29 AM
SteRobson's Avatar
SteRobson SteRobson is offline
Contributor
 
Join Date: Apr 2003
Location: York, England
Posts: 475
Default Error 16: Expression too Complex - problem with Dynamic Array


Hi,
I have a dynamic array which isn't necessarily 'Dimmed' to start with (so it's just empty) and when I come to assign a value to an element I test if it's Dimmed using the standard method (first shown by OnError on these forums I believe). The trouble is, if I check if the array is dimmed and then assign a value to it if it isn't empty I get Runtime Error 16: Expression too complex.

The code below demonstrates this pretty well - just paste it into a Form_Load event and run it:
Code:
'This snippet is written to illustrate a problem with 'testing if an array is dimensioned or not. 'On Windows XP Home SP2 with VB6 (SP6) this gives an '"Expression is too complex" error (Error 16) - not tested 'on any other systems. 'Create a couple of variables Dim Val1 As Single, Val2 As Single 'Create an array Dim MyArray() As Single 'Put an element in the array ReDim MyArray(0) 'The rest of this code could be in some other function 'somewhere, but it still throughs up the error anyway. 'Assign some values to the variables Val1 = 46: Val2 = 2 If (Not MyArray) = -1 Then 'check if the array has been dimmed 'The array is empty - do nothing Else 'Assign a value to the zero element of the array MyArray(0) = Val1 / Val2 End If

This problem has kind of been mentioned in other threads (such as this one) but never pinned down like this. Does anyone have any words of wisdom on what's causing this problem and how to solve it?
__________________
S t e

On Error Goto Blame_Someone_Else
Reply With Quote
  #2  
Old 10-01-2004, 03:24 AM
Flyguy's Avatar
Flyguy Flyguy is offline
Lost Soul

Super Moderator
* Guru *
 
Join Date: May 2001
Location: Vorlon
Posts: 19,039
Default

I never understood why people need this kind of functionallity.
I use dynamic arrays all the time, but always initialise them to have at least 1 element.
Reply With Quote
  #3  
Old 10-01-2004, 03:55 AM
robertdeniro robertdeniro is offline
Junior Contributor
 
Join Date: Feb 2003
Location: Durban, South Africa
Posts: 306
Default

Tried this out myself... it seems that the (Not Array) method does something that VB doesn't expect.
It looks like getting a pointer in this way modifies the pointer somewhat, and gets it pointing somewhere it shouldn't.
By adding another Not I got some odd results like the same runtime error BEFORE the array was Redimmed, or even used!

Unless you have access to the VB source code, you can only guess at why this happens. Just don't use this method if it affects you.
Rather use the standard LBound/UBound test with error handling.
Reply With Quote
  #4  
Old 10-01-2004, 04:19 AM
SteRobson's Avatar
SteRobson SteRobson is offline
Contributor
 
Join Date: Apr 2003
Location: York, England
Posts: 475
Default

Quote:
Originally Posted by Flyguy
I never understood why people need this kind of functionallity.
I use dynamic arrays all the time, but always initialise them to have at least 1 element.
Yes, there are plenty of other ways to get around the problem, but non seem quite so satisfying as the (Not MyArray) = -1 method. It just seems like a really odd problem for VB to have.
__________________
S t e

On Error Goto Blame_Someone_Else
Reply With Quote
  #5  
Old 10-01-2004, 04:35 AM
robertdeniro robertdeniro is offline
Junior Contributor
 
Join Date: Feb 2003
Location: Durban, South Africa
Posts: 306
Default

Not really.

VB is officially a closed development environment. VB does not officially support pointers. You can get them, but you're on your own once you do.

There's all kinds of stuff like subclassing, or COM, that VB just doesn't handle fluidly, because VB is getting up to all sorts of background shena****ns that you never see, or can hope to understand.

We often have to come up with workarounds without actually understanding why the workaround works.
The truth is hidden somewhere inside msvbvm60.dll.
Unlike C++, java, etc., you can't tell VB to "dumb down".

Like sands through the hourglass, so are the days of our lives..
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->