LmÉPï C Á npï À ƵÀ ïì itech Analytic Solutions

Size: px
Start display at page:

Download "LmÉPï C Á npï À ƵÀ ïì itech Analytic Solutions"

Transcription

1 LmÉPï C Á npï À ƵÀ ïì itech Analytic Solutions No. 9, 1st Floor, 8th Main, 9th Cross, SBM Colony, Brindavan Nagar, Mathikere, Bangalore itechanalytcisolutions@gmail.com Website: Mobile:

2 VBA Codes Loops (with example) No. 9, 1 st Floor, 8 th Main, 9 th Cross, SBM Colony, Brindavan Nagar, Mathikere, Bangalore Page: 2

3 Excel VBA Loops, with examples. For Loop; Do While Loop; Do Until Loop. Loops are one of the most basic and powerful programming tools in VBA, and used across most programming languages. Loops are used to repeat a block of code as many times as required, until a given condition remains true or a specific point (or value) is reached, after which the the next section of code is executed. A loop enables you to write a few simple lines of code and achieve a far more significant output, just by repetition. There are three basic kinds of VBA Loops (subdivided into 6 loops as below): The For Loop The For Next Statements The For Each Next Statements The Do While Loop The Do While Loop Statements The Do Loop While Statements The Do Until Loop The Do Until Loop Statements The Do Loop Until Statements The For Loop The For Next Statements The For Next Loop repeats a block of code a specific number of times. For counter_variable = start_value To end_value [block of code] Next counter_variable This is explained with the help of a simple example: Sub fornext1() No. 9, 1 st Floor, 8 th Main, 9 th Cross, SBM Colony, Brindavan Nagar, Mathikere, Bangalore Page: 3

4 Dim n As Integer Dim ntotal As Integer ntotal = 0 For n = 1 To 5 ntotal = n + ntotal Next n MsgBox ntotal The counter variable is "n", which is required to be declared. The start_value of the counter is 1, and its end_value is 5, both numeric values. Mentioning "Step" keyword is optional - this is a numeric value by which the counter is incremented each time the loop is run. The default step value is 1, unless specified. The Next statement increments the counter by the step value, and returns to the For statement, which repeats the block of code if the counter value does not exceed the "end" value of 5. If counter is equal to "end" value, the loop will continue; it stops when the "end" value is exceeded. The block of code which is repeated in this loop is: "ntotal = n + ntotal". Stepwise explanation: In this example, the counter increments by the default step value of 1, and in the first loop (where n = 1), ntotal adds up to 1 (adds 1 to its initial value of zero); The Next statement increments the counter by 1 (n = 2) and returns to For statement, and in the second loop ntotal adds up to 3 (adds 2 to its previous value of 1); The Next statement increments the counter by 1 (n = 3) and returns to For statement, and in the third loop ntotal adds up to 6 (adds 3 to its previous value of 3); The Next statement increments the counter by 1 (n = 4) and returns to For statement, and in the fourth loop ntotal adds up to 10 (adds 4 to its previous value of 6); The Next statement increments the counter by 1 (n = 5) and returns to For statement, and in the fifth loop ntotal adds up to 15 (adds 5 to its previous value of 10); No. 9, 1 st Floor, 8 th Main, 9 th Cross, SBM Colony, Brindavan Nagar, Mathikere, Bangalore Page: 4

5 After executing the fifth loop, the Next statement increments the counter (ie. n) value to 6 and returns to the For statement, but this does not get executed because its value has gone beyond the "end" value of 5 specified here. MsgBox will display the value 15. In the above example, if the For statement is changed to "For n = 1 To 5 Step 2": The counter increments by the default step value of 2, and in the first loop (where n = 1), ntotal adds up to 1 (adds 1 to its initial value of zero); The Next statement increments the counter by 2 (n = 3) and returns to For statement, and in the second loop ntotal adds up to 4 (adds 3 to its previous value of 1); The Next statement increments the counter by 2 (n = 5) and returns to For statement, and in the third loop ntotal adds up to 9 (adds 5 to its previous value of 4); After executing the third loop, the Next statement increments the counter (ie. n) value to 7 and returns to the For statement, but this does not get executed because its value has gone beyond the "end" value of 5 specified here. MsgBox will display the value 9. Negative step values (count backword from a higher to a lower value): in the above example, the For statement is changed to "For n = 5 To 1 Step -1": In this example, the counter decrements by the step value of -1, and in the first loop (where n = 5), ntotal adds up to 5 (adds 5 to its initial value of zero); The Next statement decrements the counter by -1 (n = 4) and returns to For statement, and in the second loop ntotal adds up to 9 (adds 4 to its previous value of 5); The Next statement decrements the counter by -1 (n = 3) and returns to For statement, and in the third loop ntotal adds up to 12 (adds 3 to its previous value of 9); The Next statement decrements the counter by -1 (n = 2) and returns to For statement, and in the fourth loop ntotal adds up to 14 (adds 2 to its previous value of 12); The Next statement decrements the counter by -1 (n = 1) and returns to For statement, and in the fifth loop ntotal adds up to 15 (adds 1 to its previous value of 14); No. 9, 1 st Floor, 8 th Main, 9 th Cross, SBM Colony, Brindavan Nagar, Mathikere, Bangalore Page: 5

6 After executing the fifth loop, the Next statement decrements the counter (ie. n) value to -1 and returns to the For statement, but this does not get executed because its value has gone beyond the "end" value of 1 specified here. MsgBox will display the value 15. The For Each Next Statements The For Each Next Loop repeats a block of code for each object in a group. It repeats execution of a block of code, for each element of a collection. The loop stops when all the elements in the collection have been covered, and execution moves to the section of code immediately following the Next statement. For Each object_variable In group_object_variable [block of code] Next object_variable Example: This loops through each worksheet in the workbook, and the code protects each with a password. Here, ws is the Worksheet Object variable, and the group or collection are all the Worksheets in this Workbook. Sub foreach1() Dim ws As Worksheet For Each ws In ThisWorkbook.Worksheets ws.protect Password:="123" Next ws No. 9, 1 st Floor, 8 th Main, 9 th Cross, SBM Colony, Brindavan Nagar, Mathikere, Bangalore Page: 6

7 Example: This loops through each cell in the Range("A1:A10"), and the code sets background color of yellow in each. Here, icell is the Range Object variable, and the group or collection are all Cells in the Range("A1:A10"). Sub foreach2() Dim icell As Range For Each icell In ActiveSheet.Range("A1:A10") icell.interior.color = RGB(255, 255, 0) Next icell Nesting Loops: You can nest loops by putting one loop within another loop, upto unlimited number of times. The counter variable for each loop must be unique. You can nest one kind of loop within another different kind of loop. In a For Loop, it is necessary that the inner loop be completed before the Next statement of the outer loop is encountered. You can also nest one kind of control structure within another kind viz. you can nest an IF statement within a WITH block which can itself be nested within a For... Each Loop. However, control structures cannot be overlapped viz. each nested block has to close & terminate within its outer nested level. Example: Example of nesting an IF statement within a WITH block which is nested within a For... Each Loop. The code loops through each cell in the range A1:A10, and if cell value exceeds 5, the background color of that cell is set as Yellow, else Red for values of 5 and less. Sub nestingloops() Dim icell As Range For Each icell In ActiveSheet.Range("A1:A10") With icell No. 9, 1 st Floor, 8 th Main, 9 th Cross, SBM Colony, Brindavan Nagar, Mathikere, Bangalore Page: 7

8 If icell > 5 Then.Interior.Color = RGB(255, 255, 0) Else.Interior.Color = RGB(255, 0, 0) End With Next icell The Exit For Statement You can exit the For Loop (both For... Next and For Each... Next Statements) early, without completing the full cycle, by using the Exit For statement. The Exit For statement will immediately stop execution of the existing loop and execute the section of code immediately following the Next statement, and in the case of inner nested level it will stop and execute the next outer nested level. You can have any number of Exit For statements in a loop. It is particularly useful in case you want to terminate the loop on reaching a certain value or satisfying a specific condition, or in case you want to terminate an endless loop at a certain point. Example: If Range ("A1") is blank, ntotal will add up to the value 55. If Range("A1") contains the value 5, the loop will terminate and exit when the counter (ie. n) reaches 5, and ntotal will add up to 15 (Note that the loop runs for the counter value of 5, and thereafter exits the loop). Sub exitfor1() Dim n As Integer Dim ntotal As Integer ntotal = 0 For n = 1 To 10 ntotal = n + ntotal If n = ActiveSheet.Range("A1") Then No. 9, 1 st Floor, 8 th Main, 9 th Cross, SBM Colony, Brindavan Nagar, Mathikere, Bangalore Page: 8

9 Exit For Next n MsgBox ntotal The Do While Loop The Do While Loop Statements; The Do Loop While Statements The Do While Loop repeats a block of code indefinitely while the specified condition continues to be met and evaluated to True, and stops when the condition turns False. The condition can be tested either at the start or at the end of the Loop. "The Do While Loop Statements" test the condition at the start, while "The Do Loop While Statements" test the condition at the end of the Loop. If the condition is tested at the start of the Loop, the block of code does not execute if the condition is not met initially (and the loop does not run even once) whereas if the condition is tested at the end, the Loop runs atleast once. The Do While Loop Statements (The condition is tested at the start, in this Loop) Do While [Condition] [block of code] Loop The Do Loop While Statements (The condition is tested at the end, in this Loop) Do [block of code] Loop While [Condition] These two statements are explained with the help of examples. No. 9, 1 st Floor, 8 th Main, 9 th Cross, SBM Colony, Brindavan Nagar, Mathikere, Bangalore Page: 9

10 Example 1: The condition (n>5) is tested at the start, and because it is not met, the loop does not execute even once. ntotal will return zero. Sub dowhile1() Dim n As Integer Dim ntotal As Integer n = 5 ntotal = 0 Do While n > 5 ntotal = n + ntotal n = n - 1 Loop MsgBox ntotal Example 2: The condition (n>5) is tested at the end, and because it is met, the loop executes but only once after which the value of n reduces to 4 and the Loop ends. ntotal returns the value 5. Sub dowhile2() Dim n As Integer Dim ntotal As Integer n = 5 ntotal = 0 Do No. 9, 1 st Floor, 8 th Main, 9 th Cross, SBM Colony, Brindavan Nagar, Mathikere, Bangalore Page: 10

11 ntotal = n + ntotal n = n - 1 Loop While n > 5 MsgBox ntotal Example 3: Replace blank spaces with underscores in a Range of Cells, using VBA loops; or Remove blank spaces in a Range of Cells, using VBA loops. Sub dowhile3() 'Replace blank spaces with underscores in a Range of Cells, using VBA loops; or 'Remove blank spaces in a Range of Cells, using VBA loops. Dim icell As Range Dim textstring As String Dim n As Integer 'icell is a Cell in the specified Range which contains the textstring 'textstring is the text in a Cell in which blank spaces are to be replaced with underscores 'n is the position of blank space(s) occurring in a textstring For Each icell In ActiveSheet.Range("A1:A5") textstring = icell n = InStr(textString, " ") 'The VBA InStr function returns the position of the first occurrence of a string within another string. Using this to determine the position of the first blank space in the textstring. Do While n > 0 textstring = Left(textString, n - 1) & "_" & Right(textString, Len(textString) - n) 'blank space is replaced with the underscore character in the textstring No. 9, 1 st Floor, 8 th Main, 9 th Cross, SBM Colony, Brindavan Nagar, Mathikere, Bangalore Page: 11

12 'textstring = Left(textString, n - 1) & Right(textString, Len(textString) - n) 'Use this line of code instead of the preceding line, to remove all blank spaces in the textstring n = InStr(textString, " ") Loop icell = textstring Next The Exit Do Statement You can exit the Do While Loop early, without completing the full cycle, by using the Exit Do statement. The Exit Do statement will immediately stop execution of the existing loop and execute the section of code immediately following the Loop statement, and in the case of inner nested level it will stop and execute the next outer nested level. You can have any number of Exit Do statements in a loop. It is particularly useful in case you want to terminate the loop on reaching a certain value or satisfying a specific condition, or in case you want to terminate an endless loop at a certain point. It is similar to the Exit For statement used to exit the For Loop. Example: If Range ("A1") is blank, ntotal will add up to the value 55. If Range("A1") contains the value 5, the loop will terminate and exit when the counter (ie. n) reaches 5, and ntotal will add up to 10 (Note that the loop does not run for the counter value of 5, and exits the loop on reaching this value). Sub exitdo1() Dim n As Integer Dim ntotal As Integer ntotal = 0 Do While n < 11 ntotal = n + ntotal No. 9, 1 st Floor, 8 th Main, 9 th Cross, SBM Colony, Brindavan Nagar, Mathikere, Bangalore Page: 12

13 n = n + 1 If n = ActiveSheet.Range("A1") Then Exit Do Loop MsgBox ntotal The Do Until Loop The Do Until Loop Statements; The Do Loop Until Statements The Do Until Loop repeats a block of code indefinitely until the condition is met and evaluates to True. The condition can be tested either at the start or at the end of the Loop. "The Do Until Loop Statements" test the condition at the start, while "The Do Loop UntilStatements" test the condition at the end of the Loop. If the condition is tested at the start of the Loop, the block of code does not execute if the condition is met initially itself (and the loop does not run even once) whereas if the condition is tested at the end, the Loop runs atleast once. The Do Until Loop Statements (The condition is tested at the start, in this Loop) Do Until [Condition] [block of code] Loop The Do Loop Until Statements (The condition is tested at the end, in this Loop) Do [block of code] Loop Until [Condition] No. 9, 1 st Floor, 8 th Main, 9 th Cross, SBM Colony, Brindavan Nagar, Mathikere, Bangalore Page: 13

14 These two statements are explained with the help of examples. Example 1: Sub dountil1() 'Colors the empty cells yellow, until a non-empty cell is encountered. If the first cell is not empty, the code will not execute because the condition of "Not Empty" is mentioned at the start of the loop. Dim rowno As Integer rowno = 1 Do Until Not IsEmpty(Cells(rowNo, 1)) Cells(rowNo, 1).Interior.Color = RGB(255, 255, 0) rowno = rowno + 1 Loop Example 2: Sub dountil2() 'Colors the empty cells yellow, until a non-empty cell is encountered. If the first cell is not empty, the code will still execute atleast once because the condition of "Not Empty" is mentioned at the end of the loop. Dim rowno As Integer rowno = 1 Do Cells(rowNo, 1).Interior.Color = RGB(255, 255, 0) rowno = rowno + 1 Loop Until Not IsEmpty(Cells(rowNo, 1)) No. 9, 1 st Floor, 8 th Main, 9 th Cross, SBM Colony, Brindavan Nagar, Mathikere, Bangalore Page: 14

15 The Exit Do Statement You can exit the Do Until Loop early, without completing the full cycle, by using the Exit Do statement. It is similar to as in the Do WhileLoop, mentioned above. No. 9, 1 st Floor, 8 th Main, 9 th Cross, SBM Colony, Brindavan Nagar, Mathikere, Bangalore Page: 15

16 More Examples of using VBA Loops: Image 1 Sub loopexample1() 'enter +ive and -ive numbers alternatively, in a column. Refer Image 1. Dim n As Integer For n = 1 To 10 Step 2 ActiveSheet.Cells(n, 1) = n * 2 Next n For n = 2 To 10 Step 2 ActiveSheet.Cells(n, 1) = n * -2 Next n No. 9, 1 st Floor, 8 th Main, 9 th Cross, SBM Colony, Brindavan Nagar, Mathikere, Bangalore Page: 16

17 Image 2 Sub loopexample2() 'enter numbers in even rows only. Refer Image 2. Dim n As Integer n = 1 Do While n < 11 If n Mod 2 = 0 Then ActiveSheet.Cells(n, 1) = n * 3 n = n + 1 Loop No. 9, 1 st Floor, 8 th Main, 9 th Cross, SBM Colony, Brindavan Nagar, Mathikere, Bangalore Page: 17

18 Image 3 Sub pyramidex1() 'Create a number pyramid with VBA loops. Refer Image 3. Dim irow As Integer, n As Integer, itext As String For irow = 1 To 5 'indicates number of rows For n = 1 To irow 'each row is having number of digits which equal to the row number itext = itext & irow Next n If irow < 5 Then 'to avoid creating line feed after the fifth row itext = itext & vbcrlf Next irow ActiveSheet.Range("A15") = itext 'MsgBox itext No. 9, 1 st Floor, 8 th Main, 9 th Cross, SBM Colony, Brindavan Nagar, Mathikere, Bangalore Page: 18

19 Image 4 Sub pyramidex2() 'Create a number pyramid with VBA loops. Refer Image 4. Dim irow As Integer, n As Integer, itext As String irow = 5 'indicates number of rows For n = 1 To irow 'each row is having equal number of digits as the row number If n < irow Then 'to avoid creating line feed after the last row itext = itext & String(n, Format(n, "0")) & vbcrlf 'The VBA "String" function creates a string consisting of a single character repeated a specified number of times. Note that the VBA function of Format() returns a string/text value. Else itext = itext & String(n, Format(n, "0")) Next n ActiveSheet.Range("A17") = itext 'MsgBox itext No. 9, 1 st Floor, 8 th Main, 9 th Cross, SBM Colony, Brindavan Nagar, Mathikere, Bangalore Page: 19

20 Image 5 Sub pyramidex3() 'Create a number pyramid with VBA loops. Refer Image 5. Dim irow As Integer, n As Integer, itext As String For irow = 1 To 5 For n = 1 To irow itext = itext & irow * 2-1 Next n If irow < 5 Then itext = itext & Chr(10) 'Chr(10) provides line feed/new line Next irow ActiveSheet.Range("A21") = itext 'MsgBox itext No. 9, 1 st Floor, 8 th Main, 9 th Cross, SBM Colony, Brindavan Nagar, Mathikere, Bangalore Page: 20

21 Image 6 Sub pyramidex4() 'Create a number pyramid with VBA loops. Refer Image 6. Dim irow As Integer, n As Integer, itext As String For irow = 5 To 1 Step -1 For n = 1 To irow itext = itext & irow Next n If irow > 1 Then itext = itext & vbcrlf Next irow ActiveSheet.Range("A23") = itext 'MsgBox itext No. 9, 1 st Floor, 8 th Main, 9 th Cross, SBM Colony, Brindavan Nagar, Mathikere, Bangalore Page: 21

22 Image 7 Sub pyramidex5() 'Create a number pyramid with VBA loops. Refer Image 7. Dim irow As Integer, n As Integer, m As Integer, itext As String For irow = 1 To 5 m = irow For n = 1 To irow itext = itext & m & " " m = m + 1 Next n If irow < 5 Then itext = itext & vbcrlf Next irow ActiveSheet.Range("A25") = itext 'MsgBox itext No. 9, 1 st Floor, 8 th Main, 9 th Cross, SBM Colony, Brindavan Nagar, Mathikere, Bangalore Page: 22

23 Image 8 Sub pyramidex6() 'Create a number pyramid with VBA loops. Refer Image 8. Dim irow As Integer, n As Integer, m As Integer, itext As String m = 1 For irow = 1 To 4 For n = 1 To irow itext = itext & m & " " m = m + 1 Next n If irow < 4 Then itext = itext & vbcrlf Next irow ActiveSheet.Range("A27") = itext 'MsgBox itext No. 9, 1 st Floor, 8 th Main, 9 th Cross, SBM Colony, Brindavan Nagar, Mathikere, Bangalore Page: 23

24 Image 9 Sub pyramidex7() 'Create a number pyramid with VBA loops. Refer Image 9. Dim irow As Integer, n As Integer, m As Integer, itext As String For irow = 1 To 5 m = irow For n = 1 To irow itext = itext & m & " " m = m + 2 Next n If irow < 5 Then itext = itext & vbcrlf Next irow ActiveSheet.Range("A29") = itext 'MsgBox itext No. 9, 1 st Floor, 8 th Main, 9 th Cross, SBM Colony, Brindavan Nagar, Mathikere, Bangalore Page: 24

25 Image 10 Sub pyramidex8() 'Create a pyramid with VBA loops. Refer Image 10. Dim irow As Integer, n As Integer, itext As String irow = 5 For n = 1 To irow If n < irow Then 'to avoid creating line feed after the last row itext = itext & String(n, "#") & Chr(10) 'The VBA "String" function creates a string consisting of a single character repeated a specified number of times. Chr(10) provides line feed/new line. Else itext = itext & String(n, "#") Next ActiveSheet.Range("A31") = itext 'MsgBox itext No. 9, 1 st Floor, 8 th Main, 9 th Cross, SBM Colony, Brindavan Nagar, Mathikere, Bangalore Page: 25

26 Image 11 Sub pyramidex9() 'Create a pyramid with VBA loops. Refer Image 11. Dim irow As Integer, n As Integer, itext As String irow = 5 For n = 1 To irow * 2 Step 2 irow = irow - 1 If n < 8 Then itext = itext & String(iRow, "-") & String(n, "*") & vbcrlf Else itext = itext & String(iRow, "-") & String(n, "*") Next ActiveSheet.Range("A33") = itext 'MsgBox itext No. 9, 1 st Floor, 8 th Main, 9 th Cross, SBM Colony, Brindavan Nagar, Mathikere, Bangalore Page: 26

27 Sub palindromecheck1() 'Code to check if string is a Palindrome. A palindrome is a word, phrase, number, line or sequence that reads the same forward as it does backward. 'Note: Code does not differentiate upper and lower case, and does not ignore spacing. 'This code divides the text length by 2 and checks letters on each side with the other, to determine if text is Palindrome or not. Dim itext As String, n As Integer itext = "Racecar" itext = UCase(iText) 'remove this line to make the check case-sensitive For n = 1 To Len(iText) / 2 'divide text length by 2 to check letters on each side with the other If Mid(iText, n, 1) <> Mid(iText, Len(iText) - n + 1, 1) Then MsgBox "Not a Palindrome" Exit Sub Next n MsgBox "Palindrome" No. 9, 1 st Floor, 8 th Main, 9 th Cross, SBM Colony, Brindavan Nagar, Mathikere, Bangalore Page: 27

28 Sub palindromecheck2() 'Code to check if string is a Palindrome. A palindrome is a word, phrase, number, line or sequence that reads the same forward as it does backward. 'Note: Code does not differentiate upper and lower case, and does not ignore spacing. 'This code builds the reverse text and checks the original and reverse texts, to determine if Palindrome or not. Dim itext As String, n As Integer itext = "Level" itext = LCase(iText) 'remove this line to make the check case-sensitive revtext = "" For n = Len(iText) To 1 Step -1 revtext = revtext & Mid(iText, n, 1) 'building the reverse text to compare with original text Next n If itext = revtext Then MsgBox "Palindrome" Else MsgBox "Not a Palindrome" No. 9, 1 st Floor, 8 th Main, 9 th Cross, SBM Colony, Brindavan Nagar, Mathikere, Bangalore Page: 28

LmÉPï C Á npï À ƵÀ ïì itech Analytic Solutions

LmÉPï C Á npï À ƵÀ ïì itech Analytic Solutions LmÉPï C Á npï À ƵÀ ïì itech Analytic Solutions No. 9, 1st Floor, 8th Main, 9th Cross, SBM Colony, Brindavan Nagar, Mathikere, Bangalore 560 054 Email: itechanalytcisolutions@gmail.com Website: www.itechanalytcisolutions.com

More information

LmÉPï C Á npï À ƵÀ ïì itech Analytic Solutions

LmÉPï C Á npï À ƵÀ ïì itech Analytic Solutions LmÉPï C Á npï À ƵÀ ïì itech Analytic Solutions No. 9, 1st Floor, 8th Main, 9th Cross, SBM Colony, Brindavan Nagar, Mathikere, Bangalore 560 054 Email: itechanalytcisolutions@gmail.com Website: www.itechanalytcisolutions.com

More information

LmÉPï C Á npï À ƵÀ ïì itech Analytic Solutions

LmÉPï C Á npï À ƵÀ ïì itech Analytic Solutions LmÉPï C Á npï À ƵÀ ïì itech Analytic Solutions No. 9, 1st Floor, 8th Main, 9th Cross, SBM Colony, Brindavan Nagar, Mathikere, Bangalore 560 054 Email: itechanalytcisolutions@gmail.com Website: www.itechanalytcisolutions.com

More information

LmÉPï C Á npï À ƵÀ ïì itech Analytic Solutions

LmÉPï C Á npï À ƵÀ ïì itech Analytic Solutions LmÉPï C Á npï À ƵÀ ïì itech Analytic Solutions No. 9, 1st Floor, 8th Main, 9th Cross, SBM Colony, Brindavan Nagar, Mathikere, Bangalore 560 054 Email: itechanalytcisolutions@gmail.com Website: www.itechanalytcisolutions.com

More information

LmÉPï C Á npï À ƵÀ ïì itech Analytic Solutions

LmÉPï C Á npï À ƵÀ ïì itech Analytic Solutions LmÉPï C Á npï À ƵÀ ïì itech Analytic Solutions No. 9, 1st Floor, 8th Main, 9th Cross, SBM Colony, Brindavan Nagar, Mathikere, Bangalore 560 054 Email: itechanalytcisolutions@gmail.com Website: www.itechanalytcisolutions.com

More information

LmÉPï C Á npï À ƵÀ ïì itech Analytic Solutions

LmÉPï C Á npï À ƵÀ ïì itech Analytic Solutions LmÉPï C Á npï À ƵÀ ïì itech Analytic Solutions No. 9, 1st Floor, 8th Main, 9th Cross, SBM Colony, Brindavan Nagar, Mathikere, Bangalore 560 054 Email: itechanalytcisolutions@gmail.com Website: www.itechanalytcisolutions.com

More information

LmÉPï C Á npï À ƵÀ ïì itech Analytic Solutions

LmÉPï C Á npï À ƵÀ ïì itech Analytic Solutions LmÉPï C Á npï À ƵÀ ïì itech Analytic Solutions No. 9, 1st Floor, 8th Main, 9th Cross, SBM Colony, Brindavan Nagar, Mathikere, Bangalore 560 054 Email: itechanalytcisolutions@gmail.com Website: www.itechanalytcisolutions.com

More information

Sébastien Mathier wwwexcel-pratiquecom/en While : Loops make it possible to repeat instructions a number of times, which can save a lot of time The following code puts sequential numbers into each of the

More information

How to Create a For Next Loop in Excel VBA!

How to Create a For Next Loop in Excel VBA! Often when writing VBA code, one may need to repeat the same action or series of actions more than a couple of times. One could, in this case, write each action over and over in one s code or alternatively

More information

The For Next and For Each Loops Explained for VBA & Excel

The For Next and For Each Loops Explained for VBA & Excel The For Next and For Each Loops Explained for VBA & Excel excelcampus.com /vba/for-each-next-loop/ 16 Bottom line: The For Next Loops are some of the most powerful VBA macro coding techniques for automating

More information

Working with Database & Objects

Working with Database & Objects Working with Database & Objects Working with Database & Objects Introduction Each Access database consists of multiple objects that let you interact with data. Databases can include forms for entering

More information

LmÉPï C Á npï À ƵÀ ïì itech Analytic Solutions

LmÉPï C Á npï À ƵÀ ïì itech Analytic Solutions LmÉPï C Á npï À ƵÀ ïì itech Analytic Solutions No. 9, 1st Floor, 8th Main, 9th Cross, SBM Colony, Brindavan Nagar, Mathikere, Bangalore 560 054 Email: itechanalytcisolutions@gmail.com Website: www.itechanalytcisolutions.com

More information

Chapter 4: Control structures. Repetition

Chapter 4: Control structures. Repetition Chapter 4: Control structures Repetition Loop Statements After reading and studying this Section, student should be able to Implement repetition control in a program using while statements. Implement repetition

More information

Ms Excel Vba Continue Loop Through Range Of

Ms Excel Vba Continue Loop Through Range Of Ms Excel Vba Continue Loop Through Range Of Rows Learn how to make your VBA code dynamic by coding in a way that allows your 5 Different Ways to Find The Last Row or Last Column Using VBA In Microsoft

More information

Chapter 4: Control structures

Chapter 4: Control structures Chapter 4: Control structures Repetition Loop Statements After reading and studying this Section, student should be able to Implement repetition control in a program using while statements. Implement repetition

More information

Agenda. Strings 30/10/2009 INTRODUCTION TO VBA PROGRAMMING. Strings Iterative constructs

Agenda. Strings 30/10/2009 INTRODUCTION TO VBA PROGRAMMING. Strings Iterative constructs INTRODUCTION TO VBA PROGRAMMING LESSON5 dario.bonino@polito.it Agenda Strings Iterative constructs For Next Do Loop Do While Loop Do Loop While Do Until Loop Do Loop Until Strings 1 Strings Variables that

More information

Control Statements Selection (Conditional Logic)

Control Statements Selection (Conditional Logic) Control Statements Selection (Conditional Logic) INTRODUCTION In the last few weeks, you were introduced to the concept of flow of control: the sequence of statements that the computer executes. In procedurally

More information

While you can always enter data directly into database tables, you might find it easier to use

While you can always enter data directly into database tables, you might find it easier to use Forms Forms Introduction While you can always enter data directly into database tables, you might find it easier to use forms. Forms ensure you're entering the right data in the right location and format.

More information

B.V. Patel Institute of Business Management, Computer & Information Technology, Uka Tarsadia University

B.V. Patel Institute of Business Management, Computer & Information Technology, Uka Tarsadia University Unit 1 Programming Language and Overview of C 1. State whether the following statements are true or false. a. Every line in a C program should end with a semicolon. b. In C language lowercase letters are

More information

3. (1.0 point) To quickly switch to the Visual Basic Editor, press on your keyboard. a. Esc + F1 b. Ctrl + F7 c. Alt + F11 d.

3. (1.0 point) To quickly switch to the Visual Basic Editor, press on your keyboard. a. Esc + F1 b. Ctrl + F7 c. Alt + F11 d. Excel Tutorial 12 1. (1.0 point) Excel macros are written in the programming language. a. Perl b. JavaScript c. HTML d. VBA 2. (1.0 point) To edit a VBA macro, you need to use the Visual Basic. a. Manager

More information

Chapter 4 C Program Control

Chapter 4 C Program Control 1 Chapter 4 C Program Control Copyright 2007 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 2 Chapter 4 C Program Control Outline 4.1 Introduction 4.2 The Essentials of Repetition

More information

Sequence structure. The computer executes java statements one after the other in the order in which they are written. Total = total +grade;

Sequence structure. The computer executes java statements one after the other in the order in which they are written. Total = total +grade; Control Statements Control Statements All programs could be written in terms of only one of three control structures: Sequence Structure Selection Structure Repetition Structure Sequence structure The

More information

Chapter 1 CONTROL STRUCTURES. SYS-ED/ Computer Education Techniques, Inc.

Chapter 1 CONTROL STRUCTURES. SYS-ED/ Computer Education Techniques, Inc. Chapter 1 CONTROL STRUCTURES SYS-ED/ Computer Education Techniques, Inc. ORACLE: PL/SQL: Programming - Advanced Objectives You will learn: Uses and types of control structures. Constructing an IF statement.

More information

IDENTIFYING UNIQUE VALUES IN AN ARRAY OR RANGE (VBA)

IDENTIFYING UNIQUE VALUES IN AN ARRAY OR RANGE (VBA) Date: 20/11/2012 Procedure: Identifying Unique Values In An Array Or Range (VBA) Source: LINK Permalink: LINK Created by: HeelpBook Staff Document Version: 1.0 IDENTIFYING UNIQUE VALUES IN AN ARRAY OR

More information

Unit 7. Lesson 7.1. Loop. For Next Statements. Introduction. Loop

Unit 7. Lesson 7.1. Loop. For Next Statements. Introduction. Loop Loop Unit 7 Loop Introduction So far we have seen that each instruction is executed once and once only. Some time we may require that a group of instructions be executed repeatedly, until some logical

More information

STUDENT LESSON A12 Iterations

STUDENT LESSON A12 Iterations STUDENT LESSON A12 Iterations Java Curriculum for AP Computer Science, Student Lesson A12 1 STUDENT LESSON A12 Iterations INTRODUCTION: Solving problems on a computer very often requires a repetition of

More information

Ms Excel Vba Continue Loop Through Columns Range

Ms Excel Vba Continue Loop Through Columns Range Ms Excel Vba Continue Loop Through Columns Range Learn how to make your VBA code dynamic by coding in a way that allows your 5 Different Ways to Find The Last Row or Last Column Using VBA In Microsoft

More information

REPETITION CONTROL STRUCTURE LOGO

REPETITION CONTROL STRUCTURE LOGO CSC 128: FUNDAMENTALS OF COMPUTER PROBLEM SOLVING REPETITION CONTROL STRUCTURE 1 Contents 1 Introduction 2 for loop 3 while loop 4 do while loop 2 Introduction It is used when a statement or a block of

More information

[Page 177 (continued)] a. if ( age >= 65 ); cout << "Age is greater than or equal to 65" << endl; else cout << "Age is less than 65 << endl";

[Page 177 (continued)] a. if ( age >= 65 ); cout << Age is greater than or equal to 65 << endl; else cout << Age is less than 65 << endl; Page 1 of 10 [Page 177 (continued)] Exercises 4.11 Identify and correct the error(s) in each of the following: a. if ( age >= 65 ); cout

More information

VBA Collections A Group of Similar Objects that Share Common Properties, Methods and

VBA Collections A Group of Similar Objects that Share Common Properties, Methods and VBA AND MACROS VBA is a major division of the stand-alone Visual Basic programming language. It is integrated into Microsoft Office applications. It is the macro language of Microsoft Office Suite. Previously

More information

VBA Handout. References, tutorials, books. Code basics. Conditional statements. Dim myvar As <Type >

VBA Handout. References, tutorials, books. Code basics. Conditional statements. Dim myvar As <Type > VBA Handout References, tutorials, books Excel and VBA tutorials Excel VBA Made Easy (Book) Excel 2013 Power Programming with VBA (online library reference) VBA for Modelers (Book on Amazon) Code basics

More information

C++ Programming: From Problem Analysis to Program Design, Third Edition

C++ Programming: From Problem Analysis to Program Design, Third Edition C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 5: Control Structures II (Repetition) Why Is Repetition Needed? Repetition allows you to efficiently use variables Can input,

More information

How to Use Do While Loop in Excel VBA

How to Use Do While Loop in Excel VBA We have already covered an introduction to looping and the simplest type of loops, namely the For Next Loop and the For Each Next Loop, in previous tutorials. We discovered that the For Next Loop and the

More information

Chapter 2: Functions and Control Structures

Chapter 2: Functions and Control Structures Chapter 2: Functions and Control Structures TRUE/FALSE 1. A function definition contains the lines of code that make up a function. T PTS: 1 REF: 75 2. Functions are placed within parentheses that follow

More information

Outline. Midterm Review. Using Excel. Midterm Review: Excel Basics. Using VBA. Sample Exam Question. Midterm Review April 4, 2014

Outline. Midterm Review. Using Excel. Midterm Review: Excel Basics. Using VBA. Sample Exam Question. Midterm Review April 4, 2014 Midterm Review Larry Caretto Mechanical Engineering 209 Computer Programming for Mechanical Engineers April 4, 2017 Outline Excel spreadsheet basics Use of VBA functions and subs Declaring/using variables

More information

Computer Programming: C++

Computer Programming: C++ The Islamic University of Gaza Engineering Faculty Department of Computer Engineering Fall 2017 ECOM 2003 Muath i.alnabris Computer Programming: C++ Experiment #4 Loops Part II Contents Loop Control Statement

More information

Appendix A1 Visual Basics for Applications (VBA)

Appendix A1 Visual Basics for Applications (VBA) Credit Risk Modeling Using Excel and VBA with DVD By Gunter Löffler and Peter N. Posch 2011 John Wiley & Sons, Ltd. Appendix A1 Visual Basics for Applications (VBA) MACROS AND FUNCTIONS In this book, we

More information

3 The L oop Control Structure

3 The L oop Control Structure 3 The L oop Control Structure Loops The while Loop Tips and Traps More Operators The for Loop Nesting of Loops Multiple Initialisations in the for Loop The Odd Loop The break Statement The continue Statement

More information

VBA Excel 2013/2016. VBA Visual Basic for Applications. Learner Guide

VBA Excel 2013/2016. VBA Visual Basic for Applications. Learner Guide VBA Visual Basic for Applications Learner Guide 1 Table of Contents SECTION 1 WORKING WITH MACROS...5 WORKING WITH MACROS...6 About Excel macros...6 Opening Excel (using Windows 7 or 10)...6 Recognizing

More information

Unit 6 - Software Design and Development LESSON 3 KEY FEATURES

Unit 6 - Software Design and Development LESSON 3 KEY FEATURES Unit 6 - Software Design and Development LESSON 3 KEY FEATURES Last session 1. Language generations. 2. Reasons why languages are used by organisations. 1. Proprietary or open source. 2. Features and tools.

More information

Unit 3 Decision making, Looping and Arrays

Unit 3 Decision making, Looping and Arrays Unit 3 Decision making, Looping and Arrays Decision Making During programming, we have a number of situations where we may have to change the order of execution of statements based on certain conditions.

More information

CSE 123 Introduction to Computing

CSE 123 Introduction to Computing CSE 123 Introduction to Computing Lecture 11 Programming with Arrays SPRING 2012 Assist. Prof. A. Evren Tugtas Array Variables Review For detailed information on array variables look at the notes of Lecture

More information

IF 1: 2: INDEX MATCH MATCH

IF 1: 2: INDEX MATCH MATCH How to Excel Part 3 Contents Exercise 1: Advanced IF formulas... 3 Exercise 2: INDEX MATCH MATCH... 6 Data validation... 7 Exercise 3 Recording Macros... 8 Setting up a Personal workbook... 10 Adding a

More information

You can record macros to automate tedious

You can record macros to automate tedious Introduction to Macros You can record macros to automate tedious and repetitive tasks in Excel without writing programming code directly. Macros are efficiency tools that enable you to perform repetitive

More information

9691 COMPUTING. 9691/23 Paper 2 (Written Paper), maximum raw mark 75

9691 COMPUTING. 9691/23 Paper 2 (Written Paper), maximum raw mark 75 CAMBRIDGE INTERNATIONAL EXAMINATIONS Cambridge International Advanced Subsidiary and Advanced Level MARK SCHEME for the May/June 2015 series 9691 COMPUTING 9691/23 Paper 2 (Written Paper), maximum raw

More information

MgtOp 470 Business Modeling with Spreadsheets Sample Midterm Exam. 1. Spreadsheets are known as the of business analysis.

MgtOp 470 Business Modeling with Spreadsheets Sample Midterm Exam. 1. Spreadsheets are known as the of business analysis. Section 1 Multiple Choice MgtOp 470 Business Modeling with Spreadsheets Sample Midterm Exam 1. Spreadsheets are known as the of business analysis. A. German motor car B. Mexican jumping bean C. Swiss army

More information

Introduction to VBA for Excel-Tutorial 7. The syntax to declare an array starts by using the Dim statement, such that:

Introduction to VBA for Excel-Tutorial 7. The syntax to declare an array starts by using the Dim statement, such that: Introduction to VBA for Excel-Tutorial 7 In this tutorial, you will learn deal with arrays. We will first review how to declare the arrays, then how to pass data in and how to output arrays to Excel environment.

More information

IS 320 A-C Page 1 Spring 99 Exam 2

IS 320 A-C Page 1 Spring 99 Exam 2 IS 320 A-C Page 1 Please use the space provided on the exam for your answers to the following questions. Note that question values are shown in parentheses. 1. (18) Consider the following user interface

More information

DATABASE AUTOMATION USING VBA (ADVANCED MICROSOFT ACCESS, X405.6)

DATABASE AUTOMATION USING VBA (ADVANCED MICROSOFT ACCESS, X405.6) Technology & Information Management Instructor: Michael Kremer, Ph.D. Database Program: Microsoft Access Series DATABASE AUTOMATION USING VBA (ADVANCED MICROSOFT ACCESS, X405.6) AGENDA 3. Executing VBA

More information

Lecture 7 Tao Wang 1

Lecture 7 Tao Wang 1 Lecture 7 Tao Wang 1 Objectives In this chapter, you will learn about: Interactive loop break and continue do-while for loop Common programming errors Scientists, Third Edition 2 while Loops while statement

More information

Control Statements: Part 1

Control Statements: Part 1 4 Let s all move one place on. Lewis Carroll Control Statements: Part 1 The wheel is come full circle. William Shakespeare How many apples fell on Newton s head before he took the hint! Robert Frost All

More information

Chapter 2.4: Common facilities of procedural languages

Chapter 2.4: Common facilities of procedural languages Chapter 2.4: Common facilities of procedural languages 2.4 (a) Understand and use assignment statements. Assignment An assignment is an instruction in a program that places a value into a specified variable.

More information

1. In the accompanying figure, the months were rotated by selecting the text and dragging the mouse pointer up and to the right.

1. In the accompanying figure, the months were rotated by selecting the text and dragging the mouse pointer up and to the right. Excel: Chapter 3 True/False Indicate whether the statement is true or false. Figure 3-3 1. In the accompanying figure, the months were rotated by selecting the text and dragging the mouse pointer up and

More information

Loop Structures. Loop Structures. Algorithm to record 5 TV programmes. Recall Structured Programming..3 basic control structures.

Loop Structures. Loop Structures. Algorithm to record 5 TV programmes. Recall Structured Programming..3 basic control structures. Loop Structures Recall Structured Programming..3 basic control structures Sequence Input -> Process -> Output Selection IF ENDIF SELECT CASE END SELECT Loop Structures DO WHILE LOOP DO LOOP UNTIL FOR NEXT

More information

Structured Program Development

Structured Program Development Structured Program Development Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan Outline Introduction The selection statement if if.else switch The

More information

\n is used in a string to indicate the newline character. An expression produces data. The simplest expression

\n is used in a string to indicate the newline character. An expression produces data. The simplest expression Chapter 1 Summary Comments are indicated by a hash sign # (also known as the pound or number sign). Text to the right of the hash sign is ignored. (But, hash loses its special meaning if it is part of

More information

Unit 6 - Software Design and Development LESSON 3 KEY FEATURES

Unit 6 - Software Design and Development LESSON 3 KEY FEATURES Unit 6 - Software Design and Development LESSON 3 KEY FEATURES Last session 1. Language generations. 2. Reasons why languages are used by organisations. 1. Proprietary or open source. 2. Features and tools.

More information

C++ Programming: From Problem Analysis to Program Design, Fourth Edition. Chapter 5: Control Structures II (Repetition)

C++ Programming: From Problem Analysis to Program Design, Fourth Edition. Chapter 5: Control Structures II (Repetition) C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 5: Control Structures II (Repetition) Objectives In this chapter, you will: Learn about repetition (looping) control structures

More information

Download the files from you will use these files to finish the following exercises.

Download the files from  you will use these files to finish the following exercises. Exercise 6 Download the files from http://www.peter-lo.com/teaching/x4-xt-cdp-0071-a/source6.zip, you will use these files to finish the following exercises. 1. This exercise will guide you how to create

More information

Unit 3. Operators. School of Science and Technology INTRODUCTION

Unit 3. Operators. School of Science and Technology INTRODUCTION INTRODUCTION Operators Unit 3 In the previous units (unit 1 and 2) you have learned about the basics of computer programming, different data types, constants, keywords and basic structure of a C program.

More information

Loops and Files. Chapter 04 MIT 12043, Fundamentals of Programming By: S. Sabraz Nawaz

Loops and Files. Chapter 04 MIT 12043, Fundamentals of Programming By: S. Sabraz Nawaz Loops and Files Chapter 04 MIT 12043, Fundamentals of Programming By: S. Sabraz Nawaz Chapter Topics o The Increment and Decrement Operators o The while Loop o Shorthand Assignment Operators o The do-while

More information

Introduction. C provides two styles of flow control:

Introduction. C provides two styles of flow control: Introduction C provides two styles of flow control: Branching Looping Branching is deciding what actions to take and looping is deciding how many times to take a certain action. Branching constructs: if

More information

INTRODUCTION TO C++ PROGRAM CONTROL. Dept. of Electronic Engineering, NCHU. Original slides are from

INTRODUCTION TO C++ PROGRAM CONTROL. Dept. of Electronic Engineering, NCHU. Original slides are from INTRODUCTION TO C++ PROGRAM CONTROL Original slides are from http://sites.google.com/site/progntut/ Dept. of Electronic Engineering, NCHU Outline 2 Repetition Statement for while do.. while break and continue

More information

Chapter 5: Control Structures II (Repetition)

Chapter 5: Control Structures II (Repetition) Chapter 5: Control Structures II (Repetition) 1 Objectives Learn about repetition (looping) control structures Explore how to construct and use count-controlled, sentinel-controlled, flag-controlled, and

More information

LECTURE 5 Control Structures Part 2

LECTURE 5 Control Structures Part 2 LECTURE 5 Control Structures Part 2 REPETITION STATEMENTS Repetition statements are called loops, and are used to repeat the same code multiple times in succession. The number of repetitions is based on

More information

Mr.Khaled Anwar ( )

Mr.Khaled Anwar ( ) The Rnd() function generates random numbers. Every time Rnd() is executed, it returns a different random fraction (greater than or equal to 0 and less than 1). If you end execution and run the program

More information

Chapter 1 Summary. Chapter 2 Summary. end of a string, in which case the string can span multiple lines.

Chapter 1 Summary. Chapter 2 Summary. end of a string, in which case the string can span multiple lines. Chapter 1 Summary Comments are indicated by a hash sign # (also known as the pound or number sign). Text to the right of the hash sign is ignored. (But, hash loses its special meaning if it is part of

More information

MICROSOFT EXCEL 2000 LEVEL 5 VBA PROGRAMMING INTRODUCTION

MICROSOFT EXCEL 2000 LEVEL 5 VBA PROGRAMMING INTRODUCTION MICROSOFT EXCEL 2000 LEVEL 5 VBA PROGRAMMING INTRODUCTION Lesson 1 - Recording Macros Excel 2000: Level 5 (VBA Programming) Student Edition LESSON 1 - RECORDING MACROS... 4 Working with Visual Basic Applications...

More information

Lesson B Objectives IF/THEN. Chapter 4B: More Advanced PL/SQL Programming

Lesson B Objectives IF/THEN. Chapter 4B: More Advanced PL/SQL Programming Chapter 4B: More Advanced PL/SQL Programming Monday 2/23/2015 Abdou Illia MIS 4200 - Spring 2015 Lesson B Objectives After completing this lesson, you should be able to: Create PL/SQL decision control

More information

Module 4: Decision-making and forming loops

Module 4: Decision-making and forming loops 1 Module 4: Decision-making and forming loops 1. Introduction 2. Decision making 2.1. Simple if statement 2.2. The if else Statement 2.3. Nested if Statement 3. The switch case 4. Forming loops 4.1. The

More information

Using loops and debugging code

Using loops and debugging code Using loops and debugging code Chapter 7 Looping your code pp. 103-118 Exercises 7A & 7B Chapter 8 Fixing Bugs pp. 119-132 Exercise 8 Chapter 7 Looping your code Coding a For loop Coding a Do loop Chapter

More information

Learning the Language - V

Learning the Language - V Learning the Language - V Fundamentals We now have locations to store things so we need a way to get things into those storage locations To do that, we use assignment statements Deja Moo: The feeling that

More information

Why Is Repetition Needed?

Why Is Repetition Needed? Why Is Repetition Needed? Repetition allows efficient use of variables. It lets you process many values using a small number of variables. For example, to add five numbers: Inefficient way: Declare a variable

More information

V3 1/3/2015. Programming in C. Example 1. Example Ch 05 A 1. What if we want to process three different pairs of integers?

V3 1/3/2015. Programming in C. Example 1. Example Ch 05 A 1. What if we want to process three different pairs of integers? Programming in C 1 Example 1 What if we want to process three different pairs of integers? 2 Example 2 One solution is to copy and paste the necessary lines of code. Consider the following modification:

More information

Microsoft Excel 2010 Level 1

Microsoft Excel 2010 Level 1 Microsoft Excel 2010 Level 1 One Day Course Course Description You have basic computer skills such as using a mouse, navigating through windows, and surfing the Internet. You have also used paper-based

More information

Statements and Operators

Statements and Operators Statements and Operators Old Content - visit altium.com/documentation Mod ifi ed by Rob Eva ns on Feb 15, 201 7 Parent page: EnableBasic Enable Basic Statements Do...Loop Conditional statement that repeats

More information

You will have mastered the material in this chapter when you can:

You will have mastered the material in this chapter when you can: CHAPTER 6 Loop Structures OBJECTIVES You will have mastered the material in this chapter when you can: Add a MenuStrip object Use the InputBox function Display data using the ListBox object Understand

More information

Assessed Exercise 1 Working with ranges

Assessed Exercise 1 Working with ranges Week 3 Assessed Exercise 1 Working with ranges Multiple representations Different thing in different cases Single cell Collection of cells The handle to the thing you want to work with Many operations

More information

Sébastien Mathier wwwexcel-pratiquecom/en Arrays are "variables" that allow many values to be stored We have already covered this topic in Lesson 3, but now we will go into greater depth Why use arrays?

More information

IFA/QFN VBA Tutorial Notes prepared by Keith Wong

IFA/QFN VBA Tutorial Notes prepared by Keith Wong Chapter 2: Basic Visual Basic programming 2-1: What is Visual Basic IFA/QFN VBA Tutorial Notes prepared by Keith Wong BASIC is an acronym for Beginner's All-purpose Symbolic Instruction Code. It is a type

More information

Flow Control. CSC215 Lecture

Flow Control. CSC215 Lecture Flow Control CSC215 Lecture Outline Blocks and compound statements Conditional statements if - statement if-else - statement switch - statement? : opertator Nested conditional statements Repetitive statements

More information

Repetition CSC 121 Fall 2014 Howard Rosenthal

Repetition CSC 121 Fall 2014 Howard Rosenthal Repetition CSC 121 Fall 2014 Howard Rosenthal Lesson Goals Learn the following three repetition methods, their similarities and differences, and how to avoid common errors when using them: while do-while

More information

Chapter 4 C Program Control

Chapter 4 C Program Control Chapter C Program Control 1 Introduction 2 he Essentials of Repetition 3 Counter-Controlled Repetition he for Repetition Statement 5 he for Statement: Notes and Observations 6 Examples Using the for Statement

More information

Introduction to Visual Basic and Visual C++ Arithmetic Expression. Arithmetic Expression. Using Arithmetic Expression. Lesson 4.

Introduction to Visual Basic and Visual C++ Arithmetic Expression. Arithmetic Expression. Using Arithmetic Expression. Lesson 4. Introduction to Visual Basic and Visual C++ Arithmetic Expression Lesson 4 Calculation I154-1-A A @ Peter Lo 2010 1 I154-1-A A @ Peter Lo 2010 2 Arithmetic Expression Using Arithmetic Expression Calculations

More information

Repetition Structures

Repetition Structures Repetition Structures Chapter 5 Fall 2016, CSUS Introduction to Repetition Structures Chapter 5.1 1 Introduction to Repetition Structures A repetition structure causes a statement or set of statements

More information

Condition-Controlled Loop. Condition-Controlled Loop. If Statement. Various Forms. Conditional-Controlled Loop. Loop Caution.

Condition-Controlled Loop. Condition-Controlled Loop. If Statement. Various Forms. Conditional-Controlled Loop. Loop Caution. Repetition Structures Introduction to Repetition Structures Chapter 5 Spring 2016, CSUS Chapter 5.1 Introduction to Repetition Structures The Problems with Duplicate Code A repetition structure causes

More information

Relationship between Pointers and Arrays

Relationship between Pointers and Arrays Relationship between Pointers and Arrays Arrays and pointers are intimately related in C and often may be used interchangeably. An array name can be thought of as a constant pointer. Pointers can be used

More information

Fundamentals. Fundamentals. Fundamentals. We build up instructions from three types of materials

Fundamentals. Fundamentals. Fundamentals. We build up instructions from three types of materials Fundamentals We build up instructions from three types of materials Constants Expressions Fundamentals Constants are just that, they are values that don t change as our macros are executing Fundamentals

More information

Java Programming: Guided Learning with Early Objects Chapter 5 Control Structures II: Repetition

Java Programming: Guided Learning with Early Objects Chapter 5 Control Structures II: Repetition Java Programming: Guided Learning with Early Objects Chapter 5 Control Structures II: Repetition Learn about repetition (looping) control structures Explore how to construct and use: o Counter-controlled

More information

Microsoft Visual Basic 2015: Reloaded

Microsoft Visual Basic 2015: Reloaded Microsoft Visual Basic 2015: Reloaded Sixth Edition Chapter Seven More on the Repetition Structure Objectives After studying this chapter, you should be able to: Code a counter-controlled loop Nest repetition

More information

Repe$$on CSC 121 Fall 2015 Howard Rosenthal

Repe$$on CSC 121 Fall 2015 Howard Rosenthal Repe$$on CSC 121 Fall 2015 Howard Rosenthal Lesson Goals Learn the following three repetition methods, their similarities and differences, and how to avoid common errors when using them: while do-while

More information

Structured Programming. Dr. Mohamed Khedr Lecture 9

Structured Programming. Dr. Mohamed Khedr Lecture 9 Structured Programming Dr. Mohamed Khedr http://webmail.aast.edu/~khedr 1 Two Types of Loops count controlled loops repeat a specified number of times event-controlled loops some condition within the loop

More information

d2vbaref.doc Page 1 of 22 05/11/02 14:21

d2vbaref.doc Page 1 of 22 05/11/02 14:21 Database Design 2 1. VBA or Macros?... 2 1.1 Advantages of VBA:... 2 1.2 When to use macros... 3 1.3 From here...... 3 2. A simple event procedure... 4 2.1 The code explained... 4 2.2 How does the error

More information

L o o p s. for(initializing expression; control expression; step expression) { one or more statements }

L o o p s. for(initializing expression; control expression; step expression) { one or more statements } L o o p s Objective #1: Explain the importance of loops in programs. In order to write a non trivial computer program, you almost always need to use one or more loops. Loops allow your program to repeat

More information

Second Term ( ) Department of Computer Science Foundation Year Program Umm Al Qura University, Makkah

Second Term ( ) Department of Computer Science Foundation Year Program Umm Al Qura University, Makkah COMPUTER PROGRAMMING SKILLS (4800153-3) CHAPTER 5: REPETITION STRUCTURE Second Term (1437-1438) Department of Computer Science Foundation Year Program Umm Al Qura University, Makkah Table of Contents Objectives

More information

Cambridge International Examinations Cambridge International Advanced Subsidiary and Advanced Level

Cambridge International Examinations Cambridge International Advanced Subsidiary and Advanced Level Cambridge International Examinations Cambridge International Advanced Subsidiary and Advanced Level COMPUTER SCIENCE 9608/02 Paper 2 Fundamental Problem-solving and Programming Skills For Examination from

More information

Introduction to Arrays. Midterm Comments. Midterm Results. Midterm Comments II. Function Basics (Problem 2) Introduction to Arrays April 11, 2017

Introduction to Arrays. Midterm Comments. Midterm Results. Midterm Comments II. Function Basics (Problem 2) Introduction to Arrays April 11, 2017 Introduction to Arrays Larry Caretto Mechanical Engineering 209 Computer Programming for Mechanical Engineers 11, 2017 Outline Review midterm Array notation and declaration Minimum subscript for arrays

More information

Control Statements. Objectives. ELEC 206 Prof. Siripong Potisuk

Control Statements. Objectives. ELEC 206 Prof. Siripong Potisuk Control Statements ELEC 206 Prof. Siripong Potisuk 1 Objectives Learn how to change the flow of execution of a MATLAB program through some kind of a decision-making process within that program The program

More information

Java Programming: Guided Learning with Early Objects Chapter 5 Control Structures II: Repetition

Java Programming: Guided Learning with Early Objects Chapter 5 Control Structures II: Repetition Java Programming: Guided Learning with Early Objects Chapter 5 Control Structures II: Repetition Learn about repetition (looping) control structures Explore how to construct and use: o Counter-controlled

More information

Chapter 3 Structured Program Development

Chapter 3 Structured Program Development 1 Chapter 3 Structured Program Development Copyright 2007 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 3 - Structured Program Development Outline 3.1 Introduction

More information