扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
图一、创建一个新的窗体应用程序 |
Function ComputeFibonacci(ByVal n As Integer) As Long ’ The parameter n must be >= 0 and <= 91. ’ Fib(n), with n > 91, overflows a long. If n < 0 OrElse n > 91 Then Throw New ArgumentException( "value must be >= 0 and <= 91", "n") End If Dim result As Long = 0 If n < 2 Then result = 1 Else result = ComputeFibonacci(n - 1) + ComputeFibonacci(n - 2) End If ’ Report progress as a percentage of the total task. Dim percentComplete As Integer = CSng(n) / CSng(numberToCompute) * 100 If percentComplete > highestPercentageReached Then highestPercentageReached = percentComplete Me.ProgressBar1.Value = percentComplete End If Return result End Function |
Private Sub startSyncButton_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles startSyncButton.Click ’ Reset the text in the result label. result.Text = [String].Empty ’ Disable the UpDown control until ’ the synchronous operation is done. Me.numericUpDown1.Enabled = False ’ Disable the Start button until ’ the synchronous operation is done. Me.startSyncButton.Enabled = False ’ Enable the Cancel button while ’ the synchronous operation runs. Me.cancelSyncButton.Enabled = True ’ Get the value from the UpDown control and store it ’ in the globle variable numberToCompute. numberToCompute = CInt(numericUpDown1.Value) ’ Reset the variable for percentage tracking. highestPercentageReached = 0 ’ Start the synchronous operation. result.Text = ComputeFibonacci(numberToCompute).ToString ’ Enable the UpDown control. Me.numericUpDown1.Enabled = True ’ Enable the Start button. startSyncButton.Enabled = True ’ Disable the Cancel button. cancelSyncButton.Enabled = False End Sub |
图二、即使函数在运行,但程序对用户操做没有任何反应 |
Private Sub cancelSyncButton_Click(ByVal sender As System.Object,_ ByVal e As System.EventArgs) Handles cancelSyncButton.Click MsgBox("Cancel") End Sub |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者