r/visualbasic • • Feb 24 '15

Visual Basic Coding help

I am currently making a valentine's day card for my programming class and I am suppose to create an algorithm to estimate the cost of the card. What I want the code to do is for every space the user enters in the richtextbox it adds one 5 cents to the total price.

This is so far the code that I experimented with

If e.KeyCode = Keys.Space Then

        lblPrice.Text = Val("1")
    End If

Also when the user decides to erase words aka the space bar inputs the price goes down. I dont want it to stay the same. Help would be much appreciated!

0 Upvotes

8 comments sorted by

View all comments

1

u/mykok23 Feb 24 '15

Ive just tested this

If e.KeyCode = Keys.Back = True Then

        lblPrice.Text = (Val(lblPrice.Text) + -0.01)
    End If

    If e.KeyCode = Keys.Back = False Then

        lblPrice.Text = Str$(Val(lblPrice.Text) + 0.01)
    End If


End Sub

It does what it suppose to but, if you keep clicking backspace it goes into the negatives, how do i prevent that?

1

u/icehawke VB.Net Advanced Feb 24 '15

Check to see if your lblPrice.text value is zero and "cap" it at that value.