Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Reproducable Hard Crash in Excel 2003 (and earlier versions) with the following VBA code.

Hi,

I have a problem in some VBA code that causes a hard crash in Excel 2000 and
2003 (haven't tried Excel XP but I would assume the same result).
Fortunately I managed to reproduce the problem in a simple workbook, and the
code is that small that I can duplicate it here.

In a new workbook, add the following:


ThisWorkBook

Public Sub EntryPoint()

Dim data() As MY_DATA_TYPE

ReDim data(0)
data(0).val1 = "Test"
data(0).val2 = "Test 2"

MethodA data

End Sub

Private Sub MethodA(ByRef data() As MY_DATA_TYPE)

Dim form As UserForm1
Set form = New UserForm1
form.Test = data

End Sub


Module1

Public Type MY_DATA_TYPE
val1 As String
val2 As String
End Type


UserForm1

Private m_data() As MY_DATA_TYPE

Public Property Let Test(ByRef newValue() As MY_DATA_TYPE)
m_data = newValue
End Property

The code will crash when setting the Test property of UserForm1

This only seems to occur in this particular configuration of code. I can
pass the dyamic array through a number of methods without issue, but when I
assign the UserForm property is when it fails. It will also work fine if I
short circuit MethodB and set the UserForm property directly from the
EntryPoint method. Yet another way to get it to work is to make the dynamic
array a module level variable in ThisWorkBook and thus not have to pass it
between methods in ThisWorkbook.

I do have a work around so am not being held up by this, but I would be
appreciative if someone from Microsoft (or otherwise) could confirm this
behavior and advise whether it is a bug or known limitation. I couldn't find
anything in the KB about it.

Kind Regards,
Wayne.



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,253
Default Reproducable Hard Crash in Excel 2003 (and earlier versions) with the following VBA code.

ok i confirm it crashed in xlXP too :)

but what's the point?


the PROBLEM is that
you're treating a userform as a class module (first time i saw that :)




keepITcool

< email : keepitcool chello nl (with @ and .)
< homepage: http://members.chello.nl/keepitcool


"David Battams" wrote:

Hi,

I have a problem in some VBA code that causes a hard crash in Excel
2000 and 2003 (haven't tried Excel XP but I would assume the same
result). Fortunately I managed to reproduce the problem in a simple
workbook, and the code is that small that I can duplicate it here.

In a new workbook, add the following:


ThisWorkBook

Public Sub EntryPoint()

Dim data() As MY_DATA_TYPE

ReDim data(0)
data(0).val1 = "Test"
data(0).val2 = "Test 2"

MethodA data

End Sub

Private Sub MethodA(ByRef data() As MY_DATA_TYPE)

Dim form As UserForm1
Set form = New UserForm1
form.Test = data

End Sub


Module1

Public Type MY_DATA_TYPE
val1 As String
val2 As String
End Type


UserForm1

Private m_data() As MY_DATA_TYPE

Public Property Let Test(ByRef newValue() As MY_DATA_TYPE)
m_data = newValue
End Property

The code will crash when setting the Test property of UserForm1

This only seems to occur in this particular configuration of code. I
can pass the dyamic array through a number of methods without issue,
but when I assign the UserForm property is when it fails. It will also
work fine if I short circuit MethodB and set the UserForm property
directly from the EntryPoint method. Yet another way to get it to work
is to make the dynamic array a module level variable in ThisWorkBook
and thus not have to pass it between methods in ThisWorkbook.

I do have a work around so am not being held up by this, but I would
be appreciative if someone from Microsoft (or otherwise) could confirm
this behavior and advise whether it is a bug or known limitation. I
couldn't find anything in the KB about it.

Kind Regards,
Wayne.





  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,236
Default Reproducable Hard Crash in Excel 2003 (and earlier versions) with the following VBA code.

I treat Userforms as Class Modules without problems. It find it tider than
returning values via a Standard Module.


--
Rob van Gelder - http://www.vangelder.co.nz/excel


"keepITcool" wrote in message
...
ok i confirm it crashed in xlXP too :)

but what's the point?


the PROBLEM is that
you're treating a userform as a class module (first time i saw that :)




keepITcool

< email : keepitcool chello nl (with @ and .)
< homepage: http://members.chello.nl/keepitcool


"David Battams" wrote:

Hi,

I have a problem in some VBA code that causes a hard crash in Excel
2000 and 2003 (haven't tried Excel XP but I would assume the same
result). Fortunately I managed to reproduce the problem in a simple
workbook, and the code is that small that I can duplicate it here.

In a new workbook, add the following:


ThisWorkBook

Public Sub EntryPoint()

Dim data() As MY_DATA_TYPE

ReDim data(0)
data(0).val1 = "Test"
data(0).val2 = "Test 2"

MethodA data

End Sub

Private Sub MethodA(ByRef data() As MY_DATA_TYPE)

Dim form As UserForm1
Set form = New UserForm1
form.Test = data

End Sub


Module1

Public Type MY_DATA_TYPE
val1 As String
val2 As String
End Type


UserForm1

Private m_data() As MY_DATA_TYPE

Public Property Let Test(ByRef newValue() As MY_DATA_TYPE)
m_data = newValue
End Property

The code will crash when setting the Test property of UserForm1

This only seems to occur in this particular configuration of code. I
can pass the dyamic array through a number of methods without issue,
but when I assign the UserForm property is when it fails. It will also
work fine if I short circuit MethodB and set the UserForm property
directly from the EntryPoint method. Yet another way to get it to work
is to make the dynamic array a module level variable in ThisWorkBook
and thus not have to pass it between methods in ThisWorkbook.

I do have a work around so am not being held up by this, but I would
be appreciative if someone from Microsoft (or otherwise) could confirm
this behavior and advise whether it is a bug or known limitation. I
couldn't find anything in the KB about it.

Kind Regards,
Wayne.







  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,253
Default Reproducable Hard Crash in Excel 2003 (and earlier versions) with the following VBA code.

hmm..
might be a good idea :)

having looked at your site
speedtest is a nice eyeopener too :)

I'm learning!




keepITcool

< email : keepitcool chello nl (with @ and .)
< homepage: http://members.chello.nl/keepitcool


"Rob van Gelder" wrote:

I treat Userforms as Class Modules without problems. It find it tider
than returning values via a Standard Module.


"keepITcool" wrote in message
...
ok i confirm it crashed in xlXP too :)

but what's the point?


the PROBLEM is that
you're treating a userform as a class module (first time i saw that
:)



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Reproducable Hard Crash in Excel 2003 (and earlier versions) with the following VBA code.

There's no "treating" a UserForm class as an object module. It IS an object
module.

Try placing the public type declaration in UserForm1 and see what error
message you get....

KeepItCool - what do you mean what is the point? I presume hard crashes are
a feature in your code? :-)


"keepITcool" wrote in message
...
hmm..
might be a good idea :)

having looked at your site
speedtest is a nice eyeopener too :)

I'm learning!




keepITcool

< email : keepitcool chello nl (with @ and .)
< homepage: http://members.chello.nl/keepitcool


"Rob van Gelder" wrote:

I treat Userforms as Class Modules without problems. It find it tider
than returning values via a Standard Module.


"keepITcool" wrote in message
...
ok i confirm it crashed in xlXP too :)

but what's the point?


the PROBLEM is that
you're treating a userform as a class module (first time i saw that
:)







  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 593
Default Reproducable Hard Crash in Excel 2003 (and earlier versions) with the following VBA code.

"David Battams" wrote ...

There's no "treating" a UserForm class as an object module. It IS an object
module.


I think Rob meant he uses a userform as he would a class e.g. add
public members to the userform rather than use public variables in a
standard module etc.

KeepItCool - what do you mean what is the point? I presume hard crashes are
a feature in your code? :-)


I think KeepItCool meant he usually instantiates a userform with

Load UserForm1

(which is reasonable if you only need one instance) and wasn't waare
he could you could do the same with

Dim frm1 As UserForm1
Set frm1 = New UserForm1

David, untested but if you replace the struct (MY_DATA_TYPE) with a
complex object (a VB class) I think the problem would go away. That's
what I mean by the struct being the problem. But something tells me
you need the struct for an external app...?

Jamie.

--
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 593
Default Reproducable Hard Crash in Excel 2003 (and earlier versions) with the following VBA code.

keepITcool wrote ...

ok i confirm it crashed in xlXP too :)

but what's the point?

the PROBLEM is that
you're treating a userform as a class module (first time i saw that :)


That isn't the problem! Userforms *should* be treated as classes. You
should read my posts more often ;-)

http://groups.google.com/groups?selm...g .google.com

AFAIK it's the user defined type that is the problem. I've seen it
before in this ng but don't have any answers other than workarounds
(which the OP already has).

Jamie.

--
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Reproducable Hard Crash in Excel 2003 (and earlier versions) with the following VBA code.

Hi Jamie,

I figured the user defined type is what set the cat amongst the pigeons, and
for some reason only the specific combination of passing by reference to a
local method, then to a UserForm class property setter (or in VB do you guys
call value type setters, letters? ;-)

When running my full application as an Excel Add-In I was getting the
following automation error:
Automation Error: The Object Invoked Has Disconnected from Its Clients

That makes me think there is something sinister going on in the background
somewhere, since the code itself should be pretty harmless.

Anyway, I've taken the route of a module level variable of the user defined
type, then passing that once only to the form class via its associated
property. Seems to work fine.

Cheers,
Wayne.



"Jamie Collins" wrote in message
om...
keepITcool wrote ...

ok i confirm it crashed in xlXP too :)

but what's the point?

the PROBLEM is that
you're treating a userform as a class module (first time i saw that :)


That isn't the problem! Userforms *should* be treated as classes. You
should read my posts more often ;-)


http://groups.google.com/groups?selm...g .google.com

AFAIK it's the user defined type that is the problem. I've seen it
before in this ng but don't have any answers other than workarounds
(which the OP already has).

Jamie.

--



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
List function in earlier Excel versions John_Carty Excel Discussion (Misc queries) 4 November 4th 05 08:48 AM
2003 compatibility with earlier versions George Applegate Setting up and Configuration of Excel 0 November 2nd 05 12:31 PM
2003 compatibility with earlier versions George Applegate Excel Worksheet Functions 0 November 2nd 05 12:29 PM
2003 compatibility with earlier versions George Applegate Setting up and Configuration of Excel 0 November 2nd 05 12:29 PM
2003 compatibility with earlier versions George Applegate Excel Discussion (Misc queries) 0 November 2nd 05 12:27 PM


All times are GMT +1. The time now is 09:34 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"