I need to get the x variable from textbox6 into the equation and by pushing button 1, the finish product goes into label2, which is lets say 15min and 45 seconds. I need 15:45 to countdown to 0, and form1 pops up.

I am learning VB from tutorials online, so expect a dummy here :p

You will need to validate your textbox inputs to ensure the user enters valid numeric values.

Hope this helps.

Please remember to click “Mark as Answer” on the post that helps you and to unmark it if a marked post does not actually answer your question.
Thank you!
----------------------
"Microsoft Community Contributor Award 2011"

Please remember to click “Mark as Answer” on the post that helps you and to unmark it if a marked post does not actually answer your question.
Thank you!
----------------------
"Microsoft Community Contributor Award 2011"

What I want is just the time, not date or anything else, in regular format, which in this case would be 22:30.

So far I only have:

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Label2.Text = 25 - (Int32.Parse(TextBox11.Text) / 160)
Label2.Text = (DateTime.Parse(Label2.Text))
End Sub

Please remember to click “Mark as Answer” on the post that helps you and to unmark it if a marked post does not actually answer your question.
Thank you!
----------------------
"Microsoft Community Contributor Award 2011"

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Label2.Text = 25 - (Int32.Parse(TextBox11.Text) / 160)
Label2.Text = (DateTime.Parse(Label2.Text))
End Sub

Hope you get what I mean now :/

That means you need to get the integral part and decimal part, the integral part is hour and the decimal part is minute. After calculate this equation and get the result, you want to cast it datetime type and display it with Label.

If I don't misunderstand your requriement, please check my sample code:

Note: you need to use System.Math.Truncate method which Calculates the integral part of a specified decimal number.

Protected Sub Page_Load(sender As Object, e As EventArgs)
Dim input As Double = CDbl(TextBox11.Text)
Label1.Text = CalculateTime(input)
End Sub
Public Function CalculateTime(input As Double) As String
Dim total As Double = 25 - (input / 160)
'get minutes
Dim hours As Double = System.Math.Truncate(total)
'get seconds
Dim mins As Double = (total - hours) * 60
Dim dt As New DateTime()
Dim timeStr As String = hours & ":" & mins
DateTime.TryParse(timeStr, dt)
Return dt.ToString("hh:mm")
End Function

Please mark the replies as answers if they help or unmark if not.
Feedback to us

None

0 Points

3 Posts

## Need to solve this equation in vb

Jul 21, 2012 07:28 PM|tehtman|LINK

This is the equation I have to solve

I need to get the x variable from textbox6 into the equation and by pushing button 1, the finish product goes into label2, which is lets say 15min and 45 seconds. I need 15:45 to countdown to 0, and form1 pops up.

I am learning VB from tutorials online, so expect a dummy here :p

Contributor

5601 Points

1489 Posts

## Re: Need to solve this equation in vb

Jul 21, 2012 09:08 PM|santa_1975|LINK

Hi,

Try this.

You will need to validate your textbox inputs to ensure the user enters valid numeric values.

Hope this helps.

Thank you!

----------------------

"Microsoft Community Contributor Award 2011"

None

0 Points

3 Posts

## Re: Need to solve this equation in vb

Jul 21, 2012 09:30 PM|tehtman|LINK

Thanks :p didnt think it would be that simple to do

But im still curious how I would convert the variable to get it into time format

Contributor

5601 Points

1489 Posts

## Re: Need to solve this equation in vb

Jul 21, 2012 11:20 PM|santa_1975|LINK

Hi,

Refer to this link for converting a string value to datetime with different formats.

http://www.dotnetperls.com/datetime-parse-vbnet

Hope this helps.

Thank you!

----------------------

"Microsoft Community Contributor Award 2011"

None

0 Points

3 Posts

## Re: Need to solve this equation in vb

Jul 22, 2012 01:10 AM|tehtman|LINK

Ok, I dont think you quite understand me...

25-(400/160) 25-2.50 22.5 min

What I want is just the time, not date or anything else, in regular format, which in this case would be 22:30.

So far I only have:

Contributor

5601 Points

1489 Posts

## Re: Need to solve this equation in vb

Jul 22, 2012 12:26 PM|santa_1975|LINK

Hi,

To convert a string into datetime and to just display the time part alone use the below code.

Hope this helps.

Thank you!

----------------------

"Microsoft Community Contributor Award 2011"

All-Star

25305 Points

2607 Posts

## Re: Need to solve this equation in vb

Jul 27, 2012 04:24 AM|Mamba Dai - MSFT|LINK

Hi,

That means you need to get the integral part and decimal part, the integral part is hour and the decimal part is minute. After calculate this equation and get the result, you want to cast it datetime type and display it with Label.

If I don't misunderstand your requriement, please check my sample code:

Note: you need to use System.Math.Truncate method which Calculates the integral part of a specified decimal number.

Feedback to us