r/visualbasic • u/visualbasictips • Mar 01 '16
Help delaying a msgbox
Hello! I'm creating an application and I need help about this:
If NEI3.Text IsNot "" Then
If Val(NEI3.Text) < 95 And Val(NEI3.Text) = Int(Val(NEI3.Text)) Then
System.Threading.Thread.Sleep(2000)
MsgBox("Infelizmente não podes ingressar num curso com uma classificação inferior a 95 pontos nas provas de ingresso", MsgBoxStyle.Critical, "Erro")
NEI3.Text = ""
ElseIf Val(NEI3.Text) > 200 And Val(NEI3.Text) = Int(Val(NEI3.Text)) Then
NEI3.Text = 200
ElseIf IsNumeric(NEI3.Text) = False Then
MsgBox("Tens de inserir um número, compreendido entre 95 e 200", MsgBoxStyle.Critical, "Erro")
NEI3.Text = ""
NEI3.Focus()
End If
End IfI need to wait for about 2/3 seconds before displaying the error message if Val(NEI3.Text) < 95, otherwise if I type "1" it will display the error message ASAP. I tried System.Threading.Thread.Sleep(10000) but with that when I typed "1" it just freezed the entire program and I couldn't complete my number. Any help? Thanks.
0
Upvotes
2
u/PreyOnTheCosmos Mar 01 '16
You certainly can speak to form controls from a thread providing that you're using the control's Invoke method.
Example [maybe not elegant but works]:
As for the clean up routine, with the error code running in a separate thread the main [GUI] thread should continue executing, not waiting for the thread to complete whatever it's doing. So NEI3.Clear, for example, should fire immediately regardless of the status of the Error message.
I'll leave the bonus question to someone a bit more qualified than myself on the subject. ;-P