1 Replies - 133 Views - Last Post: 13 October 2019 - 10:41 AM Rate Topic: -----

#1 Catea   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 13-October 19

Result will show in textbox 2.

Posted 13 October 2019 - 10:04 AM

Hi guys! I'm creating a program wherein a user enters an amount to textbox1 and will show the result in textbox2 by clicking the compute button. It also used three radio buttons with 10% discount, 5% and 10% interests percentage. When I click compute button it doesn't give the correct answer like discounted payment or payment with interest.Do I need the If-Then Statement? I'm currently studying and researching about visual studio to learn more.I hope you can help me. Thanks in advance.

This is my code:

Public Class Form1
    Private Payment1 As Integer
    Private Payment2 As Double
    Private nNum1, nNum2 As String


    Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
        Payment1 = Val(TextBox1.Text)
    End Sub

    Private Sub TextBox2_TextChanged(sender As Object, e As EventArgs) Handles TextBox2.TextChanged
        Payment2 = Val(TextBox2.Text)
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Payment2 = 10% * Payment1
        TextBox2.Text = Str(Payment2)
    End Sub

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Payment1 = 0
        Payment2 = 0
        nNum1 = " "
        nNum2 = " "
        TextBox1.Text = nNum1
        TextBox2.Text = nNum2

    End Sub

    Private Sub RadioButton1_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton1.CheckedChanged
        Payment2 = Payment1 * 0.1 - Payment1
        TextBox2.Text = Str(Payment2)
    End Sub

    Private Sub RadioButton2_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton2.CheckedChanged
        Payment2 = Payment1 * 0.05 + Payment1
        Payment2.Text = Str(Payment1)
    End Sub

    Private Sub RadioButton3_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton3.CheckedChanged
        Payment2 = Payment1 * 0.1 + Payment1
        TextBox2.Text = Str(Payment1)
    End Sub
End Class
:code:

This post has been edited by modi123_1: 13 October 2019 - 10:39 AM
Reason for edit:: In the future please use the [code] tag button in the editor


Is This A Good Question/Topic? 0
  • +

Replies To: Result will show in textbox 2.

#2 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15314
  • View blog
  • Posts: 61,409
  • Joined: 12-June 08

Re: Result will show in textbox 2.

Posted 13 October 2019 - 10:41 AM

You are using the radio buttons incorrectly. You should not be doing payment or math on the 'check changed' when you seem to really want to do that when the button clicks.

In the button click you would want see which radio button is selected and do the appropriate math from there. That would require a few IF statements.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1