Click here to Skip to main content
15,905,967 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Option Explicit On      
Option Infer On
Option Strict Off


Public Class main

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click

        Static cars1 As Integer
        Static cars2 As Integer
        Static cars3 As Integer
        Static cars4 As Integer

        Dim txtID As String

        Dim txtNumberSold As Integer

        txtID = ID.Text

        txtNumberSold = convertintx(NumberSold.Text)



        If txtID.Substring(0, 1) = "F" Or txtID.Substring(0, 1) = "f" Then
            cars1 = cars1 + txtNumberSold
            Button1.Text = cars1
        End If

        If txtID.Substring(0, 1) = "P" Or txtID.Substring(0, 1) = "p" Then
            cars2 = cars2 + txtNumberSold
            Button2.Text = cars2
        End If


        If txtID.Substring(3, 1) = "1" Then
            cars3 = cars3 + txtNumberSold
            Button3.Text = cars3
        End If

        If txtID.Substring(3, 1) = "2" Then
            cars4 = cars4 + txtNumberSold
            Button4.Text = cars4
        End If



        ID.Text = ""
        NumberSold.Text = ""


    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Button1.Text = "0"
        Button2.Text = "0"
        Button3.Text = "0"
        Button4.Text = "0"
    End Sub

    Private Function convertintx(ByVal strx As String)

        If strx = "" Then
            strx = "0"
        End If


        Dim s As String
        s = strx
        Dim str(10) As String
        Dim number(10) As Integer
        Dim sum As Integer
        sum = 0


        str = Split(s, "+")
        Dim i As Integer
        For i = 0 To str.Length - 1
            number(i) = CInt(str(i))
            sum += number(i)


        Next


        Return sum
    End Function
Posted
Updated 6-May-11 4:02am
v2
Comments
Marc A. Brown 6-May-11 10:03am    
You really need to provide an explanation of what you're getting, what you're expecting, and any other information that might help, rather than just a code dump.

1 solution

Ocean,

It looks like you are over-complicating this problem, but you really haven't given much idea as to what this should do.

Please give a little more detail on the problem you're trying to solve, what your expected outputs for the given inputs would be, etc.

If I had to give you an answer at this point, I would suggest simplifying the approach. For instance, if you really only have 4 cases of input (f1, f2, p1, p2) why not just use four buttons?

Rather than creating static variables in your click handler, create private variables at the class level and make sure you initialize them correctly (they will live for the duration of your form). Better would be a class to represent your model, though that might be too complex to get you started.

Best of luck.

Cheers.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900