1 / 18

Public Class Form1 Inherits System.Windows.Forms.Form Private Sub bntRedDemo_Click (….

Public Class Form1 Inherits System.Windows.Forms.Form Private Sub bntRedDemo_Click (…. Sleep(5000) bntRedDemo.Text = "You waited 5 seconds for this?" End Sub Declare Sub Sleep Lib " kernel32 " (ByVal dwMilliseconds As Long) End Class.

spanns
Download Presentation

Public Class Form1 Inherits System.Windows.Forms.Form Private Sub bntRedDemo_Click (….

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Public Class Form1 Inherits System.Windows.Forms.Form Private Sub bntRedDemo_Click(…. Sleep(5000) bntRedDemo.Text = "You waited 5 seconds for this?" End Sub Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) End Class Windows From Designer generated code After 5 Seconds

  2. Sleep(5000) ‘Pause for 5 seconds Sleep(1000) ‘Pause for 1 second Sleep(500) ‘Pause for 1/2 second

  3. The For loop is very versatile with lots of options. The following is the syntax: ForLoopCounter = InitialValue ToTerminatingValue Program Statement(s) NextLoopCounter The sequence for the correct evaluation of a For loop is as follows: 1 The LoopCounter is set to the value InitialValue. 2 The LoopCounter is compared to the TerminatingValue. If the LoopCounter is greater than the TerminatingValue, go to step 6. Otherwise, continue with the execution of the loop. 3 The program statements contained in the body of the loop are executed. 4 The value LoopCounter is incremented. 5 Go to step 2. 6 Exit the loop.

  4. Private Sub bntRedDemo_Click(…. DimintCounter As Integer intCounter = 0 ForintCounter = 1 To5 bntRedDemo.Text = (intCounter).ToString bntRedDemo.Refresh() Sleep(1000) NextintCounter End Sub 1 2 … 5

  5. Private Sub bntRedDemo_Click(…. DimintCounter As Integer intCounter = 0 ForintCounter = 1 To47 bntRedDemo.Text = (intCounter).ToString bntRedDemo.Refresh() Sleep(1000) NextintCounter End Sub 1 2 … 47

  6. Private Sub bntRedDemo_Click(…. DimintCounter As Integer intCounter = 0 ForintCounter = 11 To47 bntRedDemo.Text = (intCounter).ToString bntRedDemo.Refresh() Sleep(1000) NextintCounter End Sub 11 12 … 47

  7. Private Sub bntRedDemo_Click(…. DimintCounter As Integer intCounter = 0 ForintCounter = 11 To47 bntRedDemo.Text = (intCounter).ToString bntRedDemo.Refresh() Sleep(1000) NextintCounter End Sub From now on I will just show the loop body for clarity. As always, we recall that the rest of the code is really there

  8. ForintCounter = 1 To10 Step 2 bntRedDemo.Text = (intCounter).ToString bntRedDemo.Refresh() Sleep(1000) NextintCounter 1 3 We can use the Step option to count in increments other that 1 Lets show all the odd numbers from 1 to 10 … 9

  9. ForintCounter = 10 To1 Step -1 bntRedDemo.Text = (intCounter).ToString bntRedDemo.Refresh() Sleep(1000) NextintCounter bntRedDemo.Text = "We have liftoff!" 10 9 … 1 We can use the Step option to count in increments other that 1 We can use a negative step to count backwards.

  10. Dim strS As String strS = “” ForintCounter = 1 To5 strS = strS & (intCounter).ToString bntRedDemo.Text = strS NextintCounter But how do we do this?

  11. Case Study I Lets us add up all the integers from 1 to 100 1 + 2 + 3 + 4 …. + 98 + 99 + 100

  12. Dim intTotalCount As Integer intTotalCount = 0 For intCounter = 1 To 100 intTotalCount = intTotalCount + intCounter Next intCounter bntRedDemo.Text = intTotalCount.ToString

  13. Case Study II Lets us multiply up all the integers from 1 to 10 1 * 2 * 3 * 4 * 5 * 6 * 7 * 8 * 9 * 10 Also called 10 factorial, denoted as 10!

  14. Dim intTotal As Integer intTotal = 1 For intCounter = 1 To 10 intTotal = intTotal * intCounter Next intCounter bntRedDemo.Text = intTotal.ToString

  15. Case Study III Lets us multiply up all the integers from 1 to 100 1 * 2 * 3 * 4 * 5 …* 98 * 99 * 100 Stop: We can not do this. 100! Is much larger than 2,147,483,647, in fact 100! Is much larger than our long type (9,223,372,036,854,775,807)

  16. Case Study II Lets us add up all the integers from Low to High, where Low and High are not known in advance Low + (Low +1) + (Low +2)… + High

  17. Dim intTotalCount, intLow, intHigh As Integer intTotalCount = 0 intLow = ‘ assume some code that gets the value intHigh = ‘ assume some code that gets the value For intCounter = intLow To intHigh intTotalCount = intTotalCount + intCounter Next intCounter bntRedDemo.Text = intTotalCount.ToString

More Related