30.07.2013 Views

Visual Basic.NET How to Program (PDF)

Visual Basic.NET How to Program (PDF)

Visual Basic.NET How to Program (PDF)

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 8 Object-Based <strong>Program</strong>ming 319<br />

13 ' Label and TextBox for minute<br />

14 Friend WithEvents lblSetMinute As Label<br />

15 Friend WithEvents txtSetMinute As TextBox<br />

16<br />

17 ' Label and TextBox for second<br />

18 Friend WithEvents lblSetSecond As Label<br />

19 Friend WithEvents txtSetSecond As TextBox<br />

20<br />

21 ' Labels for outputting time<br />

22 Friend WithEvents lblOutput1 As Label<br />

23 Friend WithEvents lblOutput2 As Label<br />

24<br />

25 ' But<strong>to</strong>n for adding one second <strong>to</strong> time<br />

26 Friend WithEvents cmdAddSecond As But<strong>to</strong>n<br />

27<br />

28 Dim time As New CTime3()<br />

29<br />

30 ' <strong>Visual</strong> Studio .<strong>NET</strong> generated code<br />

31<br />

32 ' update time display<br />

33 Private Sub UpdateDisplay()<br />

34 lblOutput1.Text = "Hour: " & time.Hour & "; Minute: " & _<br />

35 time.Minute & "; Second: " & time.Second<br />

36<br />

37 lblOutput2.Text = "Standard time is: " & _<br />

38 time.ToStandardString & "; Universal Time is: " _<br />

39 & time.ToUniversalString()<br />

40 End Sub ' UpdateDisplay<br />

41<br />

42 ' invoked when user presses Add Second but<strong>to</strong>n<br />

43 Protected Sub cmdAddSecond_Click( _<br />

44 ByVal sender As System.Object, _<br />

45 ByVal e As System.EventArgs) Handles cmdAddSecond.Click<br />

46<br />

47 ' add one second<br />

48 time.Second = (time.Second + 1) Mod 60<br />

49 txtSetSecond.Text = time.Second<br />

50<br />

51 ' add one minute if 60 seconds have passed<br />

52 If time.Second = 0 Then<br />

53 time.Minute = (time.Minute + 1) Mod 60<br />

54 txtSetMinute.Text = time.Minute<br />

55<br />

56 ' add one hour if 60 minutes have passed<br />

57 If time.Minute = 0 Then<br />

58 time.Hour = (time.Hour + 1) Mod 24<br />

59 txtSetHour.Text = time.Hour<br />

60 End If<br />

61<br />

62 End If<br />

63<br />

64 UpdateDisplay()<br />

65 End Sub ' cmdAddSecond_Click<br />

Fig. 8.7 Graphical user interface for class CTime3 (part 2 of 3).

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!