Why my vb calculation appears infinity?

The calcluator is set to calculate current, resistance and power.
the followings are the code for the calculator:
Public Class Form3
Dim Black As Integer = 0
Dim Brown As Integer = 1
Dim Red As Integer = 2
Dim Orange As Integer = 3
Dim Yellow As Integer = 4
Dim Green As Integer = 5
Dim Blue As Integer = 6
Dim Violet As Integer = 7
Dim Gray As Integer = 8
Dim White As Integer = 9
Dim Gold As Integer = 5
Dim Silver As Integer = 10
Dim None As Integer = 20
----------------------------------------
Private Sub dud1_SelectedItemChanged(sender As Object, e As EventArgs) Handles dud1.SelectedItemChanged
If dud1.SelectedItem = "Black" Then
txt7.BackColor = Color.Black
txt7.Text = Black
ElseIf dud1.SelectedItem = "Brown" Then
txt7.BackColor = Color.Brown
txt7.Text = Brown
ElseIf dud1.SelectedItem = "Red" Then
txt7.BackColor = Color.Red
txt7.Text = Red
ElseIf dud1.SelectedItem = "Orange" Then
txt7.BackColor = Color.Orange
txt7.Text = Orange
ElseIf dud1.SelectedItem = "Yellow" Then
txt7.BackColor = Color.Yellow
txt7.Text = Yellow
ElseIf dud1.SelectedItem = "Green" Then
txt7.BackColor = Color.Green
txt7.Text = Green
ElseIf dud1.SelectedItem = "Blue" Then
txt7.BackColor = Color.Blue
txt7.Text = Blue
ElseIf dud1.SelectedItem = "Violet" Then
txt7.BackColor = Color.Violet
txt7.Text = Violet
ElseIf dud1.SelectedItem = "Gray" Then
txt7.BackColor = Color.Gray
txt7.Text = Gray
ElseIf dud1.SelectedItem = "White" Then
txt7.BackColor = Color.White
txt7.Text = White
End If
End Sub
----------------------------------------
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
txt1.Text = Val(txt7.Text + txt8.Text) * 10 ^ (Val(txt9.Text))
txt2.Text = (Val(txt7.Text + txt8.Text) * 10 ^ (Val(txt9.Text))) * Val(Val(txt10.Text) / 100)
End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
txt6.Text = Val(txt5.Text) / Val(txt12.Text)
txt11.Text = Val(txt5.Text) * Val(txt6.Text)
txt12.Text = Val(1 / (Val(1 / (txt3.Text)) + Val(1 / txt4.Text)))
End Sub
----------------------------------------
The calculation appears "infinity" for current when press "calculate" for the first time. After pressing it for second time then the actual no. appear.
If I change the no. of voltage then press calculate, it will show the previous no. The actual no. appears only when the "calculate" button pressed twice.
What's the problem?

Looks like you have some unintialized variables. Dividing by txt12 before giving it a value will use its default value of zero.

Bug solved. Thank you. ^^

Based on the code snippet you provided, it appears that the issue is related to the order of calculations in your code when you click the "Calculate" button.

In the `Button1_Click` event handler, you're performing two calculations:
1. Calculating `txt1.Text`: `Val(txt7.Text + txt8.Text) * 10 ^ (Val(txt9.Text))`
2. Calculating `txt2.Text`: `(Val(txt7.Text + txt8.Text) * 10 ^ (Val(txt9.Text))) * Val(Val(txt10.Text) / 100)`

Similarly, in the `Button2_Click` event handler, you're performing three calculations:
1. Calculating `txt6.Text`: `Val(txt5.Text) / Val(txt12.Text)`
2. Calculating `txt11.Text`: `Val(txt5.Text) * Val(txt6.Text)`
3. Calculating `txt12.Text`: `Val(1 / (Val(1 / (txt3.Text)) + Val(1 / txt4.Text)))`

The issue seems to stem from the fact that you're using `Val()` to convert the text in the textboxes to numbers for calculations. However, if the textbox values are empty or not valid numbers, it can lead to unexpected results, including infinity.

To fix this issue, you can perform some input validation before performing the calculations. You can use functions like `Integer.TryParse()` or `Double.TryParse()` to check if the textbox values can be successfully converted to numbers. Additionally, you can set default values or display error messages if the input is not valid.

For example, you can modify your `Button1_Click` event handler as follows:

```
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim val7 As Integer
Dim val8 As Integer
Dim val9 As Integer
Dim val10 As Double

If Integer.TryParse(txt7.Text, val7) AndAlso Integer.TryParse(txt8.Text, val8) AndAlso
Integer.TryParse(txt9.Text, val9) AndAlso Double.TryParse(txt10.Text, val10) Then

txt1.Text = (val7 + val8) * 10 ^ val9
txt2.Text = ((val7 + val8) * 10 ^ val9) * (val10 / 100)
Else
MessageBox.Show("Invalid input. Please enter valid numbers.")
End If
End Sub
```

You can apply a similar validation approach to the `Button2_Click` event handler as well.

By performing proper input validation, you can ensure that the calculations are performed correctly, and you won't encounter infinite values or unexpected results.