Computer

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?

  1. 👍 0
  2. 👎 0
  3. 👁 153
  1. Looks like you have some unintialized variables. Dividing by txt12 before giving it a value will use its default value of zero.

    1. 👍 0
    2. 👎 0
    posted by Steve
  2. Bug solved. Thank you. ^^

    1. 👍 0
    2. 👎 0

Respond to this Question

First Name

Your Response

Similar Questions

  1. math

    a. The power of an electric appliance is given by the formula P=I^2R, where I is the current and R is resistance. Use this information to explain how you can use radicals to determine the current if the power and the resistance is

    asked by Steve on September 19, 2016
  2. Physics

    Power transmission lines often use a form of electric current called alternating current, but in many regions, such as the Province of Quebec, high-voltage direct-current lines are used instead. Direct current is the kind of

    asked by Sheree on May 31, 2012
  3. Science

    A coil of inductance 0.04henry and negligible resistance is connected in parallel with a 10ohms resistor, across a 240volts supply of frequency 50hz. Calculate:1) the current through the resistance, 2) the current through the

    asked by Vincent on June 10, 2018
  4. Rohan Khan

    A person with body resistance between his hands of 10KÙ accidently grasps the terminal of a 14-KV power supply. (a) If the internal resistance of the power supply is 2000Ù, what is the current through the person’s body? (b)

    asked by Rohan Khan on June 10, 2011
  5. Physics

    A 12-V automobile storage battery has an internal resistance of 0.004 ohms. A) Find the current and power dissipation when the terminals are connected by a conductor of negligible Resistance B) The battery delivers 80A to the

    asked by Rina on February 27, 2016
  6. Physics

    Which of the following statements about Ohm’s Law is true? A. Keeping the same voltage and decreasing resistance decreases the current. B. To increase the current, decrease the resistance. C. Ohm’s law relates power, current

    asked by Saif on January 23, 2017
  7. physics

    a 6.0 kW electric oven is connected to a fuse box by a cable of resistance 0.25 ohms. when the cooker is switched on at full power, a current of 26 A passes through it. Calculate the potential difference between the two ends of

    asked by eleena on April 19, 2014
  8. math power series(please helpassessment tomorrow)

    The exponential function can be represented as an infinity power series as follows. e^x=1 + x/1! + x^2/2! + x^3/3!+⋯,-∞

    asked by bryan on May 2, 2017
  9. sir damon plz help me or steve

    An ac source of 50v,100÷πHz is connected in series with an inductor of inductance L ad a resistor of resistance R.the current in the circuit is 2A ad p.d. across L and R are 30v ad 40v respectively 1) calculate the average power

    asked by maths on November 3, 2016
  10. physics

    Two resistances 2omega and 3omega are in parallel. The combination is in series with 15omega resistance and a power supply of voltage V. There is a current of 3omega resistance. What are the values of the current and votage across

    asked by favour on August 25, 2013

More Similar Questions