Solved

Trouble clearing the data in a UDT

Posted on 2014-09-23
11
99 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 47

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 47

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
Industry Leaders: 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 47

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 47

Accepted Solution

by:
Martin Liss earned 500 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 47

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 47

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 47

Expert Comment

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

Featured Post

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

738 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