VB HELP NEEDED - URGENT !

Associate
Joined
2 Oct 2007
Posts
1,595
Location
Birmingham
right guys i've gotta finish my program today and finish the write up which i havent started yet by today and uploaded by 5pm.

Im having trouble finishing off my program atm. a number of problems where i am stuck.

I'll show you my first.....

vbhelp1.jpg


Basicly form one is where you choose the car and the details appear in listbox1 (RED)

and i need to be able to hit 'Buy' on form one and then the all those car details to be added into listbox1 (Black) on the next form so the infomation is there when you buying a car ?

I think you have to create a module or class but i have no idea where to go from here.

Can anyone please help me ?
 
Form2.ListBox1.Text = Form1.ListBox1.Text

Put this into the "Buy" button command in Form1 after the code to load Form2.

The above should work for VB6, it will hopefully be similar for a later version.
 
If you want to use a class:

Create a car details class:
Public Class clsCarDetails
public regNumber as string
public regDate as string
'etc
'Should really be read write properties but you can write that yourself
End Class

When the buy button is clicked create an instance of the clsCarDetails

Private Sub button1_click(Blah)
dim cd as new clsCarDetails
'set the properties of the class
cd.regNumber = varRegNumber 'or whatever you've got it stored as
cd.regDate = varRegDate 'or whatever you've got it stored as

'Create the new form
Dim detForm as new FormDetails(cd)
detForm.show()

End sub

On FormDetails:

Public Sub New(CarDets as clsCarDetails)

listbox1.add(CarDets.regNumber)

End Sub
 
Last edited:
Ah well the car system works like this ...

Combobox1 Code :
Code:
 If ComboBox1.Text.StartsWith("Audi") Then
            ComboBox2.Items.Clear()
            ComboBox2.Items.Add("A4")
            ComboBox2.Items.Add("RS4")
        End If



        If ComboBox1.Text.StartsWith("BMW") Then
            ComboBox2.Items.Clear()
            ComboBox2.Items.Add("3-Series")
            ComboBox2.Items.Add("5-Series")
        End If

Combobox2 Code:
Code:
If ComboBox2.Text.StartsWith("A4") Then
            ComboBox3.Items.Clear()
            ComboBox3.Items.Add("1.8T 4d - YC52 PSY")
            ComboBox3.Items.Add("1.8T Sport 4d - LD51 FWH")

        End If

        If ComboBox2.Text.StartsWith("RS4") Then
            ComboBox3.Items.Clear()
            ComboBox3.Items.Add("4.2 FSI Quattro 4d Saloon - BN06 JXH")

        End If

        If ComboBox2.Text.StartsWith("3-Series") Then
            ComboBox3.Items.Clear()
            ComboBox3.Items.Add("320i - BT57 XWG")
            ComboBox3.Items.Add("330i - BG57 LPO")

        End If

Listbox1(red) Code
Code:
If ComboBox3.SelectedItem = "1.8T 4d - YC52 PSY" Then
            ListBox1.Items.Clear()
            ListBox1.Items.Add("Reg Number :YC52 PSY ")
            ListBox1.Items.Add("Reg Date :2003")
            ListBox1.Items.Add("Colour : Silver")
            ListBox1.Items.Add("Mileage : 85684")
            ListBox1.Items.Add("Doors : 5")
            ListBox1.Items.Add("Transmission : Auto")
            ListBox1.Items.Add("Service History : Yes")
            ListBox1.Items.Add("Engine Size : 1,781 cc")
            ListBox1.Items.Add("Drive Side : RHD")
        End If

        If ComboBox3.SelectedItem = "1.8T Sport 4d - LD51 FWH" Then
            ListBox1.Items.Clear()
            ListBox1.Items.Add("Reg Number :LD51 FWH ")
            ListBox1.Items.Add("Reg Date :2004")
            ListBox1.Items.Add("Colour : Gray")
            ListBox1.Items.Add("Mileage : 90764")
            ListBox1.Items.Add("Doors : 5")
            ListBox1.Items.Add("Transmission : Manual")
            ListBox1.Items.Add("Service History : Yes")
            ListBox1.Items.Add("Engine Size : 1,781 cc")
            ListBox1.Items.Add("Drive Side : RHD")
        End If

So i dont know if i can do it the way you've shown me ?

I've done it this way because the task is to make a replica system. all the loose ends dont have to tie up. like on the buy menus when you hit by, its just a messagebox saying Congrats you've successfully made a sale.
 
Create a car details class:
Code:
Public Class clsCarDetails

private sregNum as string
private sregDate as string

   Public Property RegNumber As String
        Get
            Return "Reg Number : " & sregNum
        End Get
        Set(ByVal value As string)
            sregNum = value
        End Set
    End Property

   Public Property RegDate As String
        Get
            Return "Reg Date : " & sregDate
        End Get
        Set(ByVal value As string)
            sregdate = value
        End Set
    End Property
'etc
End Class

In the first form:

Code:
private cd as clsCarDetails

In this bit:

Code:
If ComboBox3.SelectedItem = "1.8T 4d - YC52 PSY" Then
    cd = new clsCarDetails
    cd.RegNumber = "YC52 PSY"
    cd.RegDate = "2003"

    ListBox1.Items.Clear()
    ListBox1.Items.Add(cd.RegNumber)
    ListBox1.Items.Add(cd.RegDate)
'etc

On the buy button

Code:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  Dim dtForm as new Form2(cd)
  dtForm.show()
  me.hide()
End Sub

in your form 2 code

Code:
Public Sub New(CarDets as clsCarDetails)
InitializeComponent()
listbox1.Items.clear()
listbox1.Items.add(CarDets.RegNumber)
listbox1.Items.add(CarDets.RegDate)

End Sub


The other way in .Net is:
Code:
   Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Form2.Show()
        Me.Hide()
        Form2.ListBox1.Items.AddRange(Me.ListBox1.Items)
    End Sub

Let us know what grade you get...
 
Last edited:
someone needs to think about naming their controls, dam its confusing trying to understand what a control/form does when its called xxx1
 
Code:
cd = new clsCarDetails
cd.RegNumber = "YC52 PSY"
cd.RegDate = "2003"

Can you explain what these are ?
sorry just i need to understand it all so i put it in. because i dont know what im putting in atm ?

What are the CD. ? because there not being recognised.
 
Code:
cd = new clsCarDetails
cd.RegNumber = "YC52 PSY"
cd.RegDate = "2003"

Can you explain what these are ?
sorry just i need to understand it all so i put it in. because i dont know what im putting in atm ?

What are the CD. ?

cd is just the name of the variable that holds the pointer to the class that will hold all the data about the car.
You could have had:
Code:
OneCarDetailsWhichReturnsFormatedTextForEachParameter = New ClsCarDetails
But that's a bit long.

Just like you can have
Dim s as String
s="some text"

As I defined cd as clsCarDetails at the top of the first form I can use cd = New clsCarDetails

Make sure you have created the clsCarDetails class first and added the line
Private cd as clsCarDetails
to the top of Form1

Simon
 
ok well i've put in

"private cd as clsCarDetails"

at the top of form 1 and saved but its still not recognising cd anywhere in the project ?
 
Have you created the clsCarDetails?
And when I say top it should be:
Code:
Option Strict On
Option Explicit On
Imports system.windows.forms
Public Class Form1
    Private cd As clsCarDetails
'etc

Form1 code:
Code:
Option Strict On
Option Explicit On
Imports system.windows.forms
Public Class Form1
    Private cd As clsCarDetails
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim dtForm As New Form2(cd)
        dtForm.Show()
        Me.Hide()
    End Sub

    Private Sub ComboBox3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox3.Click
        If ComboBox3.SelectedText = "1.8T 4d - YC52 PSY" Then
            cd = New clsCarDetails
            cd.RegNumber = "YC52 PSY"
            cd.RegDate = "2003"

            ListBox1.Items.Clear()
            ListBox1.Items.Add(cd.RegNumber)
            ListBox1.Items.Add(cd.RegDate)
            'etc
        End If
    End Sub
End Class
 
Last edited:
Yeah i created the class and pasted all that jazz in there ^^ and saved but i havent added all this option stuff in that you've just said.

i'll give it a whirl.
 
form 2 code
Code:
Option Explicit On
Option Strict On
Public Class Form2

    Private Sub Form2_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
        Form1.Show()
    End Sub

    Public Sub New()
        ' This call is required by the Windows Form Designer.
        InitializeComponent()
        ' Add any initialization after the InitializeComponent() call.
    End Sub

    Public Sub New(ByVal CarDets As clsCarDetails)
        InitializeComponent()

        ListBox1.Items.Clear()
        ListBox1.Items.Add(CarDets.RegNumber)
        ListBox1.Items.Add(CarDets.RegDate)

    End Sub
End Class

class
Code:
Option Explicit On
Option Strict On
Public Class clsCarDetails

    Private regNum As String
    Private sregDate As String

    Public Property RegNumber() As String
        Get
            Return "Reg Number : " & regNum
        End Get
        Set(ByVal value As String)
            regNum = value
        End Set
    End Property

    Public Property RegDate() As String
        Get
            Return "Reg Date : " & sregDate
        End Get
        Set(ByVal value As String)
            sregDate = value
        End Set
    End Property
    'etc
End Class
 
lol oh dear I've put that in and its now not recognising :
"ComboBox3.SelectedItem"

Sorry to be such a pain !
I'll just have leave it and upload what I've done.
unless you want to look at my app and see what i've done wrong ?
 
Try again!

Form1: you will have to change the code in the ComboBox2_selectedIndexChanged sub to the same as the top two examples I have done.
Code:
Option Strict On
Option Explicit On
Imports system.windows.forms
Public Class Form1
    Private cd As clsCarDetails
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim dtForm As New Form2(cd)
        dtForm.Show()
        Me.Hide()
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Form3.Show()
        Me.Hide()
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Form4.Show()
        Me.Hide()
    End Sub

    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged

        If ComboBox1.Text.StartsWith("Audi") Then
            ComboBox2.Items.Clear()
            ComboBox2.Items.Add("A4")
            ComboBox2.Items.Add("RS4")
        End If

        If ComboBox1.Text.StartsWith("BMW") Then
            ComboBox2.Items.Clear()
            ComboBox2.Items.Add("3-Series")
            ComboBox2.Items.Add("5-Series")
        End If

        If ComboBox1.Text.StartsWith("Citroen") Then
            ComboBox2.Items.Clear()
            ComboBox2.Items.Add("C4")
            ComboBox2.Items.Add("C5")
        End If

        If ComboBox1.Text.StartsWith("Honda") Then
            ComboBox2.Items.Clear()
            ComboBox2.Items.Add("Civic")
            ComboBox2.Items.Add("Jazz")
        End If

        If ComboBox1.Text.StartsWith("Ford") Then
            ComboBox2.Items.Clear()
            ComboBox2.Items.Add("Focus")
            ComboBox2.Items.Add("Fiesta")
        End If

        If ComboBox1.Text.StartsWith("Vauxhall") Then
            ComboBox2.Items.Clear()
            ComboBox2.Items.Add("Corsa")
            ComboBox2.Items.Add("Vectra")
        End If


    End Sub


    Private Sub ComboBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox2.SelectedIndexChanged
        If ComboBox2.Text.StartsWith("A4") Then
            ComboBox3.Items.Clear()
            ComboBox3.Items.Add("1.8T 4d - YC52 PSY")
            ComboBox3.Items.Add("1.8T Sport 4d - LD51 FWH")

        End If

        If ComboBox2.Text.StartsWith("RS4") Then
            ComboBox3.Items.Clear()
            ComboBox3.Items.Add("4.2 FSI Quattro 4d Saloon - BN06 JXH")

        End If

        If ComboBox2.Text.StartsWith("3-Series") Then
            ComboBox3.Items.Clear()
            ComboBox3.Items.Add("320i - BT57 XWG")
            ComboBox3.Items.Add("330i - BG57 LPO")

        End If

        If ComboBox2.Text.StartsWith("5-Series") Then
            ComboBox3.Items.Clear()
            ComboBox3.Items.Add("520i - MM51 GPE")
            ComboBox3.Items.Add("530i - KO93 MMC")

        End If

        If ComboBox2.Text.StartsWith("C4") Then
            ComboBox3.Items.Clear()
            ComboBox3.Items.Add("1.6i 16V SX 5d - GH89 ILE")
            ComboBox3.Items.Add("1.6HDi 16V VTR Plus 5d")

        End If

        If ComboBox2.Text.StartsWith("C5") Then
            ComboBox3.Items.Clear()
            ComboBox3.Items.Add("2.7 HDI V6 Exclusive - DF23 LSP")
            ComboBox3.Items.Add("2.2 HDI 16V VTR+ - DF34 LSO")

        End If

        If ComboBox2.Text.StartsWith("Fiesta") Then
            ComboBox3.Items.Clear()
            ComboBox3.Items.Add("ST 2d - KN55 LHC")
            ComboBox3.Items.Add("Zetec S - CW06 TPS")

        End If

        If ComboBox2.Text.StartsWith("Focus") Then
            ComboBox3.Items.Clear()
            ComboBox3.Items.Add("TDCi Titanium - FP34 FPS")
            ComboBox3.Items.Add("RS - KO59 FPT")

        End If

        If ComboBox2.Text.StartsWith("Civic") Then
            ComboBox3.Items.Clear()
            ComboBox3.Items.Add("i-VTEC GT - LP07 LFP")
            ComboBox3.Items.Add("i-CTDi S - LA06 LFP")

        End If

        If ComboBox2.Text.StartsWith("Corsa") Then
            ComboBox3.Items.Clear()
            ComboBox3.Items.Add("12v Life - LG34 LPS")
            ComboBox3.Items.Add("16v SXi - FL45 FPS")

        End If

        If ComboBox2.Text.StartsWith("Vectra") Then
            ComboBox3.Items.Clear()
            ComboBox3.Items.Add("CDTi 16V Elite - SP20 LPS")
            ComboBox3.Items.Add("V6 CDTi SRi - KP05 LAP")

        End If
    End Sub
    Private Sub ComboBox3_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox3.SelectedIndexChanged
        If ComboBox3.Text = "1.8T 4d - YC52 PSY" Then
            cd = New clsCarDetails
            cd.RegNumber = "YC52 PSY"
            cd.RegDate = "2003"
            cd.Colour = "Silver"
            cd.Mileage = "85684"
            cd.Doors = "5"
            cd.Transmission = "Auto"
            cd.ServiceHistory = "Yes"
            cd.EngineSize = "1,781 cc"
            cd.DriveSide = "RHD"
        End If

        If ComboBox3.Text = "1.8T Sport 4d - LD51 FWH" Then
            cd = New clsCarDetails
            cd.RegNumber = "LD51 FWH"
            cd.RegDate = "2004"
            cd.Colour = "Gray"
            cd.Mileage = "90764"
            cd.Doors = "5"
            cd.Transmission = "Manual"
            cd.ServiceHistory = "Yes"
            cd.EngineSize = "1,781 cc"
            cd.DriveSide = "RHD"
        End If

        If ComboBox3.Text = "4.2 FSI Quattro 4d Saloon - BN06 JXH" Then
            ListBox1.Items.Clear()
            ListBox1.Items.Add("Reg Number :BN06 JXH ")
            ListBox1.Items.Add("Reg Date :2006")
            ListBox1.Items.Add("Colour : Blue")
            ListBox1.Items.Add("Mileage : 40694")
            ListBox1.Items.Add("Doors : 5")
            ListBox1.Items.Add("Transmission : Manual")
            ListBox1.Items.Add("Service History : Yes")
            ListBox1.Items.Add("Engine Size : 4,200 cc")
            ListBox1.Items.Add("Drive Side : RHD")
        End If

        If ComboBox3.Text = "320i - BT57 XWG" Then
            ListBox1.Items.Clear()
            ListBox1.Items.Add("Reg Number :BT57 XWG ")
            ListBox1.Items.Add("Reg Date :2006")
            ListBox1.Items.Add("Colour : Blue")
            ListBox1.Items.Add("Mileage : 19856")
            ListBox1.Items.Add("Doors : 5")
            ListBox1.Items.Add("Transmission : Manual")
            ListBox1.Items.Add("Service History : Yes")
            ListBox1.Items.Add("Engine Size : 2,000 cc")
            ListBox1.Items.Add("Drive Side : RHD")
        End If

        If ComboBox3.Text = "330i - BG57 LPO" Then
            ListBox1.Items.Clear()
            ListBox1.Items.Add("Reg Number :BG57 LPO ")
            ListBox1.Items.Add("Reg Date :2006")
            ListBox1.Items.Add("Colour : Black")
            ListBox1.Items.Add("Mileage : 23948")
            ListBox1.Items.Add("Doors : 5")
            ListBox1.Items.Add("Transmission : Auto")
            ListBox1.Items.Add("Service History : Yes")
            ListBox1.Items.Add("Engine Size : 3,000 cc")
            ListBox1.Items.Add("Drive Side : LHD")

        End If

        If ComboBox3.Text = "520i - MM51 GPE" Then
            ListBox1.Items.Clear()
            ListBox1.Items.Add("Reg Number :MM51 GPE ")
            ListBox1.Items.Add("Reg Date :2001")
            ListBox1.Items.Add("Colour : Blue")
            ListBox1.Items.Add("Mileage : 66000")
            ListBox1.Items.Add("Doors : 5")
            ListBox1.Items.Add("Transmission : Auto")
            ListBox1.Items.Add("Service History : Yes")
            ListBox1.Items.Add("Engine Size : 2,171 cc")
            ListBox1.Items.Add("Drive Side : RHD")

        End If

        If ComboBox3.Text = "530i - KO93 MMC" Then
            ListBox1.Items.Clear()
            ListBox1.Items.Add("Reg Number :KO93 MMC")
            ListBox1.Items.Add("Reg Date :2003")
            ListBox1.Items.Add("Colour : Gray")
            ListBox1.Items.Add("Mileage : 35649")
            ListBox1.Items.Add("Doors : 5")
            ListBox1.Items.Add("Transmission : Auto")
            ListBox1.Items.Add("Service History : Yes")
            ListBox1.Items.Add("Engine Size : 3,000 cc")
            ListBox1.Items.Add("Drive Side : RHD")

        End If

        If ComboBox3.Text = "1.6i 16V SX 5d - GH89 ILE" Then
            ListBox1.Items.Clear()
            ListBox1.Items.Add("Reg Number :GH89 ILE")
            ListBox1.Items.Add("Reg Date :2005")
            ListBox1.Items.Add("Colour : White")
            ListBox1.Items.Add("Mileage : 46958")
            ListBox1.Items.Add("Doors : 3")
            ListBox1.Items.Add("Transmission : Manual")
            ListBox1.Items.Add("Service History : Yes")
            ListBox1.Items.Add("Engine Size : 1,560 cc")
            ListBox1.Items.Add("Drive Side : RHD")

        End If

        If ComboBox3.Text = "1.6HDi 16V VTR Plus 5d - LEE KJ0" Then
            ListBox1.Items.Clear()
            ListBox1.Items.Add("Reg Number :LEE KJ0")
            ListBox1.Items.Add("Reg Date :2006")
            ListBox1.Items.Add("Colour : Blue")
            ListBox1.Items.Add("Mileage : 56437")
            ListBox1.Items.Add("Doors : 5")
            ListBox1.Items.Add("Transmission : Manual")
            ListBox1.Items.Add("Service History : Yes")
            ListBox1.Items.Add("Engine Size : 1,560 cc")
            ListBox1.Items.Add("Drive Side : RHD")

        End If

        If ComboBox3.Text = "2.7 HDI V6 Exclusive - DF23 LSP" Then
            ListBox1.Items.Clear()
            ListBox1.Items.Add("Reg Number :DF23 LSP")
            ListBox1.Items.Add("Reg Date :2008")
            ListBox1.Items.Add("Colour : Red")
            ListBox1.Items.Add("Mileage : 46958")
            ListBox1.Items.Add("Doors : 5")
            ListBox1.Items.Add("Transmission : Manual")
            ListBox1.Items.Add("Service History : Yes")
            ListBox1.Items.Add("Engine Size : 2,7000 cc")
            ListBox1.Items.Add("Drive Side : LHD")

        End If

        If ComboBox3.Text = "2.2 HDI 16V VTR+ - DF34 LSO" Then
            ListBox1.Items.Clear()
            ListBox1.Items.Add("Reg Number :DF34 LSO")
            ListBox1.Items.Add("Reg Date :2008")
            ListBox1.Items.Add("Colour : Black")
            ListBox1.Items.Add("Mileage : 46958")
            ListBox1.Items.Add("Doors : 5")
            ListBox1.Items.Add("Transmission : Manual")
            ListBox1.Items.Add("Service History : Yes")
            ListBox1.Items.Add("Engine Size : 2,250 cc")
            ListBox1.Items.Add("Drive Side : RHD")

        End If

        If ComboBox3.Text = "i-VTEC GT - LP07 LFP" Then
            ListBox1.Items.Clear()
            ListBox1.Items.Add("Reg Number :LP07 LFP")
            ListBox1.Items.Add("Reg Date :2006")
            ListBox1.Items.Add("Colour : Black")
            ListBox1.Items.Add("Mileage : 15986")
            ListBox1.Items.Add("Doors :3")
            ListBox1.Items.Add("Transmission : Manual")
            ListBox1.Items.Add("Service History : Yes")
            ListBox1.Items.Add("Engine Size : 1,999 cc")
            ListBox1.Items.Add("Drive Side : RHD")

        End If

        If ComboBox3.Text = "i-CTDi S - LA06 LFP" Then
            ListBox1.Items.Clear()
            ListBox1.Items.Add("Reg Number :LA06 LFP")
            ListBox1.Items.Add("Reg Date :2006")
            ListBox1.Items.Add("Colour : Black")
            ListBox1.Items.Add("Mileage : 12000")
            ListBox1.Items.Add("Doors :3")
            ListBox1.Items.Add("Transmission : Manual")
            ListBox1.Items.Add("Service History : Yes")
            ListBox1.Items.Add("Engine Size : 2,200 cc")
            ListBox1.Items.Add("Drive Side : RHD")

        End If

        If ComboBox3.Text = "i-VTEC ES - GF05 TGB" Then
            ListBox1.Items.Clear()
            ListBox1.Items.Add("Reg Number :GF05 TGB")
            ListBox1.Items.Add("Reg Date :2006")
            ListBox1.Items.Add("Colour : Yellow")
            ListBox1.Items.Add("Mileage : 46985")
            ListBox1.Items.Add("Doors :5")
            ListBox1.Items.Add("Transmission : Manual")
            ListBox1.Items.Add("Service History : Yes")
            ListBox1.Items.Add("Engine Size : 1,400 cc")
            ListBox1.Items.Add("Drive Side : RHD")

        End If

        If ComboBox3.Text = "i-VTEC S - GF06 KLP" Then
            ListBox1.Items.Clear()
            ListBox1.Items.Add("Reg Number :LA06 LFP")
            ListBox1.Items.Add("Reg Date :2006")
            ListBox1.Items.Add("Colour : Blue")
            ListBox1.Items.Add("Mileage : 26395")
            ListBox1.Items.Add("Doors :3")
            ListBox1.Items.Add("Transmission : Manual")
            ListBox1.Items.Add("Service History : Yes")
            ListBox1.Items.Add("Engine Size : 1,200 cc")
            ListBox1.Items.Add("Drive Side : RHD")

        End If

        If ComboBox3.Text = "ST 2d - KN55 LHC" Then
            ListBox1.Items.Clear()
            ListBox1.Items.Add("Reg Number :KN55 LHC")
            ListBox1.Items.Add("Reg Date :2005")
            ListBox1.Items.Add("Colour : White")
            ListBox1.Items.Add("Mileage : 35000")
            ListBox1.Items.Add("Doors :3")
            ListBox1.Items.Add("Transmission : Manual")
            ListBox1.Items.Add("Service History : Yes")
            ListBox1.Items.Add("Engine Size : 2,000 cc")
            ListBox1.Items.Add("Drive Side : RHD")

        End If

        If ComboBox3.Text = "Zetec S - CW06 TPS" Then
            ListBox1.Items.Clear()
            ListBox1.Items.Add("Reg Number :CW06 TPS")
            ListBox1.Items.Add("Reg Date :2000")
            ListBox1.Items.Add("Colour : Black")
            ListBox1.Items.Add("Mileage : 86000")
            ListBox1.Items.Add("Doors :3")
            ListBox1.Items.Add("Transmission : Manual")
            ListBox1.Items.Add("Service History : Yes")
            ListBox1.Items.Add("Engine Size : 1,599 cc")
            ListBox1.Items.Add("Drive Side : RHD")

        End If

        If ComboBox3.Text = "TDCi Titanium - FP34 FPS" Then
            ListBox1.Items.Clear()
            ListBox1.Items.Add("Reg Number :FP34 FPS")
            ListBox1.Items.Add("Reg Date :2004")
            ListBox1.Items.Add("Colour : Black")
            ListBox1.Items.Add("Mileage : 68742")
            ListBox1.Items.Add("Doors :5")
            ListBox1.Items.Add("Transmission : Manual")
            ListBox1.Items.Add("Service History : Yes")
            ListBox1.Items.Add("Engine Size : 2,000 cc")
            ListBox1.Items.Add("Drive Side : RHD")

        End If

        If ComboBox3.Text = "RS - KO59 FPT" Then
            ListBox1.Items.Clear()
            ListBox1.Items.Add("Reg Number :KO59 FPT")
            ListBox1.Items.Add("Reg Date :2002")
            ListBox1.Items.Add("Colour : Blue")
            ListBox1.Items.Add("Mileage : 76408")
            ListBox1.Items.Add("Doors :3")
            ListBox1.Items.Add("Transmission : Manual")
            ListBox1.Items.Add("Service History : Yes")
            ListBox1.Items.Add("Engine Size : 2,000 cc")
            ListBox1.Items.Add("Drive Side : RHD")

        End If

        If ComboBox3.Text = "12v Life - LG34 LPS" Then
            ListBox1.Items.Clear()
            ListBox1.Items.Add("Reg Number :LG34 LPS")
            ListBox1.Items.Add("Reg Date :2004")
            ListBox1.Items.Add("Colour : Black")
            ListBox1.Items.Add("Mileage : 67483")
            ListBox1.Items.Add("Doors :5")
            ListBox1.Items.Add("Transmission : Manual")
            ListBox1.Items.Add("Service History : Yes")
            ListBox1.Items.Add("Engine Size : 1,000 cc")
            ListBox1.Items.Add("Drive Side : RHD")

        End If

        If ComboBox3.Text = "16v SXi - FL45 FPS" Then
            ListBox1.Items.Clear()
            ListBox1.Items.Add("Reg Number :FL45 FPS")
            ListBox1.Items.Add("Reg Date :2004")
            ListBox1.Items.Add("Colour : Silver")
            ListBox1.Items.Add("Mileage : 46723")
            ListBox1.Items.Add("Doors :3")
            ListBox1.Items.Add("Transmission : Manual")
            ListBox1.Items.Add("Service History : Yes")
            ListBox1.Items.Add("Engine Size : 1,200 cc")
            ListBox1.Items.Add("Drive Side : RHD")

        End If

        If ComboBox3.Text = "CDTi 16V Elite - SP20 LPS" Then
            ListBox1.Items.Clear()
            ListBox1.Items.Add("Reg Number :SP20 LPS")
            ListBox1.Items.Add("Reg Date :2005")
            ListBox1.Items.Add("Colour : Silver")
            ListBox1.Items.Add("Mileage : 46723")
            ListBox1.Items.Add("Doors :5")
            ListBox1.Items.Add("Transmission : Manual")
            ListBox1.Items.Add("Service History : Yes")
            ListBox1.Items.Add("Engine Size : 1,850 cc")
            ListBox1.Items.Add("Drive Side : RHD")

        End If

        If ComboBox3.Text = "V6 CDTi SRi - KP05 LAP" Then
            ListBox1.Items.Clear()
            ListBox1.Items.Add("Reg Number :KP05 LAP")
            ListBox1.Items.Add("Reg Date :2005")
            ListBox1.Items.Add("Colour : Red")
            ListBox1.Items.Add("Mileage : 73425")
            ListBox1.Items.Add("Doors :5")
            ListBox1.Items.Add("Transmission : Manual")
            ListBox1.Items.Add("Service History : Yes")
            ListBox1.Items.Add("Engine Size : 3,000 cc")
            ListBox1.Items.Add("Drive Side : RHD")
        End If

        ListBox1.Items.Clear()
        ListBox1.Items.Add(cd.RegNumber)
        ListBox1.Items.Add(cd.RegDate)
        ListBox1.Items.Add(cd.Colour)
        ListBox1.Items.Add(cd.Mileage)
        ListBox1.Items.Add(cd.Doors)
        ListBox1.Items.Add(cd.Transmission)
        ListBox1.Items.Add(cd.ServiceHistory)
        ListBox1.Items.Add(cd.EngineSize)
        ListBox1.Items.Add(cd.DriveSide)

    End Sub
End Class

clsCarDetails: You had 2 class definitions in your original code
Code:
Option Explicit On
Option Strict On
Public Class clsCarDetails

    Private regNum As String = ""
    Private sregDate As String = ""
    Private sColour As String = ""
    Private sMileage As String = ""
    Private sDoors As String = ""
    Private sTransmission As String = ""
    Private sServiceHistory As String = ""
    Private sEngineSize As String = ""
    Private sDriveSide As String = ""
    Public Property RegNumber() As String
        Get
            Return "Reg Number : " & regNum
        End Get
        Set(ByVal value As String)
            regNum = value
        End Set
    End Property
    Public Property RegDate() As String
        Get
            Return "Reg Date : " & sregDate
        End Get
        Set(ByVal value As String)
            sregDate = value
        End Set
    End Property
    Public Property Colour() As String
        Get
            Return "Colour : " & sColour
        End Get
        Set(ByVal value As String)
            sColour = value
        End Set
    End Property
    Public Property Mileage() As String
        Get
            Return "Mileage : " & sMileage
        End Get
        Set(ByVal value As String)
            sMileage = value
        End Set
    End Property

    Public Property Doors() As String
        Get
            Return "Doors : " & sDoors
        End Get
        Set(ByVal value As String)
            sDoors = value
        End Set
    End Property

    Public Property Transmission() As String
        Get
            Return "Transmission : " & sTransmission
        End Get
        Set(ByVal value As String)
            sTransmission = value
        End Set
    End Property

    Public Property ServiceHistory() As String
        Get
            Return "Service History : " & sServiceHistory
        End Get
        Set(ByVal value As String)
            sServiceHistory = value
        End Set
    End Property
    Public Property EngineSize() As String
        Get
            Return "Engine Size : " & sEngineSize
        End Get
        Set(ByVal value As String)
            sEngineSize = value
        End Set
    End Property
    Public Property DriveSide() As String
        Get
            Return "Drive Side : " & sDriveSide
        End Get
        Set(ByVal value As String)
            sDriveSide = value
        End Set
    End Property
End Class

Form2:
Code:
Option Explicit On
Option Strict On
Public Class Form2

    Public Sub New(ByVal CarDets As clsCarDetails)
        InitializeComponent()

        ListBox1.Items.Clear()
        ListBox1.Items.Add(CarDets.RegNumber)
        ListBox1.Items.Add(CarDets.RegDate)
        ListBox1.Items.Add(CarDets.Colour)
        ListBox1.Items.Add(CarDets.Mileage)
        ListBox1.Items.Add(CarDets.Doors)
        ListBox1.Items.Add(CarDets.Transmission)
        ListBox1.Items.Add(CarDets.ServiceHistory)
        ListBox1.Items.Add(CarDets.EngineSize)
        ListBox1.Items.Add(CarDets.DriveSide)

    End Sub
    Private Sub Form2_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
        Form1.Show()
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Form1.Show()
        Me.Hide()
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        MessageBox.Show("Conratulations. Your sale has been complete.")
    End Sub

End Class
 
Last edited:
Back
Top Bottom