In: Computer Science
Here is assignment 11 and it must be completed and submitted by Sunday july 26 at 11:59pm Pacific Time. Start early and follow the instructions. Please note, no late assignment will be accepted. The assignment’s grade will be available in your Gradebook by the following Tuesday.
This assignment is mainly to practice Selection programming structure with creating a project in VB. That is IF ... THEN ... ELSE ... END IF and IF ... THEN ... ELSEIF ... ELSEIF .... END IF
9. Double-click on Compute Button; declare variables you need to store entered intNumber and calculated intNumber. Both variables data type is Integer . Then type the Selection structure code from Assignment 7 #3. Run the program and test it for intNumber values of 50, 500 and 1000. For each test the result should be: 100, 500, and 3000 respectively.
Screenshots for creating a new project in VB:
2. In the next screen, Create a new project, you choose the correct project template. Since you created a VB project in Week 4, then the correct template: "VB Windows Forms App (.NET Framework)" will display in Recent Project Templates list, you will see a similar screenshot below, Just make sure you open VB Windows Forms App (.NET Framework) and not the one for C++. Click on Next button to continue:
3. Type project name: yourlastname-firstname-SelectionVBProgram in Project and select the VB folder that you will save VB project files in Location box. NOTE: your VB project will be saved in a folder with the project name you type in Project Name box. This will create a folder and a file with SLN extension. Both have the same project name. see below screenshot for where you enter Project name and Location:
4. To change the Location, click on three dots (...), locate the CS3 folder you created earlier for this class. in Project Location window, you should see VB folder that you created earlier in this assignment. Click once to select VB folder(do not double-click) and then click on Select Folder button. This will take you back to "Configure your new project" window. See below screenshot for selecting VB folder. Note that if you have selected VB folder to save the first VB Project, then it will automatically becomes the default folder. You will see the above screenshot. Click on Create to continue to VB Editor window.
5. Upon clicking on Create, you will be placed in VB editor window, see below:
6. From here on, click on View menu to activate Toolbox menu, expand Common Controls, Then add two Label controls, one TextBox and one Button controls on the form. Follow the instructions to name each control and add necessary text properties for each control. See below:
7. Then double-click on the Button which now should read “computer” to see the VB coding area, Form1.vb. type the code for the criteria in #9 such that when the program runs, you enter 50 for intNumber (textbox) and in the Label2 you see 100 displays, when you enter 500, result is 500 and when you enter 1000, the result is 3000. You have code in assignment 7.
Assignment 7 #3 Use the following selection structure to answer the next three questions:
If intNumber<= 100 Then
intNumber = intNumber * 2
ElseIf
intNumber> 500 Then
intNumber = intNumber * 3
End If
Application Name :yourlastname-firstname-SelectionVBProgram
Language used :VB
User interface :Form1.vb[Design]
************************************************
Form1.Designer.vb :
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()>
_
Partial Class Form1
Inherits System.Windows.Forms.Form
'Form overrides dispose to clean up the component list.
<System.Diagnostics.DebuggerNonUserCode()> _
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
Try
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
Finally
MyBase.Dispose(disposing)
End Try
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form
Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
Me.lblIntNumber = New System.Windows.Forms.Label()
Me.txtEnterIntNumber = New System.Windows.Forms.TextBox()
Me.btnCompute = New System.Windows.Forms.Button()
Me.lblResult = New System.Windows.Forms.Label()
Me.SuspendLayout()
'
'lblIntNumber
'
Me.lblIntNumber.AutoSize = True
Me.lblIntNumber.Location = New System.Drawing.Point(35, 33)
Me.lblIntNumber.Name = "lblIntNumber"
Me.lblIntNumber.Size = New System.Drawing.Size(146, 13)
Me.lblIntNumber.TabIndex = 0
Me.lblIntNumber.Text = " Enter a value for IntNumber :"
'
'txtEnterIntNumber
'
Me.txtEnterIntNumber.Location = New System.Drawing.Point(187,
30)
Me.txtEnterIntNumber.Name = "txtEnterIntNumber"
Me.txtEnterIntNumber.Size = New System.Drawing.Size(100, 20)
Me.txtEnterIntNumber.TabIndex = 1
'
'btnCompute
'
Me.btnCompute.Location = New System.Drawing.Point(132, 74)
Me.btnCompute.Name = "btnCompute"
Me.btnCompute.Size = New System.Drawing.Size(75, 23)
Me.btnCompute.TabIndex = 2
Me.btnCompute.Text = "Compute"
Me.btnCompute.UseVisualStyleBackColor = True
'
'lblResult
'
Me.lblResult.BorderStyle =
System.Windows.Forms.BorderStyle.Fixed3D
Me.lblResult.Location = New System.Drawing.Point(48, 115)
Me.lblResult.Name = "lblResult"
Me.lblResult.Size = New System.Drawing.Size(239, 30)
Me.lblResult.TabIndex = 3
Me.lblResult.Text = " Display IntNumber;"
'
'Form1
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!,
13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(361, 192)
Me.Controls.Add(Me.lblResult)
Me.Controls.Add(Me.btnCompute)
Me.Controls.Add(Me.txtEnterIntNumber)
Me.Controls.Add(Me.lblIntNumber)
Me.Name = "Form1"
Me.Text = "Selection Homework – your name"
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub
Friend WithEvents lblIntNumber As Label
Friend WithEvents txtEnterIntNumber As TextBox
Friend WithEvents btnCompute As Button
Friend WithEvents lblResult As Label
End Class
************************************
Form1.vb :
Public Class Form1 'VB Form
'Compute button click
Private Sub btnCompute_Click(sender As Object, e As EventArgs)
Handles btnCompute.Click
'declaring variables
Dim intNumber As Integer
'taking value entered by user and storing in the variable
intNumber
intNumber = Integer.Parse(txtEnterIntNumber.Text)
'checking value of intNumber
If intNumber <= 100 Then
'if value of intNumber is less than 100 then
intNumber = intNumber * 2
ElseIf intNumber > 500 Then
'if intNumber greater than 300 then
intNumber = intNumber * 3
End If
'display value of intNumber in the label
lblResult.Text = intNumber
End Sub
End Class
========================================
Output :
Screen 1:Screen when intNumber=50
Screen 2:Screen when intNumber=500
Screen 3:Screen when intNumber=1000