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

asked on

Trouble clearing the data in a UDT

form level for 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
Private Info As Info_UDT

I copied and pasted the udt's and am trying to clear the udt's
The Info and Recap clear ok, but when i try to clear the Phone_UDT i get errors no matter what i try
How to clear the data in the Phone_UDT ?

Sub ClearUdts()
With Info
  .CompanyName = 0
  .Address = 0
  .sDate = 0
  .City = 0
  .State = 0
  .Zip = 0
  .Estimator = 0
  .BidAmount = 0
  .sqs = 0
  .BidMaterial = 0
  .Email = 0
  .Bid2Material = 0
  .Bid2Amount = 0
  .BusYrs = 0
  .TempNotUsed = 0 ' for future use if needed
End With

With Recap
  .CompanyName = 0
  .Estimator = 0
  .sDate = 0
  .BidAmount = 0
  .BidMaterial = 0
  .Bid2Amount = 0
  .Bid2Material = 0
  .sqs = 0
  .BusYrs = 0
   .TempNotUsed = 0    ' for future use if needed
End With

Open in new window

Avatar of Martin Liss
Martin Liss
Flag of United States of America image

Set the values = "" rather than 0.

If that doesn't work please show what you tried.
In other words

Private Phone As Phone_UDT

With Phone
  .Cell   =  ""
  .Office   =  ""
  .Emergency   =  ""
  .Fax   =  ""
  .Owner   =  ""
  .LasrRow   =  ""
  .TempNotUsed   =  ""
End With

Open in new window

Avatar of isnoend2001

ASKER

Thanks that gives an error
With Phone 'variable undefined
  .Cell   =  ""
  .Office   =  ""
  .Emergency   =  ""
  .Fax   =  ""
  .Owner   =  ""
  .LasrRow   =  ""
  .TempNotUsed   =  ""
I have tried these to no avail, probably erased other attempts
With RoofCompany(CurrentCompany)
'PhoneContact = "" 
'Phones.Cell = ""
'PhoneInfo(.Phones.Cell) = ""
''PhoneInfo(.Phones.Office) = ""
'PhoneContact(0) = ""
'' PhoneContact = PhoneInfo(.Phones.Cell)
' PhoneContact(1) = ""
End With
Did you see line 1 in my code? That line needs to be in the same module/form as the rest of the code. If it is someplace else make it Public rather than Private.
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
Thanks
btw changing the 0 to "" gives a type mismatch
btw changing the 0 to "" gives a type mismatch
I assume you mean when the variable is defined as Byte. A String variable (as in my post ID: 40339752) will be OK.
Thanks martinLiss
Re: btw changing the 0 to "" gives a type mismatch
Not sure if that would effect coding in other places
Posted a question to another site VBWire and the coder who answered decided to write the program.
Not sure how it happened
http://www.vbforums.com/showthread.php?775021-RESOLVED-How-to-Save-classes-to-binary-file-vb6

This program started as a app for Home Owners to track and compare different roofing bids
In talking to my sister who was getting Landscaping bids, she said "Too bad it would not track other Home
Owner bid types, so i decided to modify it so it would by using a combobox. My plan was this:
Make folders for each item in the combobox under the Home Owners Name-Address folder.
and add array to hold the full paths to the cbo items. This is why i need to reset all the UDT values.
Most of the code is over my head.
 Is there a reason for changing the the byte to string ?
Byte variables may have their place since they are smaller and faster than strings but unless your app is slow/and or bloated and you are needing to optimize it, IMO they aren't needed. In fact if you are trying to store text values then you can't use them because it won't compile. For example I changed the code above a bit and added two versions of "Owner", one Byte and one String and line 30 is a problem. Just in case you don't know, your UDTs don't have to be all Byte or all String. Each variable in the UDT can be whatever variable type is most appropriate.

Option Explicit
Private Type Phone_UDT
  Cell      As String
  Office    As String
  Emergency As String
  Fax       As String
  Owner_String     As String
  Owner_Byte As Byte
  LasrRow   As String
  TempNotUsed   As String ' for future use if needed
End Type
Private Phone As Phone_UDT


Sub Initialize()
With Phone
  .Cell = ""
  .Office = ""
  .Emergency = ""
  .Fax = ""
  .Owner_String = ""
  .Owner_Byte = 0
  .LasrRow = ""
  .TempNotUsed = ""
End With
End Sub

Private Sub Command1_Click()
Phone.Owner_String = "Marty"
Phone.Owner_Byte = "Marty" ' <-- Type Mismatch error
MsgBox Phone.Owner_Byte
Initialize
MsgBox Phone.Owner_Byte
End Sub

Open in new window

Thanks, good to know
i am sure i will have more questions by the this project is done
Thanks for the help on adding and making new cbo items selected and now
this clearing udt's.
Glad you are here
So am I:)