Link to home
Start Free TrialLog in
Avatar of isnoend2001
isnoend2001Flag for United States of America

asked on

How to clear the values in udt's

I udts that i need to use over with new data
how do i clear the data in the udt's ?


Private Type Info_UDT
  CompanyName  As Byte
  Address      As Byte
  sDate        As Byte
  City         As Byte
  State        As Byte
  Zip          As Byte
  Estimator    As Byte
  BidAmount    As Byte
  sqs          As Byte
  BidMaterial  As Byte
  Email        As Byte
  Bid2Material As Byte
  Bid2Amount   As Byte
  BusYrs       As Byte
  TempNotUsed   As Byte ' for future use if needed
End Type

Private Type Recap_UDT
  CompanyName  As Byte
  Estimator    As Byte
  sDate        As Byte
  BidAmount    As Byte
  BidMaterial  As Byte
  Bid2Amount   As Byte
  Bid2Material As Byte
  sqs          As Byte
  BusYrs       As Byte
   TempNotUsed   As Byte ' for future use if needed
End Type

Private Type Phone_UDT
  Cell      As String
  Office    As String
  Emergency As String
  Fax       As String
  Owner     As String
  LasrRow   As String
  TempNotUsed   As String ' for future use if needed
End Type

Private Type Task_UDT
  DaysComplete         As String
  ReceivedWork         As String
  ReceivedPLPD         As String
  CompanySubContractor As String
  ReceivedSubWork      As String
  ReceivedSubPLPD      As String
  FutureUse            As String 'not used
   TempNotUsed        As String ' for future use if needed
End Type

Private Type RoofCompany_UDT
  CompanyName  As String
  Address      As String
  City         As String
  State        As String
  Zip          As String
  sqs          As String
  BidAmount    As String
  BidMaterial  As String
  Bid2Amount   As String
  Bid2Material As String
  sDate        As String
  BusYrs       As String
  Estimator    As String
  Email        As String
  Notes        As String
  TempNotUsed  As String ' for future use if needed
  Phones       As Phone_UDT
  Tasks        As Task_UDT
End Type

Private RoofCompany() As RoofCompany_UDT

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Martin Liss
Martin Liss
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of isnoend2001

ASKER

Thanks good to know
You're welcome and I'm glad I was able to help.

In my profile you'll find links to some articles I've written that may interest you.
Marty - MVP 2009 to 2014
i think this may not work What if:
The first time the udt is used 10 of the fields are used
The 2nd time only 5 field are overwritten
would this not leave the old data ? in some of the fields
only the first field is required to save(CompanyName)
Again it's just like the situation with a String. If the string is locally defined as in a Sub or Function, that string is automatically initialized each time the Sub or Function is run. So if you do this you don't have to worry about it

Private Type Info_UDT
  CompanyName  As Byte
  Address      As Byte
  sDate        As Byte
  City         As Byte
  State        As Byte
  Zip          As Byte
  Estimator    As Byte
  BidAmount    As Byte
  sqs          As Byte
  BidMaterial  As Byte
  Email        As Byte
  Bid2Material As Byte
  Bid2Amount   As Byte
  BusYrs       As Byte
  TempNotUsed   As Byte ' for future use if needed
End Type

Private Sub Test
Dim IU As Info_UDT

Msgbox IU.CompanyName '<---- will always display a blank
IU.CompanyName = "Apple"
End Sub

Open in new window


However here you would have to manually initialize the unchanged portions of the UDT

Private Type Info_UDT
  CompanyName  As Byte
  Address      As Byte
  sDate        As Byte
  City         As Byte
  State        As Byte
  Zip          As Byte
  Estimator    As Byte
  BidAmount    As Byte
  sqs          As Byte
  BidMaterial  As Byte
  Email        As Byte
  Bid2Material As Byte
  Bid2Amount   As Byte
  BusYrs       As Byte
  TempNotUsed   As Byte ' for future use if needed
End Type
Private IU As Info_UDT

Private Sub Test

Msgbox IU.CompanyName '<---- will display a blank the first time but "Apple" after that unless changed
IU.CompanyName = "Apple"
End Sub

Open in new window

In the second situation you could create a Sub like this one and call it when you need to. (BTW why do you use Byte?)

Private Sub Init()
 IU.CompanyName = ""
  IU.Address  = ""
  IU.sDate  = ""
  IU.City  = ""
  IU.State  = ""
  IU.Zip  = ""
  IU.Estimator = ""
  IU.BidAmount  = ""
  IU.sqs  = ""
  IU.BidMaterial  = ""
  IU.Email  = ""
  IU.Bid2Material = ""
  IU.Bid2Amount  = ""
  IU.BusYrs  = ""
  IU.TempNotUsed  = ""
End Sub

Open in new window

Thanks,
Don't know about byte, somebody else wrote the udts