Click here to Skip to main content
15,908,901 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
This is my stop watch I made in Visual Basic Express.
When the stop watch stops it displays the figure in the Message Box.

What I want it to do is Multiply the figure which can be entered into the text box by the time figure recorded which is already displayed in the message box.

Say you enter 2.45 in Text box and time recorded is 5.34 then in the message box it would display the answer which is 2.45 (text Box) * 5.34 (time recorded on stop watch) = 13.083 in the message box.

This is the code I have got so far :
Please help me finish this off, Thanks From Paul



VB
Public Class Form1

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Label1.Text = Label1.Text + 0.01
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Timer1.Enabled = True
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Timer1.Enabled = False
        MsgBox(Label1.Text)
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Timer1.Enabled = False
        Label1.Text = 0.0
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Private Sub MaskedTextBox1_MaskInputRejected(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MaskInputRejectedEventArgs)

    End Sub
End Class
Posted
Updated 29-Oct-13 6:12am
v2
Comments
ZurdoDev 29-Oct-13 12:09pm    
What's the question?
Richard MacCutchan 29-Oct-13 12:14pm    
You need to add some code to
- read the value from the textbox.
- parse it to a double value.
- multiply that value by the stopwatch time.
- store it back to the label or textbox for display.
Four simple steps.

Hello

If you assume that TextBox1.Text and Label1.Text always contains a number then just multiply the two values and display the result:

VB
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    Timer1.Enabled = False

    Dim result As String
    result = TextBox1.Text * Label1.Text

    MsgBox(result)
End Sub


If the text values can be something else you may want to convert them to a number first:

VB
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    Timer1.Enabled = False

    Dim value As Double
    Dim result As String

    If Double.TryParse(TextBox1.Text, value) Then
        'TextBox1.Text is a number
        result = value * Label1.Text
    End If

    MsgBox(result)
End Sub




Valery.
 
Share this answer
 
Thanks Valery just the right help I needed. Paul
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900