Lock button when user put a specific value on one of the choices - vb.net

I want to lock the other buttons when the user input an amount to one of the four rooms. Instead if I can't lock, please help me do the otherway whereas when the user click the other rooms, the other rooms will freeze to 0 value.
Public Class Formrooms
Dim birthday As Double
Dim party As Double
Dim vip As Double
Dim deluxe As Double
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
lblparty.BackColor = ColorTranslator.FromHtml("#100F0E")
lblbday.BackColor = ColorTranslator.FromHtml("#100F0E")
lblvip.BackColor = ColorTranslator.FromHtml("#100F0E")
lbldeluxe.BackColor = ColorTranslator.FromHtml("#100F0E")
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs)
Me.Hide()
Formsnacks.Show()
End Sub
Private Sub btnbirthday_Click(sender As Object, e As EventArgs)
Me.Hide()
Formsnacks.Show()
End Sub
Private Sub btnvip_Click(sender As Object, e As EventArgs)
Me.Hide()
Formsnacks.Show()
End Sub
Private Sub btndeluxe_Click(sender As Object, e As EventArgs)
Me.Hide()
Formsnacks.Show()
End Sub
Private Sub btndecp_Click(sender As Object, e As EventArgs) Handles btndecp.Click
lblparty.Text -= 1
If lblparty.Text <= 0 Then
lblparty.Text = 0
End If
End Sub
Private Sub btndecb_Click(sender As Object, e As EventArgs) Handles btndecb.Click
lblbday.Text -= 1
If lblbday.Text <= 0 Then
lblbday.Text = 0
End If
End Sub
Private Sub btndecv_Click(sender As Object, e As EventArgs) Handles btndecv.Click
lblvip.Text -= 1
If lblvip.Text <= 0 Then
lblvip.Text = 0
End If
End Sub
Private Sub btndecd_Click(sender As Object, e As EventArgs) Handles btndecd.Click
lbldeluxe.Text -= 1
If lbldeluxe.Text <= 0 Then
lbldeluxe.Text = 0
End If
End Sub
Private Sub btnincp_Click(sender As Object, e As EventArgs) Handles btnincp.Click
lblparty.Text += 1
If lblparty.Text >= 3 Then
lblparty.Text = 3
End If
End Sub
Private Sub btnincb_Click(sender As Object, e As EventArgs) Handles btnincb.Click
lblbday.Text += 1
If lblbday.Text >= 3 Then
lblbday.Text = 3
End If
End Sub
Private Sub btnincv_Click(sender As Object, e As EventArgs) Handles btnincv.Click
lblvip.Text += 1
If lblvip.Text >= 3 Then
lblvip.Text = 3
End If
End Sub
Private Sub btnincd_Click(sender As Object, e As EventArgs) Handles btnincd.Click
lbldeluxe.Text += 1
If lbldeluxe.Text >= 3 Then
lbldeluxe.Text = 3
End If
End Sub
Private Sub Number_only(sender As Object, e As KeyPressEventArgs)
If Asc(e.KeyChar) <> 8 Then
If Asc(e.KeyChar) < 48 Or Asc(e.KeyChar) > 57 Then
e.Handled = True
End If
End If
End Sub
Private Sub Button1_Click_1(sender As Object, e As EventArgs) Handles nextr.Click
Dim dialog As DialogResult
If lblbday.Text = 0 And lbldeluxe.Text = 0 And lblparty.Text = 0 And lblvip.Text = 0 Then
dialog = MessageBox.Show("You must choose the rooms", "Error", MessageBoxButtons.OK)
ElseIf lblbday.Text > 0 And lblparty.Text >= 1 And lblvip.Text = 1 And lbldeluxe.Text > 1 Then
dialog = MessageBox.Show("You can only choose 1 room", "Error", MessageBoxButtons.OK)
Else
Me.Hide()
formsnacks.Show()
End If
End Sub
Private Sub btnbackr_Click(sender As Object, e As EventArgs) Handles btnbackr.Click
Me.Hide()
Formtakeorders.Show()
End Sub
Private Sub lblparty_Click(sender As Object, e As EventArgs) Handles lblparty.Click
End Sub
End Class

If I've managed to pick out the actual meaning from your poor explanation, this type of thing will do the job:
Private Sub Buttons_Click(sender As Object, e As EventArgs) Handles Button4.Click,
Button3.Click,
Button2.Click,
Button1.Click
For Each btn In Controls.OfType(Of Button)()
btn.Enabled = btn Is sender
Next
End Sub
One event handler for all Buttons and then set the Enabled property of each Button. sender is the object that raised the event, i.e. the Button that was clicked. All but that Button are not the sender so all but that Button will have their Enabled property set to False.
Note that this assumes that all those Buttons are in the same container - the form in this specific case - and that container contains no other Buttons. If that's not currently the case, you can either hard-code the list of Buttons to loop over or move just those Buttons into a new container, e.g. a Panel.

I think you should get rid of the four buttons (party, birthday, vip, deluxe) and just have ONE "next" button. Then just reset the other hour selections to zero whenever you increase one of the room values:
Public Class Formrooms
Dim party As Integer
Dim birthday As Integer
Dim vip As Integer
Dim deluxe As Integer
Private Sub btndecp_Click(sender As Object, e As EventArgs) Handles btndecp.Click
If party > 0 Then
party = party - 1
lblparty.Text = party
End If
End Sub
Private Sub btndecb_Click(sender As Object, e As EventArgs) Handles btndecb.Click
If birthday > 0 Then
birthday = birthday - 1
lblbday.Text = birthday
End If
End Sub
Private Sub btndecv_Click(sender As Object, e As EventArgs) Handles btndecv.Click
If vip > 0 Then
vip = vip - 1
lblvip.Text = vip
End If
End Sub
Private Sub btndecd_Click(sender As Object, e As EventArgs) Handles btndecd.Click
If deluxe > 0 Then
deluxe = deluxe - 1
lbldeluxe.Text = deluxe
End If
End Sub
Private Sub btnincp_Click(sender As Object, e As EventArgs) Handles btnincp.Click
party = Math.Min(party + 1, 3)
lblparty.Text = party
birthday = 0
vip = 0
deluxe = 0
lblbirthday.Text = birthday
lblvip.Text = vip
lbldeluxe.Text deluxe
End Sub
Private Sub btnincb_Click(sender As Object, e As EventArgs) Handles btnincb.Click
birthday = Math.Min(birthday + 1, 3)
lblbday.Text = birthday
party = 0
vip = 0
deluxe = 0
lblparty.Text = party
lblvip.Text = vip
lbldeluxe.Text deluxe
End Sub
Private Sub btnincv_Click(sender As Object, e As EventArgs) Handles btnincv.Click
vip = Math.Min(vip + 1, 3)
lblvip.Text = vip
party = 0
birthday = 0
deluxe = 0
lblparty.Text = party
lblbirthday.Text = birthday
lbldeluxe.Text = deluxe
End Sub
Private Sub btnincd_Click(sender As Object, e As EventArgs) Handles btnincd.Click
deluxe = Math.Min(deluxe + 1, 3)
lbldeluxe.Text = deluxe
party = 0
birthday = 0
vip = 0
lblparty.Text = party
lblbirthday.Text = birthday
lblvip.Text = vip
End Sub
Private Sub Button1_Click_1(sender As Object, e As EventArgs) Handles nextr.Click
If birthday = 0 AndAlso deluxe = 0 AndAlso party = 0 AndAlso vip = 0 Then
MessageBox.Show("You must choose a room with at least one hour.", "Error", MessageBoxButtons.OK)
Else
Me.Hide()
formsnacks.Show()
End If
End Sub
End Class

I don't understand exactly, but I think that's the solution.
[1]: https://i.stack.imgur.com/D62kl.png [example][1]
And I want an explanation of the idea you want to do if I don't help you with this solution
' Name my Button : Room1 , Room2 , Room3, Room4
'example Dim ButtonRoom As Button = CType(Me.Controls("Room" & j), Button)
' Name my Button : hello1 , hello2 , hello3, hello4
'example2 Dim ButtonRoom As Button = CType(Me.Controls("hello" & j), Button)
Private Sub Room1_Click(sender As Object, e As EventArgs) Handles Room1.Click
selected_room(1)
End Sub
Private Sub Room2_Click(sender As Object, e As EventArgs) Handles Room2.Click
selected_room(2)
End Sub
Private Sub Room3_Click(sender As Object, e As EventArgs) Handles Room3.Click
selected_room(3)
End Sub
Private Sub Room4_Click(sender As Object, e As EventArgs) Handles Room4.Click
selected_room(4)
End Sub
Public Function selected_room(ByVal i As Integer)
For j As Integer = 1 To 4
Dim ButtonRoom As Button = CType(Me.Controls("<name your button here>" & j), Button)
If j = i Then
ButtonRoom.Enabled = True
Else
ButtonRoom.Enabled = False
End If
Next j
Return True
End Function
If you do not benefit from the solution I hope you contact me
instagram : ovhc_
Vote for me if I've helped you.

Related

Creating a Grade Calculator in Visual Studio's 2019 (VB) and struggling with the code a bit

I am using VB.Net in Visual Studio 2019 to help accumulate test score data.
I have a Label named Score, and Textboxes for Score Total, Score Count, and Score Average that are all read only. I also button to Add and Clear scores, as well as Exit.
I have the code done for the Clear Scores and Exit buttons, but I am struggling with the Add button and getting all the scores input and summed.
My goal is to display the sum of all the scores in the Score Total box, the number of scores in the Score Count box, and their average in the Score Average box.
This is what I have so far:
Public Class GradeCalculator
Dim score As Integer
Dim ScoreTotal As Decimal
Dim ScoreCount As Decimal
Dim Average As Integer
Private Sub frmClearScores_Click(sender As Object, e As EventArgs) Handles frmClearScores.Click
score = 0
ScoreTotal = 0
ScoreCount = 0
Average = 0
txtscore.Text = ""
txtscoretotal.Text = ""
txtscorecount.Text = ""
txtaverage.Text = ""
txtscore.Select()
End Sub
' This is the "Add" button
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
End Sub
Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
Me.Close()
End Sub
End Class
How can I finish this?
Public Class GradeCalculator
Dim ScoreTotal As Integer = 0
Dim ScoreCount As Integer = 0
Private Sub frmClearScores_Click(sender As Object, e As EventArgs) Handles frmClearScores.Click
ScoreTotal = 0
ScoreCount = 0
txtscore.Text = ""
txtscoretotal.Text = ""
txtscorecount.Text = ""
txtaverage.Text = ""
txtscore.Select()
End Sub
' This is the "Add" button
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
ScoreTotal += CInt(txtscore.Text)
ScoreCount += 1
txtscore.Text = ""
txtscoretotal.Text = ScoreTotal.ToString()
txtscorecount.Text = ScoreCount.ToString()
txtaverage.Text = (CDec(ScoreTotal)/ScoreCount).ToString()
txtscore.Select()
End Sub
Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
Me.Close()
End Sub
End Class

How to delay in adding items in list box vb.net

I am using for, while & do while loop in vb.net to add some values in list box. I want to use a timer to delay in adding values to list box. Please tell the syntax, what should I use & Following is my code:
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim a As Integer
For a = 1 To 10
ListBox1.Items.Add(a)
End If
Next
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim b As Integer
b = 4
If b < 5 Then
MessageBox.Show("eRROR")
End If
While b <= 3
ListBox2.Items.Add(b)
b = b + 1
End While
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Dim c As Integer
c = 20
Do
c = c + 1
ListBox3.Items.Add(c)
Loop While c <= 30
End Sub
Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox1.SelectedIndexChanged
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
End Class
A timer executes once every n milliseconds, you take advantage of this by handling the timer's Tick event. If you wanted to keep track of what increment you're on, either declare a private variable outside of the scope (see here) of the Tick event or declare a static variable inside the Tick event.
Private Variable:
Private counter As Integer = 0
Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As EventArgs) Handles Timer1.Tick
counter += 1
If (counter < 31) Then
ListBox1.Items.Add(counter)
Else
Timer1.Stop()
End If
End Sub
Static Variable:
Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As EventArgs) Handles Timer1.Tick
Static counter As Integer = 0
If (counter < 31) Then
counter += 1
ListBox1.Items.Add(counter)
Else
Timer1.Stop()
End If
End Sub

I have this countdown timer and i want it to start from a number set in a variable

I have this count down timer and i want it to start to count down from a value given in a variable.
Public Class frmSinglePlayer
Private TargetDT As DateTime
Private CountDownFrom As TimeSpan = TimeSpan.FromMinutes(3)
Private Sub frmSinglePlayer_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
tmrCountdown.Interval = 500
TargetDT = DateTime.Now.Add(CountDownFrom)
tmrCountdown.Start()
End Sub
Private Sub tmrCountdown_Tick(sender As Object, e As System.EventArgs) Handles tmrCountdown.Tick
Dim ts As TimeSpan = TargetDT.Subtract(DateTime.Now)
If ts.TotalMilliseconds > 0 Then
lblTime.Text = ts.ToString("mm\:ss")
Else
lblTime.Text = "00:00"
tmrCountdown.Stop()
MessageBox.Show("Done")
End If
End Sub
End Class
I want to change instead of the number 3 in this line, to put the value from my variable.
Private CountDownFrom As TimeSpan = TimeSpan.FromMinutes(3)
I have 3 radiobuttons with different values.
Private Sub rd_1h_CheckedChanged(sender As Object, e As EventArgs) Handles rd_1h.CheckedChanged
ho = 1
End Sub
Private Sub rd_2h_CheckedChanged(sender As Object, e As EventArgs) Handles rd_2h.CheckedChanged
ho = 2
End Sub
Private Sub rd_3h_CheckedChanged(sender As Object, e As EventArgs) Handles rd_3h.CheckedChanged
ho = 3
End Sub
If is confusing , please ask me and sorry for my bad english.
Maybe you need something like this?
Private TargetDT As DateTime
Dim ho As Integer = 1
Private Sub StartTimerTick(sender As Object, e As System.EventArgs, Optional countDownFrom As Integer = 0)
If sender Is Nothing Then
TargetDT = DateTime.Now.Add(TimeSpan.FromMinutes(countDownFrom))
Dim mTmr = New Timer
mTmr.Interval = 500
AddHandler mTmr.Tick, AddressOf StartTimerTick
mTmr.Start()
Exit Sub
End If
Console.WriteLine("Tick ")
Dim ts As TimeSpan = TargetDT.Subtract(DateTime.Now)
If ts.TotalMilliseconds > 0 Then
lblTime.Text = ts.ToString("mm\:ss")
Else
lblTime.Text = "00:00"
CType(sender, Timer).Stop()
CType(sender, Timer).Dispose()
MessageBox.Show("Done")
End If
End Sub
Private Sub rd_1h_CheckedChanged(sender As Object, e As EventArgs) Handles rd_1h.CheckedChanged,
rd_2h.CheckedChanged,
rd_3h.CheckedChanged
Select Case CType(sender, Control).Name
Case "rd_1h"
ho = 1
Case "rd_2h"
ho = 2
Case "rd_3h"
ho = 3
End Select
'StartTimerTick(Nothing, Nothing, ho)
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
StartTimerTick(Nothing, Nothing, ho)
End Sub

calculation is only performed once on food ordering form (VB)

I am making a food ordering form, and I am having trouble with the calculations. Every time a hotdog is ordered the form is supposed to add the cost to the total amount, so one hotdog is 2 dollars, add another and it says 4 dollars, etc. But it only performs the calculation once, so no matter how many items I add to the order the price stays the same, as if I had only ordered one.
I don't get any errors at runtime so it must be a logical error. Here is the full code. I don't know what other information I should give at this moment. All help is appreciated.
Public Class DroneDogs
Dim DogChoice As String
Dim condiment1 As String
Dim condiment2 As String
Dim condiment3 As String
Const DBL_TAX_RATE As Double = 0.07
Const DBL_DRONE_DOG As Double = 1.99
Dim intNumDog As Integer
Dim dblSubTotal As Double
Dim dblSalesTax As Double
Dim dblTotalCost As Double
Private Sub btnAddCustomer_Click(sender As Object, e As EventArgs) Handles btnAddCustomer.Click
cboCurrentCustomers.Items.Add(txtAddCustomer.Text)
End Sub
Private Sub optBeef_CheckedChanged(sender As Object, e As EventArgs) Handles optBeef.CheckedChanged
If (optBeef.Checked) Then
DogChoice = "Beef Dog"
End If
End Sub
Private Sub optPork_CheckedChanged(sender As Object, e As EventArgs) Handles optPork.CheckedChanged
If (optPork.Checked) Then
DogChoice = "Pork Dog"
End If
End Sub
Private Sub optTurkey_CheckedChanged(sender As Object, e As EventArgs) Handles optTurkey.CheckedChanged
If (optTurkey.Checked) Then
DogChoice = "Turkey Dog"
End If
End Sub
Private Sub chkKetchup_CheckedChanged(sender As Object, e As EventArgs) Handles chkKetchup.CheckedChanged
If (chkKetchup.Checked) Then
condiment1 = " + Ketchup"
Else
condiment1 = Nothing
End If
End Sub
Private Sub chkMustard_CheckedChanged(sender As Object, e As EventArgs) Handles chkMustard.CheckedChanged
If (chkMustard.Checked) Then
condiment2 = " + Mustard"
Else
condiment2 = Nothing
End If
End Sub
Private Sub chkRelish_CheckedChanged(sender As Object, e As EventArgs) Handles chkRelish.CheckedChanged
If (chkRelish.Checked) Then
condiment3 = " + Relish"
Else
condiment3 = Nothing
End If
End Sub
Private Sub btnAddDog_Click(sender As Object, e As EventArgs) Handles btnAddDog.Click
intNumDog = +1
dblSubTotal = intNumDog * DBL_DRONE_DOG
dblSalesTax = dblSubTotal * DBL_TAX_RATE
dblTotalCost = dblSubTotal + dblSalesTax
txtSub.Text = dblSubTotal.ToString("c2")
txtTax.Text = dblSalesTax.ToString("c2")
txtTotal.Text = dblTotalCost.ToString("c2")
Dim addCondiment As String = condiment1 + condiment2 + condiment3
If (DogChoice = "Beef Dog") Or
(DogChoice = "Pork Dog") Or
(DogChoice = "Turkey Dog") Then
lstOrder.Items.Add(DogChoice + addCondiment + ": " + txtTotal.Text)
Else
MsgBox("Please select a Hot Dog type.")
End If
End Sub
Private Sub btnClearOrder_Click(sender As Object, e As EventArgs) Handles btnClearOrder.Click
lstOrder.Items.Clear()
txtSub.Clear()
txtTax.Clear()
txtTotal.Clear()
chkKetchup.Checked = 0
chkMustard.Checked = 0
chkRelish.Checked = 0
optBeef.Checked = 0
optPork.Checked = 0
optTurkey.Checked = 0
End Sub
Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
'Exits the program
If MessageBox.Show("Do you want to exit the DroneDogs application?", "DroneDogs",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) _
= DialogResult.Yes Then
Application.Exit()
End If
End Sub
Private Sub btnOrderComplete_Click(sender As Object, e As EventArgs) Handles btnOrderComplete.Click
Receipt.Show()
End Sub
Private Sub btnRemoveDog_Click(sender As Object, e As EventArgs) Handles btnRemoveDog.Click
lstOrder.Items.Remove(lstOrder.SelectedItem)
End Sub
End Class
I think the problem is with the line
intNumDog = +1
In this line, you always set intNumDog to the value of +1. This is the same as:
intNumDog = 1
You want to add one to the value of intNumDog:
intNumDog += 1

VB.Net - Noncooperative decimal in string

I am writing a calculator WinForm in VB. I have a label used to display the output "Result". My problem comes when trying to add a "." to my label string. Example: I will type 355.5 and until the 5 is pressed after it, my string is showing up as .355 After the last 5 is pressed, it jumps into the correct location. I have exhausted my debugging skill and now am just going crazy. Anyone encounter this before?
Here's my entire code so far (ignore unfinished functions)
Public Class MyCalc
Private bDecFlag As Boolean
Private sMathOp As String
Private Sub ModeSel_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ModeSel.SelectedIndexChanged
If ModeSel.SelectedIndex = 3 Then
Me.Width = 360
ElseIf ModeSel.SelectedIndex > 2 Then
Me.Width = 590
Else
Me.Width = 250
End If
If ModeSel.SelectedIndex = 0 Then
For iCount As Integer = 0 To 9
Me.Controls("Digit" & iCount).Enabled = True
Next
End If
If ModeSel.SelectedIndex = 1 Then
For iCount As Integer = 2 To 9
Me.Controls("Digit" & iCount).Enabled = False
Next
End If
If ModeSel.SelectedIndex = 2 Then
For iCount As Integer = 0 To 7
Me.Controls("Digit" & iCount).Enabled = True
Next
Digit8.Enabled = False
Digit9.Enabled = False
End If
If ModeSel.SelectedIndex = 3 Then
For iCount As Integer = 0 To 9
Me.Controls("Digit" & iCount).Enabled = True
Next
For iCount As Integer = Asc("A") To Asc("F")
Me.Controls("Alpha" & Chr(iCount)).Enabled = True
Next
For iCount As Integer = Asc("G") To Asc("Z")
Me.Controls("Alpha" & Chr(iCount)).Enabled = False
Next
End If
If ModeSel.SelectedIndex = 4 Then
For iCount As Integer = 0 To 9
Me.Controls("Digit" & iCount).Enabled = True
Next
For iCount As Integer = Asc("A") To Asc("Z")
Me.Controls("Alpha" & Chr(iCount)).Enabled = True
Next
AlphaA.Enabled = False
AlphaE.Enabled = False
AlphaI.Enabled = False
AlphaO.Enabled = False
AlphaU.Enabled = False
End If
End Sub
Private Sub Digit0_Click(sender As System.Object, e As System.EventArgs) Handles Digit0.Click
UpdateResult(0)
End Sub
Private Sub Digit1_Click(sender As System.Object, e As System.EventArgs) Handles Digit1.Click
UpdateResult(1)
End Sub
Private Sub Digit2_Click(sender As System.Object, e As System.EventArgs) Handles Digit2.Click
UpdateResult(2)
End Sub
Private Sub Digit3_Click(sender As System.Object, e As System.EventArgs) Handles Digit3.Click
UpdateResult(3)
End Sub
Private Sub Digit4_Click(sender As System.Object, e As System.EventArgs) Handles Digit4.Click
UpdateResult(4)
End Sub
Private Sub Digit5_Click(sender As System.Object, e As System.EventArgs) Handles Digit5.Click
UpdateResult(5)
End Sub
Private Sub Digit6_Click(sender As System.Object, e As System.EventArgs) Handles Digit6.Click
UpdateResult(6)
End Sub
Private Sub Digit7_Click(sender As System.Object, e As System.EventArgs) Handles Digit7.Click
UpdateResult(7)
End Sub
Private Sub Digit8_Click(sender As System.Object, e As System.EventArgs) Handles Digit8.Click
UpdateResult(8)
End Sub
Private Sub Digit9_Click(sender As System.Object, e As System.EventArgs) Handles Digit9.Click
UpdateResult(9)
End Sub
Private Sub DecBut_Click(sender As System.Object, e As System.EventArgs) Handles DecBut.Click
If bDecFlag = False Then
If Result.Text = "0" Then
Result.Text = "0."
bDecFlag = True
Else
Result.Text = Result.Text + "."
bDecFlag = True
End If
End If
End Sub
Private Sub ClrBut_Click(sender As System.Object, e As System.EventArgs) Handles ClrBut.Click
Result.Text = 0
bDecFlag = False
End Sub
Private Sub DelBut_Click(sender As System.Object, e As System.EventArgs) Handles DelBut.Click
If Result.Text = "0" Then
ElseIf Result.Text.Substring(Result.Text.Length - 1) = "." Then
Result.Text = Result.Text.Substring(0, Result.Text.Length - 1)
bDecFlag = False
Else
Result.Text = Result.Text.Substring(0, Result.Text.Length - 1)
If Result.Text = "" Then
Result.Text = "0"
End If
End If
End Sub
Private Sub MyCalc_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
Select Case e.KeyCode
Case Keys.NumPad0
Digit0_Click(Digit0, New EventArgs)
Case Keys.NumPad1
Digit1_Click(Digit1, New EventArgs)
Case Keys.NumPad2
Digit2_Click(Digit2, New EventArgs)
Case Keys.NumPad3
Digit3_Click(Digit3, New EventArgs)
Case Keys.NumPad4
Digit4_Click(Digit4, New EventArgs)
Case Keys.NumPad5
Digit5_Click(Digit5, New EventArgs)
Case Keys.NumPad6
Digit6_Click(Digit6, New EventArgs)
Case Keys.NumPad7
Digit7_Click(Digit7, New EventArgs)
Case Keys.NumPad8
Digit8_Click(Digit8, New EventArgs)
Case Keys.NumPad9
Digit9_Click(Digit9, New EventArgs)
Case Keys.Back
DelBut_Click(DelBut, New EventArgs)
Case Keys.Decimal
DecBut_Click(DecBut, New EventArgs)
End Select
End Sub
Private Sub MyCalc_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
bDecFlag = False
End Sub
Public Sub UpdateResult(ByVal sNum As String)
If Result.Text = "0" Then
Result.Text = sNum
Else
Result.Text &= sNum
End If
End Sub
End Class
So after the long debugging, I found out that you are using the Label/Textbox RightToLeft property set to yes. Nothing is wrong with it really, but it can't handle special characters including decimal points, commas, etc. properly. The workaround for this is to reverse what we have expected - to reverse the string concatenation.
Result.Text = "." & Result.Text
Not seeing entire code I'm not exactly sure but I think there might be something wrong with string concatenation.
Try changing into this:
Result.Text = Result.Text & "."