The following information is for the EMANT300
What if the user wants the answer to be updated when the inputs are changed rather than wait until the add button is clicked. There are several ways to do this. One way is to use the timer component.
-
In .NET jargon, a control is a visual component whereas a component is non-visual. Thus, the Label, NumericUpDown and Button are all controls whereas the Timer which we will use now is a component. A component does not appear (or is invisible) during runtime.
-
Goto the Toolbox, click on the Components tab to display the components as shown on the right
-
Click on Timer. While holding on the mouse left button, drag the Timer to the form and release the left button to get the component placed as shown in the figure above. You must release the component on the form. When you have successfully placed the Timer component, the Form looks as below. As a non-visual component, it resides in a component tray which is at the bottom of the form designer.
The Timer object is called Timer1 and some of its default properties are
-
timer1.Enabled is false
-
timer1.Interval is 100 ms
-
On the Timer1 properties window, set the Enabled property to True. Double click on the Timer1 component to create the Timer1's default event called Tick Type in the highlighted code to the event handler created
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim answer As Decimal
answer = NumericUpDown1.Value + NumericUpDown2.Value
Label1.Text = answer.ToString
End Sub
You will realize that this is the same code we type in earlier for the Button1_Click event. As the timer elapsed event is fired every 100ms, the answer is therefore recalculated and displayed every 100ms.
Label1.Text = answer.ToString
In Exercise 4, you learnt about the Convert class in the System namespace. In this example, we convert a decimal to a string before displaying it using label1.
Click on Debug-> Start to run your modified Windows program. If you did not have any typing errors, the program will run. Label1 changes to reflect the sum of the numbers. Change the values in the numeric controls and Label1 will change to reflect the sum of the numbers.
-
Click on
to return to the development environment. -
Save your project by clicking on File -> Save All.
DAQ & Visual Basic Page 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37