?
Solved

Trouble clearing the data in a UDT

Posted on 2014-09-23
11
Medium Priority
?
105 Views
Last Modified: 2014-09-23
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

0
Comment
Question by:isnoend2001
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 4
11 Comments
 
LVL 49

Expert Comment

by:Martin Liss
ID: 40339652
Set the values = "" rather than 0.

If that doesn't work please show what you tried.
0
 
LVL 49

Expert Comment

by:Martin Liss
ID: 40339658
In other words

Private Phone As Phone_UDT

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

Open in new window

0
 

Author Comment

by:isnoend2001
ID: 40339724
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
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 49

Expert Comment

by:Martin Liss
ID: 40339735
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.
0
 
LVL 49

Accepted Solution

by:
Martin Liss earned 2000 total points
ID: 40339752
Here's code for a complete example. Add a command button to a form.

Option Explicit
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 Phone As Phone_UDT


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

Private Sub Command1_Click()
Phone.Owner = "Marty"
MsgBox Phone.Owner
Initialize
MsgBox Phone.Owner
End Sub

Open in new window

0
 

Author Closing Comment

by:isnoend2001
ID: 40339794
Thanks
btw changing the 0 to "" gives a type mismatch
0
 
LVL 49

Expert Comment

by:Martin Liss
ID: 40339805
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.
0
 

Author Comment

by:isnoend2001
ID: 40339857
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 ?
0
 
LVL 49

Expert Comment

by:Martin Liss
ID: 40339915
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

0
 

Author Comment

by:isnoend2001
ID: 40339942
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
0
 
LVL 49

Expert Comment

by:Martin Liss
ID: 40340008
So am I:)
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month11 days, 20 hours left to enroll

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question