(1) state the condition under which a FOR-TO-NEXT loop will not be executed.

(2) With the aid of illustrative example, describe how a subroutine is implemented in BASIC.

You have not specified whether it is Visual Basic 6 or VB.net. In this case, the answers don't make a difference, but the versions will help to give a better context.

1. The format of the for-next loop statement is:
FOR i = start TO finish, [STEP s]
... statements to be executed
NEXT

On entering the loop, if the initial value of finish is greater than start, the statements inside the loop will not be executed at all.
However, if s is specified and is negative, the loop content will not be executed if start is less than finish.

Examples where the loop will not execute are:
FOR i=10 TO -1.... next
FOR k=1 TO 10 STEP -5... next

2. Example:
Here is an actual example from VB.net

Sub keypressed(ByVal o As [Object], ByVal e As KeyPressEventArgs)
If e.KeyChar = Microsoft.VisualBasic.ChrW(13) Or Char.IsDigit(e.KeyChar) Or e.KeyChar = Microsoft.VisualBasic.ChrW(7) Then
e.Handled = True
End If
End Sub 'keypressed

You can modify it according to your requirements for describing how subroutines are implemented.

For a VB6 tutorial:
http://www.vbtutor.net/vbtutor.html

For a VB.net tutorial:
http://www.homeandlearn.co.uk/NET/vbNET.html

CIT201: Programming



Assignment 2

--------------------------------------------------------------------------------

Entering Code in Visual Basic

In this assignment, you will finish the project you began last week. Open the Smith Repair Parts Specials program interface.





Code the Project

The description and price of a repair part or service should display to the two TextBox controls with the ReadOnly property = True because the TextBox controls on this form are used for output, not input.



Three Display Buttons: when a button is clicked, the relevant information should display on the form.



The data to be displayed for each of these three buttons are given in the table shown below.



Button
Repair Specials Information
Price

Auto
New Brakes and Calipers
$129.95

Truck
Heavy Duty Tires
$185.50

Commercial
Annual Inspections
$82.49




Include the following:

1. When designing the form, select control names that follow the naming convention specified in the lecture.

2. Include comments before the Public Class declaration that include the PROJECT, PROGRAMMER NAME, and DATE.

3. Include remarks statements inside of each sub procedure to identify what the sub procedure does.



Zip the files and upload into the appropriate dropbox.



This activity will be graded using the Technology Application Grading Rubric - Programming.



Learning Outcome(s): 4

4. Design a program interface and determine the appropriate controls and code.

(1) The condition under which a FOR-TO-NEXT loop will not be executed is if the initial value of the loop variable is greater than or equal to the final value. In other words, if the loop variable starts at a value that is already equal to or greater than the ending value specified in the loop, the loop will not run. This is because the loop variable is incremented with each iteration, and if it starts at or exceeds the final value, there are no more iterations needed.

For example, let's consider the following FOR-TO-NEXT loop in BASIC:

```
FOR i = 1 TO 5
PRINT i
NEXT i
```

In this case, the loop will be executed since the initial value `1` is less than the final value `5`. It will iterate five times, printing the values `1` through `5` on separate lines.

However, if we modify the loop to start at `6`, like this:

```
FOR i = 6 TO 10
PRINT i
NEXT i
```

Now, the loop will not be executed because the initial value `6` is already greater than the final value `10`. Therefore, no iterations will occur, and no numbers will be printed.

(2) In BASIC, a subroutine is implemented using the `GOSUB` statement. It allows you to define a block of code that can be called and executed at any point in the program. Here's an illustrative example:

```
10 PRINT "Before subroutine"
20 GOSUB 100
30 PRINT "After subroutine"
40 END

100 PRINT "Inside subroutine"
110 RETURN
```

In this example, when the program is executed, it will first print "Before subroutine," then jump to the subroutine with the line number `100` using the `GOSUB` statement. Inside the subroutine, it will print "Inside subroutine" and then use the `RETURN` statement to return to the line after the `GOSUB` statement in the main program.

After returning from the subroutine, the program will continue execution and print "After subroutine." Finally, it will reach the `END` statement, ending the program execution.

So, the output of this program will be:

```
Before subroutine
Inside subroutine
After subroutine
```