|
-
Jan 13th, 2021, 08:56 PM
#1
Thread Starter
Junior Member
[RESOLVED] How do I Automatically update a text box, using a NumbericUpDown Box
I'm trying to make my program so it auto updates the price in the text boxes for this "Pod" whenever I increase or decrease the value of the NumericUpDown box.
People.Value is the NumericUpDown Box
'Calculating and Displaying Prices for Liverpool Pod
Code:
If cboxPod.Text = "Liverpool" = True And People.Value >= 0 Then
TotalPrice.Text = "£" & (9 * People.Value)
VAT.Text = ("£" & TotalPrice.Text * 0.2)
Subtotal.Text = ("£" & TotalPrice.Text * 0.8)
End If
Does anyone have any help?
Last edited by dday9; Jan 13th, 2021 at 10:22 PM.
-
Jan 13th, 2021, 09:05 PM
#2
Re: How do I Automatically update a text box, using a NumbericUpDown Box
You have to call the code to update the textbox in the ValueChanged event handler of the NumericUpDown control.
That means the code to update the textbox should be put in its own method so that it can be called to update the textbox from wherever needed, such as when you change the location, or the number of people, or the number of days, etc...
Each of the places you can change one of the inputs, the changed event for that input can call the common method to update the textbox.
"Anyone can do any amount of work, provided it isn't the work he is supposed to be doing at that moment" Robert Benchley, 1930
-
Jan 13th, 2021, 09:31 PM
#3
Thread Starter
Junior Member
Re: How do I Automatically update a text box, using a NumbericUpDown Box
So there is no way I specifically can make it auto update as I will be having a ComboBox, A NumbericUpDown Value, and two DateTimePickers which will all effect the price?
-
Jan 13th, 2021, 10:34 PM
#4
Re: How do I Automatically update a text box, using a NumbericUpDown Box
There are a couple of notes:
- You have Option Strict turned off
- You can use ToString and pass the currency format
- You will need to leverage the ValueChanged event of the NumericUpDown
- You do not need the = True after you compare cboxPod's Text
- You may also want to handle the ComboBox's SelectedIndexChanged event too.
For more information on Option Strict and why it should be turned on, take a look at my website: https://www.vblessons.com/lessons.html#/1/2
For more information on formatting numbers, take a look at MSDN: https://docs.microsoft.com/en-us/dot...format-strings
For more information on ValueChanged, take a look at MSDN: https://docs.microsoft.com/en-us/dot...n.valuechanged
The reason why you do not need the = True is because you are already checking if the text equals a value is true. Quick side note, if the Minimum property of the NumericUpDown is 0 then you won't need to check if it is greater than or equal to 0.
The reason why you may want to handle the ComboBox's SelectedIndexChanged event is what if you start to handle multiple values in the ComboBox? Wouldn't you want the prices to update when you selected a new item?
Take a look at this code:
Code:
Private Sub ComboBoxOrNumericUpDown_Changed(sender As Object, e As EventArgs) Handles People.ValueChanged, cboxPod.SelectedIndexChanged
If cboxPod.Text = "Liverpool" Then
Dim totalPriceValue = 9 * People.Value
Dim vatValue = totalPriceValue * 0.2 'theft
Dim subTotalValue = totalPriceValue * 0.8
TotalPrice.Text = totalPriceValue.ToString("C")
VAT.Text = vatValue.ToString("C")
Subtotal.Text = subTotalValue.ToString("C")
End If
End Sub
-
Jan 13th, 2021, 10:37 PM
#5
Thread Starter
Junior Member
Re: How do I Automatically update a text box, using a NumbericUpDown Box
Thank you, I'll take a look.
-
Jan 13th, 2021, 11:19 PM
#6
Re: How do I Automatically update a text box, using a NumbericUpDown Box
 Originally Posted by dday9
There are a couple of notes:
- You have Option Strict turned off
- You can use ToString and pass the currency format
- You will need to leverage the ValueChanged event of the NumericUpDown
- You do not need the = True after you compare cboxPod's Text
- You may also want to handle the ComboBox's SelectedIndexChanged event too.
For more information on Option Strict and why it should be turned on, take a look at my website: https://www.vblessons.com/lessons.html#/1/2
For more information on formatting numbers, take a look at MSDN: https://docs.microsoft.com/en-us/dot...format-strings
For more information on ValueChanged, take a look at MSDN: https://docs.microsoft.com/en-us/dot...n.valuechanged
The reason why you do not need the = True is because you are already checking if the text equals a value is true. Quick side note, if the Minimum property of the NumericUpDown is 0 then you won't need to check if it is greater than or equal to 0.
The reason why you may want to handle the ComboBox's SelectedIndexChanged event is what if you start to handle multiple values in the ComboBox? Wouldn't you want the prices to update when you selected a new item?
Take a look at this code:
Code:
Private Sub ComboBoxOrNumericUpDown_Changed(sender As Object, e As EventArgs) Handles People.ValueChanged, cboxPod.SelectedIndexChanged
If cboxPod.Text = "Liverpool" Then
Dim totalPriceValue = 9 * People.Value
Dim vatValue = totalPriceValue * 0.2 'theft
Dim subTotalValue = totalPriceValue * 0.8
TotalPrice.Text = totalPriceValue.ToString("C")
VAT.Text = vatValue.ToString("C")
Subtotal.Text = subTotalValue.ToString("C")
End If
End Sub
 Originally Posted by THopwood
Thank you, I'll take a look.
You can combine that with what i told you in your other thread, about multiple event handlers
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jan 14th, 2021, 09:11 AM
#7
Re: How do I Automatically update a text box, using a NumbericUpDown Box
 Originally Posted by .paul.
You can combine that with what i told you in your other thread, about multiple event handlers
I don't know if you saw or not, but that is what I did in my example.
-
Jan 14th, 2021, 01:36 PM
#8
Re: How do I Automatically update a text box, using a NumbericUpDown Box
 Originally Posted by dday9
I don't know if you saw or not, but that is what I did in my example.
I saw what you did. The other thread was a slightly different question
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jan 14th, 2021, 01:59 PM
#9
Re: [RESOLVED] How do I Automatically update a text box, using a NumbericUpDown Box
Ah I see, I misunderstood.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|