p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

pro_vb thread: Using ReDim


Message #1 by jimsk@s... on Wed, 18 Apr 2001 03:23:22
	There's a catch to using UDTs in VB.  You cannot ReDim them and expect it
to work, especially if you have arrays in them.  You either must manually
nullify and redim every part of the UDT, or (preferred) create an empty
instance of your UDT and assign the old UDT to it:

udtYourGood = udtBlank

	If that fails, I would create a seperate TestResult with the correct size
and assign a DeviceID.DeviceResult to it:

Dim trEmpty As TestResult(0 To 15)
Dim didBlah As DeviceID
' ... code to do stuff
' time for the redim
didBlah.DeviceResult = trEmpty

? Chuck

> -----Original Message-----
> From: jimsk@s... [mailto:jimsk@s...]
> Sent: Wednesday, April 18, 2001 3:23 AM
> To: professional vb
> Subject: [pro_vb] Using ReDim
>
>
>
>   How do you initalize the following user Type using ReDim?
>
> Type TestResult    'Test result information
>     TestNum As Byte             ' Test number
>     Flag As Byte                ' Result of test
>                                 ' Bit 7 Pass(1)/Fail(0)
>                                 ' Bit 6 Zero Data(1)
>                                 ' Bit 5 Data OverRange(1)
>                                 ' Bit 4 NoData(1)
>                                 ' Bit 3 Oscillation(1)
>                                 ' Bit 2 Contact Data(1)
>     Result As Single            ' Test data result
> End Type
>
> Type DeviceID       'Device ID information
>     Device As String * 1        ' Header always a "D"
>     Device1 As Byte             ' Header always 00
>     SerialNum As Integer        ' Serial number of device 1 to 32767 max
>     BinNum As Integer           ' Bin number device sorted to 1 to 250 max
>     DeviceResult() As TestResult ' Data results from device
> End Type
>
>    The problem I am running into is the ReDim does not seen to initialize
> the DeviceResult() array properly.
>
>   Example:
>
>   Dim MyDevice() as DeviceID
>
>   Redim Mydevice(3)
>   ReDim MyDevice(0).DeviceResult(15) ' Does this make sense????
>
>   Code will not work.
>
>   If I force the array size the at the Dim Statement ie
>   Dim MyDevice(3) as DeviceID and with the Type (DeviceResult(15))
>   initialize as well, the code works.
>
>   I am wide open to suggestions....
>
>   Thank you


  Return to Index