我想将总分钟转换为天数小时和分钟。我是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
当我运行它时,我有十进制的答案..任何人都可以建议我这样做的正确方法吗?我不想要小数。
答案 0 :(得分:4)
看起来你不理解变量的概念,你不需要有三个不同的处理程序来完成这项工作,你可以在一个处理程序中完成所有操作。
你可以在算术上做你想做的事,但在我看来,更简单的方法是使用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
答案 1 :(得分:0)
如果我在延迟时间框中输入一些值我想要的日子。小时。分钟改为新值...... @obl