pass a variable from within a class

paulthepaddy

Well-known member
Joined
Apr 9, 2011
Messages
222
Location
UK
Programming Experience
Beginner
hey all this is confusing lol and im not sure if what i want is possable but we will see :D

i have a class called car and within that class i have a few vairables

VB.NET:
Public Class car
    Public Property Name As String
    Public Property ID As Byte
    Public Make As String
    Public Model As String
    Public Colour As String
    Public Reg As String
    Public FullDamageList As List(Of String) = New List(Of String)

#Region "Car Totals: SUB, TOTAL,DIS, ADD Finished"
    Public Subtotal As Char
    Public Discount As Char
    Public additional As Char
    Public Total As Char
    Public finished As Boolean = False
#End Region

#Region "SSR Lists & Price Variables"
    Public SSR_ScratchDamage As List(Of String) = New List(Of String)
    Public SSR_ScratchPrice As Short = 0

    Public SSR_StoneChipDamage As List(Of String) = New List(Of String)
    Public SSR_StoneChipPrice As Short = 0

    Public SSR_WalkaroundDamage As String
    Public SSR_WalkaroundPrice As Byte = 0
#End Region

#Region "Spray Lists & Price Variables"
    Public Spray_StandardDamage As List(Of String) = New List(Of String)
    Public Spray_StandardPrice As Short = 0

    Public Spray_ParkingSensorsDamage As String
    Public Spray_ParkingSensorsPrice As Byte = 0

    Public Spray_WingMirrorDamage As List(Of String) = New List(Of String)
    Public Spray_WingMirrorPrice As Byte = 0

    Public Spray_DoorMouldingDamage As List(Of String) = New List(Of String)
    Public Spray_DoorMouldingPrice As Integer = 0
#End Region

#Region "Fiber List & Price Variables"
    Public Fiber_CigaretteBurnDamage As List(Of String) = New List(Of String)
    Public Fiber_CigaretteBurnPrice As Short = 0

    Public Fiber_TornFabricDamage As List(Of String) = New List(Of String)
    Public Fiber_TornFabricPrice As Short = 0

    Public Fiber_WornFabricDamage As List(Of String) = New List(Of String)
    Public Fiber_WornFabricPrice As Short = 0

    Public Fiber_CigaretteBurninCarpetDamage As List(Of String) = New List(Of String)
    Public Fiber_CigaretteBurninCarpetPrice As Short = 0

    Public Fiber_TearinCarpetDamage As List(Of String) = New List(Of String)
    Public Fiber_TearinCarpetPrice As Short = 0
#End Region

#Region "Aroma"
    Public Aroma_Damage As String
    Public Aroma_Price As Byte = 0
#End Region

#Region "Glass Lists & Price"
    Public Glass_ScratcheDamage As List(Of String) = New List(Of String)
    Public Glass_ScratchePrice As Byte = 0

    Public Glass_ChipDamage As List(Of String) = New List(Of String)
    Public Glass_ChipPrice As Byte = 0
#End Region

i want to be able to call the variales through a variable for example

VB.NET:
Public sub Load_List_And_Price (SelectCar as Car, List as String, Price as string)
list = list & "Damage"
Price = Price & "Price"

for each item in selectcar.list
damage_list.item.add(list)
next

num_Subtotal.value = selectcar.price
end sub

VB.NET:
 Call Load_List_And_Price(Combobox_CurrentCar, Combobox_SSR.SelectedText,Combobox_SSR.SelectedText)

Combobox currentcar holds a list(of Car)
combobox SSr holds a service
so the values being passed to the sub would be

VB.NET:
 Call Load_List_And_Price(Car1, SSR_Scratch,SSR_Scratch)

turning the sub into this

VB.NET:
list = list & "Damage"
Price = Price & "Price"

for each item in Car1.SSR_ScratchDamage
damage_list.item.add(list)
next

num_Subtotal.value = Car1.SSR_Scratch.price
end sub

i hope this makes sense
 
I think you need to revisit the requirements. I understand the Car class -- but it seems that you have too many misc. properties for the Car.

VB.NET:
#Region "SSR Lists & Price Variables"
    Public SSR_ScratchDamage As List(Of String) = New List(Of String)
    Public SSR_ScratchPrice As Short = 0

    Public SSR_StoneChipDamage As List(Of String) = New List(Of String)
    Public SSR_StoneChipPrice As Short = 0

    Public SSR_WalkaroundDamage As String
    Public SSR_WalkaroundPrice As Byte = 0
#End Region

#Region "Spray Lists & Price Variables"
    Public Spray_StandardDamage As List(Of String) = New List(Of String)
    Public Spray_StandardPrice As Short = 0

    Public Spray_ParkingSensorsDamage As String
    Public Spray_ParkingSensorsPrice As Byte = 0

    Public Spray_WingMirrorDamage As List(Of String) = New List(Of String)
    Public Spray_WingMirrorPrice As Byte = 0

    Public Spray_DoorMouldingDamage As List(Of String) = New List(Of String)
    Public Spray_DoorMouldingPrice As Integer = 0
#End Region

#Region "Fiber List & Price Variables"
    Public Fiber_CigaretteBurnDamage As List(Of String) = New List(Of String)
    Public Fiber_CigaretteBurnPrice As Short = 0

    Public Fiber_TornFabricDamage As List(Of String) = New List(Of String)
    Public Fiber_TornFabricPrice As Short = 0

    Public Fiber_WornFabricDamage As List(Of String) = New List(Of String)
    Public Fiber_WornFabricPrice As Short = 0

    Public Fiber_CigaretteBurninCarpetDamage As List(Of String) = New List(Of String)
    Public Fiber_CigaretteBurninCarpetPrice As Short = 0

    Public Fiber_TearinCarpetDamage As List(Of String) = New List(Of String)
    Public Fiber_TearinCarpetPrice As Short = 0
#End Region

You have all these List(Of String) with different names, do they need to be that way? Perhaps you could make a Service class or Damage class then in the car class you could have
VB.NET:
Dim Damages as List(Of Damage) = new List(Of Damage)

maybe soemthing like
VB.NET:
Public Class Damage
     Public Enum DamageType As Integer
          None,
          Service,
          Fiber,
          Spray
     End Enum
     
     Private _name As String
     Private _price As Decimal
     Private _damageType As DamageType

     Public Property Name() As String
          Get
               Return _name
          End Get
          Set(ByVal value As String)
               _name = value
          End Set
     End Property

     Public Property Price() As Decimal
          Get
               Return _price
          End Get
          Set(ByVal value As Decimal)
               _price = value
          End Set     
     End Property

     Public Property TypeOfDamage() As DamageType
          Get
               Return _damageType
          End Get
          Set(ByVal value As DamageType)
               _damageType = value
          End Set
     End Property

     Public Sub New()
          MyBase.New()

     End Sub

     Public Sub New(ByVal name As String, ByVal price As Decimal, ByVal damageType As DamageType)
          Me.New()
          Name = name
          Price = price
          TypeOfDamage = damageType
     End Sub

End Class

And the way to use it in the car class
VB.NET:
Public Class car
     Public Property Name As String
     Public Property ID As Byte
     Public Make As String
     Public Model As String
     Public Colour As String
     Public Reg As String
     Private _damages As List(Of Damage)

     Public Property ReadOnly Damages As List(Of Damage)
          Get
               Return _damages
          End Get
     End Property

     Public Sub AddDamage(ByVal damageToAdd As Damage)
          If _damages Is Nothing
               _damages = New List(Of Damage)()
          End If

          _damages.Add(damageToAdd)          
     End Sub

     'Code snip
End Class

Maybe you cannot go back and write the code to function this way, but I think (imo) that it would be better to separate it out to classes. Each damage contains it's own price so that way if Damage ABC has a price of $200.00 on Car XYZ then it can be different from Damage ABC with $300.00 on Car JKL. Also now your car class can use a method or property to iterate over each Damage and return a total or subtotal of Price. If you need to add a damage, instantiate an instance of the Damage class rather than having to add a List(Of String) to the car class, rebuild, etc...

I think I have the code written up pretty good, did all out of the IDE so make sure to check it over if you use it.
 
hi demausdauth

Thanks for your effort and your time for looking into this thanks.
i have drew a small picture to show you what the list's are for.

I have so many lists as it is helpful for when i need to send the car data form the application to a word document.
im not a professional or much exsperience everything i know is self taught
BTW im doing this for my uncles buisness so im not a script kiddie trying to make a few bucks from other peoples knowledge
it also allows me to control Easier how the damage is displayed on the invoice below is a few examples

1) First Example
How it is selected on application:

SSR - Stone Chip - Bonnet
SSR - Stone Chip - Front O/S Bumper
SSR - Stone Chip - Front O/S Door

How it Looks on Invoice:

Repair Stone Chips on Bonnet
Front O/S Bumper
Front O/S Door

2) Second Example
How it is selected on application:

SSR - Stone Chip - Bonnet
SSR - Stone Chip - Front O/S Bumper
SSR - Scratch - Front O/S Door

How it Looks on Invoice:

Repair Stone Chips on Bonnet
Front O/S Bumper

Repair Scratch on Front O/S Door

3) Third Example
How it is selected on application:

SSR - Stone Chip - Bonnet
SSR - Stone Chip - Front O/S Bumper
SSR - Scratch - Front O/S Door
Spray - Parking Sensors - Parking Sensors

How it Looks on Invoice:

Repair Stone Chips on Bonnet
Front O/S Bumper

Repair Scratch on Front O/S Door

Paint Parking Sesnors

Their are so many diffrent lists as each Service has a diffrent Description on the invoice and price
Example
in SSR (Sprayless Special Repair) Stone Chip & Scratch have the same price formula but are diffrent on invoice

Repair Scratch
Repair Stone Chips

Where The Spraying Has The Same(ish) Price
Paint Standard Panel has the same price formula for whole car
Apart From the parking sensors, Wing Mirror, and door moulding
So each one again needs their own list.

i found Seperate lists easier because if the user forgets to add a peice of damage to the list it will check the damage already in the list then clear the list so i dont have to worry about
damage being entered in twice or getting put into the wrong place in the list, correct price.

i had thought about creating a class for the damage but i thought it would end up being harder as the damage to be added to the car is in a checkedlist box the checked items get sent to a sub depending on a delegate
which adds it to the corrisponding list with the corrisponding price

if you really wanted (absolutaly no obligation) i could send you the solutions and let you have a wee look around. you could tell me what areas needs to be improved and what they can be improved with (i mean like use a delegate here or just something i can find information about so im still learning :D)

Diagrame.png
 
My general rule of thumb is to make things as generic as possible to start with and then work towards specifics. This is why I suggested the general list of Damages, you can add as many as you like to a car or as few and no changes need to done to the Car class.

If you make the damages/services database driven (or whatever you are using for data storage) then you could have a table.

DamageValues (DamageValues_ID int (PK), DamageValues_Name varchar(250), DamageValues_BasePrice decimal, DamageValues_Group)

where some values might be
1 Stone Chip - Bonnet ??? SSR
2 Stone Chip - Front O/S Bumper ??? SSR


What does this allow?
1) Damages are flexible, easily added or taken away from the application itself.
2) To fill comboboxes you can select from the DB and based on a where statement. This could be part of the DamageValues_Group that I proposed above or even other fields.
3) No need to check for specific damages -- becomes more or less does this DamageValues_ID exist in the list of Damages on the Car class already, if so then we can't add it again.



Just some more suggestions.

If you want me to take a look at the solution and offer some advice I can.
 
hey sorry for late reply, i have been really busy with my uncle sure if you give me your email or something i will send them i think its easier ooking at the whole thing and seeing what can be replaced and what cant be replaced, as i said though i have selftaught so their is probably a lot that can be changed lol
 
Back
Top