我想将总分钟数转换为天数小时和分钟。我是 vb 新手,仍在努力学习……这是我的代码……
Private Sub TextBox3_TextChanged(sender As Object, e As EventArgs) Handles TextBox3.TextChanged
TextBox1.Text = TextBox3.Text / 1440
End Sub
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
TextBox3.Text = TextBox1.Text * 1440
TextBox7.Text = TextBox1.Text / 24
End Sub
Private Sub TextBox7_TextChanged(sender As Object, e As EventArgs) Handles TextBox7.TextChanged
TextBox1.Text = TextBox7.Text * 24
End Sub
当我运行它时,我得到十进制的答案.. 谁能建议我一个正确的方法来做到这一点?我不想要小数。
看起来您并不了解变量的概念,您不需要使用三个不同的处理程序来完成这项工作,您可以在一个处理程序中完成所有操作。
您可以在算术上做您想做的事,但在我看来,更简单的方法是使用 TimeSpan。它看起来像这样:
'TextBox1 is where the user inputs the number of minutes
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
Dim d = TimeSpan.FromMinutes(TextBox1.Text) 'creates a TimeSpan based on user input, this is also a variable creation
TextBox5.Text = d.ToString("dd\:hh\:mm") 'you can format it with a custom format
'Or you can access the elements of the TimeSpan like so
TextBox2.Text = d.Days
TextBox3.Text = d.Hours
TextBox4.Text = d.Minutes
End Sub
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句