25
COLLEGE OF WATER CONSERVENCY AND HYDROPOWER ENGINEERING ACADEMIC YEAR 2014-2015, MODULUS: METHODS OF PROGRAMMING (VISUAL BASIC) STUDENT ID: M2014028 STUDENT NAME: BAGARAGAZA ROMUALD MAJOR: WATER CONSERVANCY AND HYDROPOWER ENGINEERING Lecturer Module Leader: COLLEGE OF INTERNATIONAL STUDENTS

Vb Exam 2014

Embed Size (px)

DESCRIPTION

programming

Citation preview

  • COLLEGE OF WATER CONSERVENCY AND HYDROPOWER

    ENGINEERING

    ACADEMIC YEAR 2014-2015,

    MODULUS: METHODS OF PROGRAMMING (VISUAL BASIC)

    STUDENT ID: M2014028

    STUDENT NAME: BAGARAGAZA ROMUALD

    MAJOR: WATER CONSERVANCY AND HYDROPOWER ENGINEERING

    Lecturer Module Leader:

    COLLEGE OF INTERNATIONAL STUDENTS

    AdminTypewriterLIU WENTING

  • Questions

    1. The file sonnet.txt contains Shakespeares sonnet 18. Each entry in the contains a

    line of the sonnet. Write a program that reports the average number of the words

    in the lines and the total number of words in the sonnet.

    2. Design a project about your research field. To solve a problem.

    My project is:

    (Design a water Treatment total discharge Consumption for different users

    and the amount of money the treatment will receive per day).

    Tasks

    Print: - interface

    -Properties

    -Code

    SOLUTION FOR Q1

    In my project I used the following tools: Label, Button, Textbox, Checkbox,

    Groupbox.

    a) INTERFACE AND PROPERTIES

    i) For LABEL

    The following picture an interface of the label and its properties. As you can see

    the selected is lign1 which name is label5

    Because the properties are so many in VB I need to show the other for the text

    properties.

    AdminArrow

    AdminTypewriter1

  • As the on the above picture the selected lign1 in properties you can see that the Text

    in blue is Named as Lign1.Note: All labels from label1 up to label14 are the same.

    ii) FOR TEXTBOX

    As you can see the label is followed by a textbox, the textbox shows us the number of

    the words in lign1. So the following picture shows textbox properties. As you can see the

    selected textbox has a text 8.

    AdminArrow

    AdminTypewriter2

  • Because the properties are so many in VB I need to show you other picture for

    text properties.

    On the above picture the selected textbox1 in properties you can see that the Text in

    blue is named as 8, means that 8 is the number of the words in lign1 from sonnet.

    Note : All labels from label1 up to label14 are the same.

    iii) FOR GROUPBOX

    AdminArrow

    AdminArrow

    AdminTypewriter3

  • Below the third option I used known as groupbox, it represent the results obtained by

    calculating the total number of the words and the average number of the words, and there

    also are other two one is for submission and other is for quit or close.The below pictures

    represent an interface and the properties of the groupbox.

    As you can see in the above picture, we have a selected groupbox and its properties but

    because the properties are so many, I need to print again another box showing the text

    property of this groupbox.

    AdminArrow

    AdminArrow

    AdminTypewriter4

  • In the groupbox there are three labels and there checkbox, let me start to the label of total

    words in the sonnet

    This above picture shows the total words in the sonnet and its textbox

    Because the properties are so many in VB I need to show you other picture for text

    properties.

    AdminArrow

    AdminArrow

    AdminTypewriter5

  • As the on the above picture the selected total words in the sonnet in properties you

    can see that the Text in blue is Named as total words in the sonnet.

    Note: All labels means label of number of the lign in the sonnet and average words

    labels , I used the same procedures.

    And then the most important things is to define the Textbox of the above labels.

    The above picture shows us the property name of the textbox1 in a label of total words in

    the sonnet. And as you know that the VB has so many properties, we need to show again

    the text property of this textbox.

    AdminArrow

    AdminTypewriter6

  • Through the observation you can see that in the text of this textbox is empty, means that

    after writing the code the results will be displayed.

    Note1 : average words was done in the same way like we did in the above. By

    defining label and textbox.

    Note2 : On the label of the line in sonnet it also as in the above note 1 but the different

    is that we wrote the number of the line by manual in other to get the automatic

    calculation in total words and average words in a line.

    In our groupbox we have also other TWO BUTTONS; one is for SUBMIT and the other

    one is for QUIT the program or to CLOSE DEBUGING, lets us try to see their interface

    and their properties downward.

    INTERFACE AND PROPERTIES

    AdminArrow

    AdminTypewriter788

  • This picture represent the interface of and the properties of the SUBMIT button as you

    can see it has the name OF BUTTONCHECKSTATE.

    And as you know that the VB has so many properties, we need to show again the text

    property of this BUTTON and we can see that on the text is write as SUBMIT.

    AdminArrow

    AdminArrow

    AdminTypewriter8

  • After this button properties I can proceed with the second button known as QUIT This

    picture represent the interface of and the properties of the QUIT button as you can see it

    has the name of BUTTON2

    And as you know that the VB has so many properties, we need to show again the text

    properties of this BUTTON and we can see that on the text is write as QUIT means is to

    quit/close debugging.

    AdminArrow

    AdminArrow

    AdminTypewriter9

  • b) CODE

    Public Class Form1 Private Sub Buttoncheckstate_Click(sender As System.Object, e As System.EventArgs) Handles Buttoncheckstate.Click Dim a, b, c, d, q, f, g, h, i, j, k, l, m, n, o, P, AVG As Integer a = TextBox4.Text b = TextBox5.Text c = TextBox6.Text d = TextBox7.Text q = TextBox8.Text f = TextBox9.Text g = TextBox10.Text h = TextBox17.Text i = TextBox16.Text j = TextBox15.Text k = TextBox14.Text l = TextBox13.Text m = TextBox12.Text n = TextBox11.Text P = TextBox2.Text o = (a + b + c + d + q + f + g + h + i + j + k + l + n + m) AVG = o / P TextBox1.Text = o TextBox3.Text = AVG End Sub Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click End End Sub End Class

    AdminTypewriter10

  • The following step is to run this Program.

    If you click on start debugging (F5) your program will look like this,

    After that I click on submit button and then the following program will be displayed

    showing the Total Words in the Sonnet and the Average Number of the Words.

    AdminHighlight

    AdminTypewriter11

  • Total Words in the Sonnet is 115 and

    The Average Number of the Words is 8

    AdminRectangle

    AdminRectangle

    AdminTypewriter12

  • Total Words in the Sonnet is 115 and

    The Average Number of the Words is 8

    If you click on QUIT button you stop running your program.

    AdminRectangle

    AdminRectangle

    AdminRectangle

    AdminTypewriter13

  • Q2

    2. Design a project about your research field. To solve a problem.

    My project is:

    (Design a water Treatment total discharge Consumption for different users

    and the amount of money the treatment will receive per day).

    Tasks

    Print: - interface

    -Properties

    -Code

    SOLUTION FOR Q2

    In my project I used the following tools: Label, Button, Textbox, Checkbox,

    INTERFACE AND PROPERTIES

    iv) For LABEL

    The following picture an interface of the label and its properties. As you can see

    the selected is TREATED WATER DISTRIBUTION AGENDA which name is

    label6

    Because the properties are so many in VB I need to show the other for the text

    properties.

    AdminRectangle

    AdminArrow

    AdminTypewriter14

  • As the on the above picture the selected label1 in properties you can see that the

    Text in blue is Named as TREATED WATER DISTRIBUTION AGENDA

    .Note: All labels from label1 up to label 6 are the same.

    v) FOR TEXTBOX

    As you can see the label is followed by a textbox, the textbox shows us the Minimum

    water consumption for each categories. So the following picture shows textbox

    properties. As you can see the selected textbox has a text 8.

    AdminArrow

    AdminTypewriter15

  • Because the properties are so many in VB I need to show you other picture for text

    properties.

    On the above picture the selected textbox1 in properties you can see that the Text in

    blue is named as 1, means that 1 is minimum water consumption for each user.

    Note : All textbox from textbox 1up to textbox 6 are the same.

    AdminArrow

    AdminArrow

    AdminTypewriter16

  • CHECKBOX

    As you can see here I used checkbox in order to represent the different types of water

    consumptions, here I used six water users. Lets describe the interface and the properties

    of only one checkbox because others I did in the same manner.

    As you can see in the above picture, we have a selected checkbox and its properties but

    because the properties are so many, I need to print again another box showing the text

    property of this checkbox.

    All these checkbox I did it in the same manner. Factory, industry , fire ,public&

    emergency

    AdminArrow

    AdminArrow

    AdminTypewriter17

  • LABELS : These are special cases of labels because shows us the allowable Maximum

    water consumption for user types.

    Because the properties are so many in VB I need to show you other picture for text

    properties.

    AdminArrow

    AdminArrow

    AdminTypewriter18

  • TWO BUTTONS; one is for OK and the other one is for QUIT the program or to CLOSE

    DEBUGING, lets us try to see their interface and their properties downward

    INTERFACE AND PROPERTIES

    This picture represent the interface of and the properties of the SUBMIT button as you

    can see it has the name OF BUTTONCHECKSTATE.

    And as you know that the VB has so many properties, we need to show again the text

    property of this BUTTON and we can see that on the text is write as OK.

    AdminArrow

    AdminArrow

    AdminTypewriter19

  • After this button properties I can proceed with the second button known as QUIT This

    picture represent the interface of and the properties of the QUIT button as you can see it

    has the name of BUTTON2

    And as you know that the VB has so many properties, we need to show again the text

    properties of this BUTTON and we can see that on the text is write as QUIT means is to

    quit/close debugging.

    AdminArrow

    AdminArrow

    AdminTypewriter20

  • c) CODE

    Public Class Form1 Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click Dim a, Cash As Integer If CheckBox1.CheckState = CheckState.Checked Then a = 6 * Val(TextBox1.Text) End If If CheckBox2.CheckState = CheckState.Checked Then a = a + 37 * Val(TextBox2.Text) End If If CheckBox3.CheckState = CheckState.Checked Then a = a + 41 * Val(TextBox3.Text) End If If CheckBox4.CheckState = CheckState.Checked Then a = a + 12 * Val(TextBox4.Text) End If If CheckBox5.CheckState = CheckState.Checked Then a = a + 10 * Val(TextBoxCash.Text) End If If CheckBox6.CheckState = CheckState.Checked Then a = a + 4 * Val(TextBox6.Text) End If Amount.Text = a Cash = 200 * a TextBoxCash.Text = Cash End Sub Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click Close() End Sub End Class

    AdminRectangle

    AdminTypewriter21

  • The following step is to run this Program.

    If you click on start debugging (F5) your program will look like this,

    As you can see on this program, we have three columns : Types, max.Consumption

    and Quantity of water per Day.

    You tick among of these water consumption type and the you enter the max.

    amount of water consumed in a day and click to ok exactly total amount of water

    will display in front of total discharge in cumec And also the total CASH be

    calculated in RMB

    AdminTypewriter22

  • HERE you see that domestic, factory, industry, and fire water were supplied and

    the total amount of water delivered by this water treatment plant is 835m3

    which

    is equal tob169700 RMB

    AdminRectangle

    AdminRectangle

    AdminRectangle

    AdminRectangle

    AdminRectangle

    AdminRectangle

    AdminTypewriter23

  • HERE you see that domestic, factory, industry, and fire water were supplied and

    the total amount of water delivered by this water treatment plant is 835m3

    which

    is equal tob169700 RMB

    If you click on QUIT button you stop running your program.

    AdminRectangle

    AdminRectangle

    AdminRectangle

    AdminRectangle

    AdminRectangle

    AdminRectangle

    AdminRectangle

    AdminTypewriter24