Hello to all, i am new at this and i am just learning, i have a scholl project to make a program that needs to have discount base on how much they buy like 5 - 10% | 15 - 25% | 25 - 40% and ofc here is the code.

Imports Microsoft.VisualBasic
Public Class Form1


    Private Sub TextBox1_KeyPress(sender As Object, e As KeyPressEventArgs) Handles TextBox1.KeyPress
        If Asc(e.KeyChar) < 48 Or Asc(e.KeyChar) > 57 Then
            e.Handled = True
            MessageBox.Show("Въведете клиентски номер!")
        End If
    End Sub



    Private Sub TextBox2_KeyPress(sender As Object, e As KeyPressEventArgs) Handles TextBox2.KeyPress
        If Asc(e.KeyChar) < 65 Or Asc(e.KeyChar) > 90 _
            And Asc(e.KeyChar) < 97 Or Asc(e.KeyChar) > 122 Then
            e.Handled = True
            MessageBox.Show("Въведете Име!")
        End If
    End Sub

    Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged

    End Sub

    Private Sub TextBox2_TextChanged(sender As Object, e As EventArgs)

    End Sub


    Private Sub TextBox1_TextChanged_1(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
        If TextBox1.Text.Length >= 9 Then
            MessageBox.Show("10 Цифри")
        Else
            MessageBox.Show("Въведете 10 цифровия си номер!")
        End If
    End Sub

    Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
        If ComboBox1.Text = "Дървена" Then
            txtPrice.Text = "15лв кв/2"
        ElseIf ComboBox1.Text = "Алуминиева" Then
            txtPrice.Text = "25лв кв/2"
        ElseIf ComboBox1.Text = "PVC" Then
            txtPrice.Text = "35лв кв/2"
        End If
    End Sub

    Dim Pay As Integer
    Private Sub txtQty_TextChanged(sender As Object, e As EventArgs) Handles txtQty.TextChanged

        txtPay.Text = Val(txtQty.Text) * Val(txtPrice.Text) & "лв"
    End Sub

    Private Sub txtPay_TextChanged(sender As Object, e As EventArgs) Handles txtPay.TextChanged

    End Sub
End Class

These are the items :

            If ComboBox1.Text = "Дървена" Then
                txtPrice.Text = "15лв кв/2"
            ElseIf ComboBox1.Text = "Алуминиева" Then
                txtPrice.Text = "25лв кв/2"
            ElseIf ComboBox1.Text = "PVC" Then
                txtPrice.Text = "35лв кв/2"

As you can see they have different value, also i am having an issue when i start to type in textbox2 (that's only for Numbers) every time it says 10 symbols (as i define it "Въведете 10 цифровия си номер") i need that to happen not every time i enter, but when it has only 9 and the person is trying to enter only 9.

I will be very thankfull if some one cloud help me out :)

As per your codification textbox2 is not for numbers. It would be TextBox1.

i need that to happen not every time i enter, but when it has only 9 and the person is trying to enter only 9.

Is it for the text length? If it, the codes should be

If Trim(TextBox1.Text).Length > 9 Then
    MessageBox.Show("10 ?????")
Else If Trim(TextBox1.Text).Length = 9 Then
    MessageBox.Show("???????? 10 ???????? ?? ?????!")
End If

Hope it can help you.

Hi Shark,

It's TextBox1 not for too here is the code :

   Private Sub TextBox1_KeyPress(sender As Object, e As KeyPressEventArgs) Handles TextBox1.KeyPress
        If Asc(e.KeyChar) < 48 Or Asc(e.KeyChar) > 57 Then
            e.Handled = True
            MessageBox.Show("Въведете клиентски номер!")
        End If
    End Sub

That's for Numbers so the "client" can enter only Numbers in and few lines below is this code :

Private Sub TextBox1_TextChanged_1(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
        If TextBox1.Text.Length >= 9 Then
            MessageBox.Show("10 Цифри")
        Else
            MessageBox.Show("Въведете 10 цифровия си номер!")
        End If
    End Sub

Hello! ZFPuhi
You declare two TextChanged Events for TextBox1. One at line no 22 TextBox1_TextChanged and second one at line no 31TextBox1_TextChanged_1. I assume that you have confusion about them. They are same and for only TextBox1. Remove anyone.

You made a keypress event to restrict keypressing.
But in TextChanged event, you want to generate a message, if the client enter greater or equal to 9 digits. The codes should be

Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
    If TextBox1.Text.Length > 9 Then
        MessageBox.Show("10 ?????")
    Else If TextBox1.Text.Length = 9 Then
        MessageBox.Show("???????? 10 ???????? ?? ?????!")
    End If
End Sub

Hope it can help you.

Hello Shark,

Sorry dose not help me, i can upload my project so you can get a look at it and guide me if you want or help me. Also skype or smoething that is more faster than posts will be great too.

O.K. lets deal with one issue at a time. First use the keyup ebent to check for invalid entry and also for the enter key and the back_key to allow editing if a wrong number has been enterd.

 Private Sub TextBox1_KeyUp(sender As Object, e As KeyEventArgs) Handles TextBox1.KeyUp
        If Not ((e.KeyValue >= 48 AndAlso e.KeyValue <= 57) OrElse e.KeyCode = Keys.Enter OrElse e.KeyCode = Keys.Back) Then
            MessageBox.Show("That's not numeric!")
            TextBox1.Text = TextBox1.Text.Substring(0, TextBox1.Text.Length - 1)
            TextBox1.Select(TextBox1.Text.Length + 1, 1)
        End If
    End Sub

If a wrong input was made wedisplay the Msg, remove the wrong character and move the cursoe back to the end of the string for new input.

I guess i am doing something really wrong because it stil fails.
Here is a picture of the project Picture And here is a link to the project it self Project
On the picture i have explained all the things that the fileds Mean and do.
Basically First is the Name (where people need to press Space when i do it says Enter name so something is messy) When i try Entering (key press) on Numbers i always get the message. Please check and advice.

Guess no one can help out by checking the school project, can some one at least tell me how i can make a submit button where it will collect all the data and show it in a window ?

P.S.
Made the Number thing work, now how to make it when a person Goes to other area to alert him if he did not enter 10 Number code or when he hits the Submit button (which i don't know how to make).
Also when about the name When a person tries to add name (textbox2) and like hits Space (for space) it automaticaly pops up please enter name and dose not make the Space, how to fix that?

Edited 1 Year Ago by ZFPuhi: Number & Name.

Well, I suppose people don't like to download whole projects for security reasons. Also for the benefit of the thread it is better to display the code so every one interested can help out. O.K. so I downloaded your code. You are still using the keypress event. This handles only characters if there is one -so don't catch the Return or other keys that are not characters. That is why I suggested to use the keyup event in my previous post to handle also keys that don't have a character representation. You also should put Option Strict On which wouldn't allow you to do this:

 txtPay.Text = Val(txtQty.Text) * Val(txtPrice.Text) & "лв"

here you mix up string and numbers and hope the compiler will sort it out.
On line 39 you dim pay outside of a sub.
And for your textbox2 its the same as for your textbox1 - don't use the keypress event.

This was the old thing, here is the new code.
I need to make the button2_click show all the data and sort the problems with the Name (can't space and it needs to have at least 10, and the numbers it needs to have 10 less to give him error when he tries to go to other box or to click submit).

Imports Microsoft.VisualBasic
Public Class Form1


    Private Sub TextBox1_KeyUp(sender As Object, e As KeyEventArgs) Handles TextBox1.KeyUp
        If Not ((e.KeyValue >= 48 AndAlso e.KeyValue <= 57) OrElse e.KeyCode = Keys.Enter OrElse e.KeyCode = Keys.Back) Then
            MessageBox.Show("Въведете клиентски номер!")
            TextBox1.Text = TextBox1.Text.Substring(0, TextBox1.Text.Length - 1)
            TextBox1.Select(TextBox1.Text.Length + 1, 1)
        End If
    End Sub



    Private Sub TextBox2_KeyPress(sender As Object, e As KeyPressEventArgs) Handles TextBox2.KeyPress
        If Asc(e.KeyChar) < 65 Or Asc(e.KeyChar) > 90 _
            And Asc(e.KeyChar) < 97 Or Asc(e.KeyChar) > 122 Then
            e.Handled = True
            MessageBox.Show("Въведете Име!")
        End If
    End Sub


    Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
        If ComboBox1.Text = "Дървена" Then
            txtPrice.Text = "15лв кв/2"
        ElseIf ComboBox1.Text = "Алуминиева" Then
            txtPrice.Text = "25лв кв/2"
        ElseIf ComboBox1.Text = "PVC" Then
            txtPrice.Text = "35лв кв/2"
        End If
    End Sub

    Dim Pay As Integer
    Private Sub txtQty_TextChanged(sender As Object, e As EventArgs) Handles txtQty.TextChanged

        txtPay.Text = Val(txtQty.Text) * Val(txtPrice.Text) & "лв"
    End Sub

    Private Sub txtPay_TextChanged(sender As Object, e As EventArgs) Handles txtPay.TextChanged

    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        TextBox1.Text = ""
        RichTextBox1.Text = ""
        ComboBox1.Text = ""
        txtPay.Text = ""
        txtQty.Text = ""
        txtPrice.Text = ""


    End Sub

    Private Sub RichTextBox1_KeyPress(sender As Object, e As KeyPressEventArgs) Handles RichTextBox1.KeyPress
        If Asc(e.KeyChar) < 65 Or Asc(e.KeyChar) > 90 _
    And Asc(e.KeyChar) < 97 Or Asc(e.KeyChar) > 122 Then
            e.Handled = True
            MessageBox.Show("Въведете Име!")
        End If
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click

    End Sub
End Class

Also change your textbox2 eventhandler to:

Private Sub TextBox2_KeyUp(sender As Object, e As KeyEventArgs) Handles TextBox2.KeyUp
        If Not (e.KeyValue > 64 Or e.KeyValue < 91 Or e.KeyValue > 96 Or e.KeyValue < 123 Or e.KeyValue = Keys.Space) Then
            MessageBox.Show("???????? ???!")
        End If
    End Sub

With your text.length in textbox1 I don'understand what you want to do. Anyway, for the purpose of validation you can use:

 Private Sub TextBox1_Validating(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles TextBox1.Validating
        If TextBox1.Text.Length >= 9 Then
            MessageBox.Show("10 ?????")
        Else
            MessageBox.Show("???????? 10 ???????? ?? ?????!")
        End If
        e.Cancel = True
    End Sub

I use your origanal code but put it in TextBox1_Validating. This way you don't pop each time the msg.

Hello Minimalist,

The first one is good, the second one with the validation FAILS, when i enter 10 number like 1234567890 when i try chaning the box it shows the first Message and i can't go to other boxses or do anything.
Here is what this thing has to do :
TextBox1 : To enter client number that needs to be 10 long example : 1234567890
TextBox2 : To enter Client name (it needs to have space).
txtQty / txtPay : when entered in txtQty 5~9 to have 5%, 10~14 to have 10% and 15~99999 to have 15% Discount,the price to be shown in txtPay
Button 2 : When clicked to show Result with all the Date entered in TextBox1 + TextBox2 + txtQty + txtPay and to say what kind of a Discount there is (as %).

Here is the Code again please follow this code (it's altered and it's the final one) i need to give this project in less than 6 days.

Imports Microsoft.VisualBasic
Public Class Form1


    Private Sub TextBox1_KeyUp(sender As Object, e As KeyEventArgs) Handles TextBox1.KeyUp
        If Not ((e.KeyValue >= 48 AndAlso e.KeyValue <= 57) OrElse e.KeyCode = Keys.Enter OrElse e.KeyCode = Keys.Back) Then
            MessageBox.Show("Въведете клиентски номер!")
            TextBox1.Text = TextBox1.Text.Substring(0, TextBox1.Text.Length - 1)
            TextBox1.Select(TextBox1.Text.Length + 1, 1)
        End If
    End Sub



    Private Sub TextBox2_KeyUp(sender As Object, e As KeyEventArgs) Handles TextBox2.KeyUp
        If Not (e.KeyValue > 64 Or e.KeyValue < 91 Or e.KeyValue > 96 Or e.KeyValue < 123 Or e.KeyValue = Keys.Space) Then
                MessageBox.Show("Въведете Име!")
            End If
    End Sub


    Private Sub TextBox1_Validating(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles TextBox1.Validating
        If TextBox1.Text.Length >= 9 Then
            MessageBox.Show("10 Цифри")
        Else
            MessageBox.Show("Въведете 10 цифровия си номер!")
        End If
        e.Cancel = True
    End Sub
    Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
        If ComboBox1.Text = "Дървена" Then
            txtPrice.Text = "15лв кв/2"
        ElseIf ComboBox1.Text = "Алуминиева" Then
            txtPrice.Text = "25лв кв/2"
        ElseIf ComboBox1.Text = "PVC" Then
            txtPrice.Text = "35лв кв/2"
        End If
    End Sub

    Dim Pay As Integer
    Private Sub txtQty_TextChanged(sender As Object, e As EventArgs) Handles txtQty.TextChanged

        txtPay.Text = Val(txtQty.Text) * Val(txtPrice.Text) & "лв"
    End Sub

    Private Sub txtPay_TextChanged(sender As Object, e As EventArgs) Handles txtPay.TextChanged

    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        TextBox1.Text = ""
        RichTextBox1.Text = ""
        ComboBox1.Text = ""
        txtPay.Text = ""
        txtQty.Text = ""
        txtPrice.Text = ""


    End Sub

    Private Sub RichTextBox1_KeyPress(sender As Object, e As KeyPressEventArgs) Handles RichTextBox1.KeyPress
        If Asc(e.KeyChar) < 65 Or Asc(e.KeyChar) > 90 _
    And Asc(e.KeyChar) < 97 Or Asc(e.KeyChar) > 122 Then
            e.Handled = True
            MessageBox.Show("Въведете Име!")
        End If
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click

    End Sub
End Class

P.S.

Also if there's a way when clicked the button and the result is shown to Alter the box (like desing) that's showing the result or if i can Show the result in the richbox (but the box to be not editable).

Edited 1 Year Ago by ZFPuhi

O.K I changed the code for the validating a bit to:

Private Sub TextBox1_Validating(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles TextBox1.Validating
        If TextBox1.Text.Length < 10 Then
            MessageBox.Show("10 ?????")
            e.Cancel = True
        ElseIf TextBox1.Text.Length > 10 Then
            MessageBox.Show("???????? 10 ???????? ?? ?????!")
            e.Cancel = True
        End If
    End Sub

Maybe this will work for you.
And for textbox2 I have gone back to the keypress event:

Private Sub TextBox2_KeyPress(sender As Object, e As KeyPressEventArgs) Handles TextBox2.KeyPress
        If Not ((Asc(e.KeyChar) = 8 OrElse e.KeyChar = " ") OrElse (e.KeyChar >= "A" AndAlso e.KeyChar <= "Z") OrElse (e.KeyChar >= "a" AndAlso e.KeyChar <= "z")) Then
            e.Handled = True
            CType(sender, TextBox).Clear()
            MessageBox.Show("???????? ???!")
        End If
    End Sub

See if this is what you want. Once you got this working as you need we check on the other problems.

Edited 1 Year Ago by Minimalist

Great Perfect, it works now with no issuess, now can we make the Submit button do something i tried searching videos and stuff but cloud not find how and where or what ?...

O.K. it would be better you mark this thread as solved and start a new thread with the new questions. This way this thread doesn't get to long and makes it easier for some one searching later with keywords. You also may mark up code snippets that helped to solve your problems. Thanks

HI Minimalist, actually this topic was for Discount and the issue is still at hand, i don't know how to make the Discount happen when you add the ammount (txtQty).

Yes, i want to display the discount Price if there's one, and when submited to show the 5% 10% or 15% Disocunt( i mean when submited to show that there is 5% Discount or more).

** I have made the submit button it's working and showing all, all i need now is the Discount which this Topic was originally for.
When some one enters from 5 to 9 (5, 6 , 7 , 8, 9) as a Quality to automatically discount 5% same goes for 10<15 and 15<?.

Well in line 43 you have already a good start. You can use this to work out the discount. What have you tried?
Your formula is something like:
endprice=Val(txtQty.Text) * (price-(price*0.05)) for the 5%

Edited 1 Year Ago by Minimalist

Minilist, the problem is i don't know from where to start or even how to format it ... if it was this simple i would have tried but it's hard when you FAILED at math (like i did :D ). Looking for adviec or help.

O.K. try this then:

Private Sub txtQty_TextChanged(sender As Object, e As EventArgs) Handles txtQty.TextChanged
        If Val(txtQty.Text) < 5 Then
            txtPay.Text = Val(txtQty.Text) * Val(txtPrice.Text) & "лв"
        End If
        If 4 < Val(txtQty.Text) < 10 Then
            txtPay.Text = Val(txtQty.Text) * Val(Val(txtPrice.Text) - (Val(txtPrice.Text) * 0.05)) & "лв"
        End If
        If 9 < Val(txtQty.Text) < 15 Then
            txtPay.Text = Val(txtQty.Text) * Val(Val(txtPrice.Text) - (Val(txtPrice.Text) * 0.1)) & "лв"
        End If
        If 15 < Val(txtQty.Text) < 99999 Then
            txtPay.Text = Val(txtQty.Text) * Val(Val(txtPrice.Text) - (Val(txtPrice.Text) * 0.4)) & "лв"
        End If
    End Sub

Great this works now, but is there a way to Say which discount is applyed.

I mean to include to show what % Discount is in use after hitting submit here is the full code.

Imports Microsoft.VisualBasic
Public Class Form1


    Private Sub TextBox1_KeyUp(sender As Object, e As KeyEventArgs) Handles TextBox1.KeyUp
        If Not ((e.KeyValue >= 48 AndAlso e.KeyValue <= 57) OrElse e.KeyCode = Keys.Enter OrElse e.KeyCode = Keys.Back) Then
            MessageBox.Show("Въведете клиентски номер!")
            TextBox1.Text = TextBox1.Text.Substring(0, TextBox1.Text.Length - 1)
            TextBox1.Select(TextBox1.Text.Length + 1, 1)
        End If
    End Sub


    Private Sub TextBox2_KeyPress(sender As Object, e As KeyPressEventArgs) Handles TextBox2.KeyPress
        If Not ((Asc(e.KeyChar) = 8 OrElse e.KeyChar = " ") OrElse (e.KeyChar >= "A" AndAlso e.KeyChar <= "Z") OrElse (e.KeyChar >= "a" AndAlso e.KeyChar <= "z")) Then
            e.Handled = True
            CType(sender, TextBox).Clear()
            MessageBox.Show("Въведете Име!")
        End If
    End Sub

    Private Sub TextBox1_Validating(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles TextBox1.Validating
        If TextBox1.Text.Length < 10 Then
            MessageBox.Show("10 Цифри")
            e.Cancel = True
        ElseIf TextBox1.Text.Length > 10 Then
            MessageBox.Show("Въведете 10 цифровия си номер!")
            e.Cancel = True
        End If
    End Sub

    Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
        If ComboBox1.Text = "Дървена" Then
            txtPrice.Text = "15лв кв/2"
        ElseIf ComboBox1.Text = "Алуминиева" Then
            txtPrice.Text = "25лв кв/2"
        ElseIf ComboBox1.Text = "PVC" Then
            txtPrice.Text = "35лв кв/2"
        End If
    End Sub

    Dim Pay As Integer
    Private Sub txtQty_TextChanged(sender As Object, e As EventArgs) Handles txtQty.TextChanged
        If Val(txtQty.Text) < 5 Then
            txtPay.Text = Val(txtQty.Text) * Val(txtPrice.Text) & "лв"
        End If
        If 4 < Val(txtQty.Text) < 10 Then
            txtPay.Text = Val(txtQty.Text) * Val(Val(txtPrice.Text) - (Val(txtPrice.Text) * 0.05)) & "лв"
        End If
        If 9 < Val(txtQty.Text) < 15 Then
            txtPay.Text = Val(txtQty.Text) * Val(Val(txtPrice.Text) - (Val(txtPrice.Text) * 0.1)) & "лв"
        End If
        If 15 < Val(txtQty.Text) < 99999 Then
            txtPay.Text = Val(txtQty.Text) * Val(Val(txtPrice.Text) - (Val(txtPrice.Text) * 0.4)) & "лв"
        End If
    End Sub

    Private Sub txtPay_TextChanged(sender As Object, e As EventArgs) Handles txtPay.TextChanged

    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        TextBox1.Text = ""
        TextBox2.Text = ""
        RichTextBox1.Text = ""
        ComboBox1.Text = ""
        txtPay.Text = ""
        txtQty.Text = ""
        txtPrice.Text = ""


    End Sub

    Private Sub RichTextBox1_KeyPress(sender As Object, e As KeyPressEventArgs) Handles RichTextBox1.KeyPress
        If Asc(e.KeyChar) < 65 Or Asc(e.KeyChar) > 90 _
    And Asc(e.KeyChar) < 97 Or Asc(e.KeyChar) > 122 Then
            e.Handled = True
            MessageBox.Show("Въведете Име!")
        End If
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        MsgBox("Име: " & TextBox2.Text & vbCrLf & "Клиентски Номер: " & TextBox1.Text & vbCrLf & "Модел: " & ComboBox1.Text & " Дограма" & vbCrLf & "Количество: " & txtQty.Text & vbCrLf & "Крайна Цена: " & txtPay.Text, MsgBoxStyle.Information)
    End Sub
End Class

With the percentages you need to pay attention because from your first post it wasn't clear what percentages you really want. I think you know where to change these likeL 0.05 = 5%, 0.1 =10%, 0.15=15% and 0.4 = 40%. I just put these according to your first post. For the pecentage display just make add something like & " 15%" to whee you want to displaa it.

Hello Minimalist,

I tried to add the Discount to be displayed but with no luck, i only need that Function to be displayed when clicked submit is that possible ?

P.S. I did change the 0.4 to 0.15 the other works normally.

P.S.2
For some reason it was working perfectly the discount now it started to give a Discount for all 1~5 and it needs to give only from 5 ~ 10 / 10 ~ 15 and 15 ~ infinity. Please check the code

Imports Microsoft.VisualBasic
Public Class Form1


    Private Sub TextBox1_KeyUp(sender As Object, e As KeyEventArgs) Handles TextBox1.KeyUp
        If Not ((e.KeyValue >= 48 AndAlso e.KeyValue <= 57) OrElse e.KeyCode = Keys.Enter OrElse e.KeyCode = Keys.Back) Then
            MessageBox.Show("Въведете клиентски номер!")
            TextBox1.Text = TextBox1.Text.Substring(0, TextBox1.Text.Length - 1)
            TextBox1.Select(TextBox1.Text.Length + 1, 1)
        End If
    End Sub


    Private Sub TextBox2_KeyPress(sender As Object, e As KeyPressEventArgs) Handles TextBox2.KeyPress
        If Not ((Asc(e.KeyChar) = 8 OrElse e.KeyChar = " ") OrElse (e.KeyChar >= "A" AndAlso e.KeyChar <= "Z") OrElse (e.KeyChar >= "a" AndAlso e.KeyChar <= "z")) Then
            e.Handled = True
            CType(sender, TextBox).Clear()
            MessageBox.Show("Въведете Име!")
        End If
    End Sub

    Private Sub TextBox1_Validating(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles TextBox1.Validating
        If TextBox1.Text.Length < 10 Then
            MessageBox.Show("10 Цифри")
            e.Cancel = True
        ElseIf TextBox1.Text.Length > 10 Then
            MessageBox.Show("Въведете 10 цифровия си номер!")
            e.Cancel = True
        End If
    End Sub

    Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
        If ComboBox1.Text = "Дървена" Then
            txtPrice.Text = "15лв кв/2"
        ElseIf ComboBox1.Text = "Алуминиева" Then
            txtPrice.Text = "25лв кв/2"
        ElseIf ComboBox1.Text = "PVC" Then
            txtPrice.Text = "35лв кв/2"
        End If
    End Sub

    Dim Pay As Integer
    Private Sub txtQty_TextChanged(sender As Object, e As EventArgs) Handles txtQty.TextChanged
        If Val(txtQty.Text) < 5 Then
            txtPay.Text = Val(txtQty.Text) * Val(txtPrice.Text) & "лв"
        End If
        If 4 < Val(txtQty.Text) < 10 Then
            txtPay.Text = Val(txtQty.Text) * Val(Val(txtPrice.Text) - (Val(txtPrice.Text) * 0.05)) & "лв"
        End If
        If 9 < Val(txtQty.Text) < 15 Then
            txtPay.Text = Val(txtQty.Text) * Val(Val(txtPrice.Text) - (Val(txtPrice.Text) * 0.1)) & "лв"
        End If
        If 15 < Val(txtQty.Text) < 99999 Then
            txtPay.Text = Val(txtQty.Text) * Val(Val(txtPrice.Text) - (Val(txtPrice.Text) * 0.15)) & "лв"
        End If
    End Sub

    Private Sub txtPay_TextChanged(sender As Object, e As EventArgs) Handles txtPay.TextChanged

    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        TextBox1.Text = ""
        TextBox2.Text = ""
        ComboBox1.Text = ""
        txtPay.Text = ""
        txtQty.Text = ""
        txtPrice.Text = ""


    End Sub


    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        MsgBox("Име: " & TextBox2.Text & vbCrLf & "Клиентски Номер: " & TextBox1.Text & vbCrLf & "Модел Дограма: " & ComboBox1.Text & vbCrLf & "Количество: " & txtQty.Text & vbCrLf & "Крайна Цена: " & txtPay.Text, MsgBoxStyle.Information)
    End Sub
End Class

Edited 1 Year Ago by ZFPuhi: Issue with Discount.

O.K almost there. To assign the discount you need a variable declared at formlevel - so you can set it in a sub and reuse it in your msgbox.

Public Class Form1
    Dim Perc As String = ""

Then we go to your txtQty_TextChanged sub. Here we need to change the code to:

 Private Sub txtQty_TextChanged(sender As Object, e As EventArgs) Handles txtQty.TextChanged
        Dim num As Integer = 0
        If txtQty.Text <> "" Then
            num = CInt(txtQty.Text)
            Debug.Print(num.ToString)
        End If
        If num < 5 Then
            txtPay.Text = num * Val(txtPrice.Text) & "лв"
            Perc = " 0%"
            Debug.Print("0%  ")
        End If
        If 5 <= num And num <= 9 Then
            txtPay.Text = num * Val(Val(txtPrice.Text) - (Val(txtPrice.Text) * 0.05)) & "лв"
            Perc = " 5%"
            Debug.Print("5%")
        End If
        If 10 <= num And num <= 14 Then
            txtPay.Text = num * Val(Val(txtPrice.Text) - (Val(txtPrice.Text) * 0.1)) & "лв"
            Perc = " 10%"
            Debug.Print("10%")
        End If
        If 14 <= num And num <= 99999 Then
            txtPay.Text = num * Val(Val(txtPrice.Text) - (Val(txtPrice.Text) * 0.15)) & "лв"
            Perc = " 15%"
            Debug.Print("15%  ")
        End If
    End Sub

With the debug.print statements you can check at any time values by printing these to the immidiate plane. So you can check that you get the correct values. We also assign Perc to the valid discount given.
Last we assign perc to a value in the msgbox:

 Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        MsgBox("???: " & TextBox2.Text & vbCrLf & "????????? ?????: " & TextBox1.Text & vbCrLf & "????? ???????: " & ComboBox1.Text & vbCrLf & "??????????: " & txtQty.Text & vbCrLf & "?????? ????: " & txtPay.Text & "  " & Perc, MsgBoxStyle.Information)
    End Sub

In this case a put it here: txtPay.Text & " " & Perc
Good luck with your assignment.

Now i think everything works fine here is the FINAL version of the code for the Topic, thanks Minimalistixs ..

Imports Microsoft.VisualBasic
Public Class Form1
    Dim Perc As String = ""

    Private Sub TextBox1_KeyUp(sender As Object, e As KeyEventArgs) Handles TextBox1.KeyUp
        If Not ((e.KeyValue >= 48 AndAlso e.KeyValue <= 57) OrElse e.KeyCode = Keys.Enter OrElse e.KeyCode = Keys.Back) Then
            MessageBox.Show("Въведете клиентски номер!")
            TextBox1.Text = TextBox1.Text.Substring(0, TextBox1.Text.Length - 1)
            TextBox1.Select(TextBox1.Text.Length + 1, 1)
        End If
    End Sub


    Private Sub TextBox2_KeyPress(sender As Object, e As KeyPressEventArgs) Handles TextBox2.KeyPress
        If Not ((Asc(e.KeyChar) = 8 OrElse e.KeyChar = " ") OrElse (e.KeyChar >= "A" AndAlso e.KeyChar <= "Z") OrElse (e.KeyChar >= "a" AndAlso e.KeyChar <= "z")) Then
            e.Handled = True
            CType(sender, TextBox).Clear()
            MessageBox.Show("Въведете Име!")
        End If
    End Sub

    Private Sub TextBox1_Validating(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles TextBox1.Validating
        If TextBox1.Text.Length < 10 Then
            MessageBox.Show("10 Цифри")
            e.Cancel = True
        ElseIf TextBox1.Text.Length > 10 Then
            MessageBox.Show("Въведете 10 цифровия си номер!")
            e.Cancel = True
        End If
    End Sub

    Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
        If ComboBox1.Text = "Дървена" Then
            txtPrice.Text = "15лв кв/2"
        ElseIf ComboBox1.Text = "Алуминиева" Then
            txtPrice.Text = "25лв кв/2"
        ElseIf ComboBox1.Text = "PVC" Then
            txtPrice.Text = "35лв кв/2"
        End If
    End Sub

    Dim Pay As Integer
    Private Sub txtQty_TextChanged(sender As Object, e As EventArgs) Handles txtQty.TextChanged
        Dim num As Integer = 0
        If txtQty.Text <> "" Then
            num = CInt(txtQty.Text)
            Debug.Print(num.ToString)
        End If
        If num < 5 Then
            txtPay.Text = num * Val(txtPrice.Text) & "лв"
            Perc = " 0%"
            Debug.Print("0%  ")
        End If
        If 5 <= num And num <= 9 Then
            txtPay.Text = num * Val(Val(txtPrice.Text) - (Val(txtPrice.Text) * 0.05)) & "лв"
            Perc = " 5%"
            Debug.Print("5%")
        End If
        If 10 <= num And num <= 14 Then
            txtPay.Text = num * Val(Val(txtPrice.Text) - (Val(txtPrice.Text) * 0.1)) & "лв"
            Perc = " 10%"
            Debug.Print("10%")
        End If
        If 15 <= num And num <= 99999 Then
            txtPay.Text = num * Val(Val(txtPrice.Text) - (Val(txtPrice.Text) * 0.15)) & "лв"
            Perc = " 15%"
            Debug.Print("15%  ")
        End If
    End Sub

    Private Sub txtPay_TextChanged(sender As Object, e As EventArgs) Handles txtPay.TextChanged

    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        TextBox1.Text = ""
        TextBox2.Text = ""
        ComboBox1.Text = ""
        txtPay.Text = ""
        txtQty.Text = ""
        txtPrice.Text = ""


    End Sub


    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        MsgBox("Име: " & TextBox2.Text & vbCrLf & "Клиентски Номер: " & TextBox1.Text & vbCrLf & "Модел Дограма: " & ComboBox1.Text & vbCrLf & "Количество: " & txtQty.Text & vbCrLf & "Крайна Цена: " & txtPay.Text & vbCrLf & "Вашата отстъпка е" & Perc, MsgBoxStyle.Information)
    End Sub
End Class

I can see one problem with that. If txtQty.Text is not numeric then you will get an error on

num = CInt(txtQty.Text)

Once you have determined that txtQty has a numeric value and you have converted it to num (and the same for txtPrice.Text to an Integer in price) you can do

    Select Case num
        Case Is < 5
            txtPay.Text = num * price & "??"
            Perc = " 0%"
            Debug.Print("0%  ")
        Case Is <= 9
            txtPay.Text = num * price - price * 0.05)) & "??"
            Perc = " 5%"
            Debug.Print("5%")
        Case Is <= 14
            txtPay.Text = num * price - price * 0.1)) & "??"
            Perc = " 10%"
            Debug.Print("10%")
        Case Else
            txtPay.Text = num * price - price * 0.15)) & "??"
            Perc = " 15%"
            Debug.Print("15%  ")
    End Select

I would also assume that you would get the discount on every item, in which case the calculatiion should be

num * (price - price * 0.05)

A cleaner version would be

Select Case num
    Case Is < 5
        discount = 0
    Case Is <= 9
        discount = 5
    Case Is <= 14
        discount = 10
    Case Else
        discount = 15
End Select

txtPay.Text = (100 - discount) * 0.01 * num * price
Perc = discount & "%"

You want to remove duplication of code. It makes the code easier to follow and reduces the chances of errors due to typos.

Edited 1 Year Ago by Reverend Jim

This question has already been answered. Start a new discussion instead.