ASP Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreASP Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 9th, 2003, 10:46 PM
alfware alfware is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 4 alfware User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Angry Cannot redim a array inside a class

My Problem is I have a custom class that has an dynamic array inside of it. I also need to have an array of these classes with arrays in them (all dynamic). The problem is MS VBScript appears to not understand the object when using the DIM statement.

Example 1)

Code:
class clsMyTest
	dim strTitle
	dim arrClassTest()
end class

' M Y   C L A S S   I N   A N   A R R A Y
dim arrMyTest()

for i = 0 to 3
	redim preserve arrMyTest(i)
	set arrMyTest = new clsMyTest
	arrMyTest(i).strTitle = "Boo"
	for j = 0 to 1
		redim preserve arrMyTest(i).arrClassTest(j)
		mytest(i).arrClassTest(j) = "Hoo"
		response.write arrMyTest(i).arrClassTest(j)
	next
	response.write arrMyTest(i).strTitle
next


Results:

Code:
Microsoft VBScript compilation error '800a0401' 

Expected end of statement 

/untitled.asp, line 15 

redim preserve arrMyTest(i).arrClassTest(j)
---------------------------^




Example 2)

Code:
class clsMyTest
	dim strTitle
	dim arrClassTest()
end class

dim myTest

set myTest = new clsMyTest
myTest.strTitle = "Boo"
response.write myTest.strTitle
for j = 0 to 1
	redim preserve mytest.arrClassTest(j)
	myTest.arrClassTest(j) = "Hoo"
	response.write myTest.arrClassTest(j)
next


Results:

Code:
Microsoft VBScript compilation error '800a03ed' 

Expected '(' 

/untitled.asp, line 29 

redim preserve mytest.arrClassTest(j)
---------------------^



Any ideas on how to get VBScript to like this idea? I have tryed using the With Statement eg.

Code:
With myTest
	Redim Preserve .arrMyTest(j)
End With


but fails expecting an object! Grr....

Hope you can help me!

Regards,

Michael Proctor

Reply With Quote
  #2  
Old November 9th, 2003, 11:27 PM
alfware alfware is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 4 alfware User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Code:
class clsMyTest
	dim strTitle
	dim arrClassTest()
	Public Function RedimarrClassTest (NewSize)
		'Remember to make this function a public function
		'if not you cannot call it outside the class scope
		redim preservce arrClassTest(NewSize)
	End Function
end class

dim myTest

set myTest = new clsMyTest
myTest.strTitle = "Boo"
response.write myTest.strTitle
for j = 0 to 1

	call myTest.RedimarrClassTest(j)
	'or myTest.RedimarrClassTest j

	myTest.arrClassTest(j) = "Hoo"
	response.write myTest.arrClassTest(j)
next


This allows me to jump into the private scope of the class alter the dynamic array then keep going! I would like peoples comments on this fix. As I think that my problems are due to bad coding to start with.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreASP Programming > Cannot redim a array inside a class


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT