Solved

Trouble clearing the data in a UDT

Posted on 2014-09-23
11
90 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
  • 7
  • 4
11 Comments
 
LVL 45

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 45

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
 
LVL 45

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 45

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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

Author Closing Comment

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

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 45

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 45

Expert Comment

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

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

762 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now