Post

 Resources 

Console

Home | Profile | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 VBGamer
 VBGamer
 Redimming a nested User Defined Type

Note: You must be registered in order to post a reply.

Screensize:
UserName:
Password:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkInsert EmailInsert Image Insert CodeInsert QuoteInsert List Spell Checker
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

   Insert an File
Check here to include your profile signature.
Check here to subscribe to this topic.
    

T O P I C    R E V I E W
Hoss Posted - Jul 30 2004 : 06:54:26 AM
I just blew the heck out of this problem I've been having for quite some time in my code. I couldn't quite ReDim a nested User Defined Type without getting a 'subscript out of range' error!

For those of you that don't know; A User Defined Type (UDT) is a data type that you create yourself, hence User Defined. Here's an example of a UDT:

  
Public Type Chumps  
    GirlChumps() as String
    BoyChumps() as String
End Type
  


That is our first data type that we'll be using. Notice that the GirlChumps() and BoyChumps() arrays have no ranges! The purpose of this post is to show you how to redim those arrays, so just wait a moment and I'll get to it.

We need another UDT:
  
Public Type Classrooms  
    Subject as String
    Classmates as Chumps  
End Type
  


Notice I defined the variable Classmates as Chumps, our previously defined UDT.

And finally:
  
Dim Schedule() as Classrooms  
  


Okay, now that we've got our variables dimmed, let's look into how we ReDim (Resize) our arrays with no ranges!

"How can we do this?" You might be asking. With! That's how!

  
ReDim Schedule(1) 'This is our school schedule. Unfortunately this  
                          'school is under-budgeted, so we can only attend  
                          'two classes a day.  
  
With Schedule(0) 'Our first class  
    ReDim .Classmates.GirlChumps(1) 'Only two girls in this class  
    ReDim .Classmates.BoyChumps(1) 'Only two boys in this class  
End With
  
With Schedule(1) 'Our second class  
    ReDim .Classmates.GirlChumps(1)  
    ReDim .Classmates.BoyChumps(1)  
End With
  


As you can see, using WITH we can RedDim our undefined arrays without messing with the original Schedule() range. Alternatively, you can use a loop to iterate through the Schedule and Chumps arrays to more effectively set the ranges. I didn't do that... I typed it all out, for simplicity.

Now that we have it all ReDimmed, we can now define the arrays!

  
Schedule(0).Classmates.GirlChumps(0) = "Lacy"  
Schedule(0).Classmates.GirlChumps(1) = "Melissa"  
Schedule(0).Classmates.BoyChumps(0) = "Todd"  
Schedule(0).Classmates.BoyChumps(1) = "Alex"  
Schedule(0).Subject = "Math"  
  
Schedule(1).Classmates.GirlChumps(0) = "Clarise"  
Schedule(1).Classmates.GirlChumps(1) = "Jenna"  
Schedule(1).Classmates.BoyChumps(0) = "Chris"  
Schedule(1).Classmates.BoyChumps(1) = "Matt"  
Schedule(1).Subject = "Science"  
  


Again, a loop could have been used to define the arrays, but for simplicity I typed it out manually.

--------------------------

I hope this post provided more help than hinder! Sorry if it's a bit confusing!
2   L A T E S T    R E P L I E S    (Newest First)
Hoss Posted - Jul 30 2004 : 12:12:54 PM
Heh... There's no problem. It's a tutorial, not a request for help.
Eric Coleman Posted - Jul 30 2004 : 11:25:19 AM
Where does your problem occur?

VBGamer © Go To Top Of Page
This page was generated in 0.08 seconds. Snitz Forums 2000

Copyright © 2002 - 2004 Eric Coleman, Peter Kuchnio , et. al.