Você está na página 1de 5

Problem no.

Write a program that declares two integers and initializes them to 199 and 76.
Display the sum, difference, product, average, square and remainder of the values

Source Code:

Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles MyBase.Load
Dim a As Integer
Dim b As Integer
a = 199
b = 76
TextBox1.Text = a + b
TextBox2.Text = a - b
TextBox3.Text = a * b
TextBox4.Text = (a + b) / 2
TextBox5.Text = ((a / b) Mod 2)

End Sub

Private Sub TextBox4_TextChanged(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles TextBox4.TextChanged

End Sub

Private Sub TextBox3_TextChanged(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles TextBox3.TextChanged

End Sub

Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles TextBox2.TextChanged

End Sub

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles TextBox1.TextChanged

End Sub
End Class

Problem no. 2

Write a program that computes the amount of money the computer club will receive
from the proceeds of their candy sales project. They sold 37 cases, which had 12
bars per case. The candy was sold for 0.75 per bar. Each case cost $5.00. They are
required to give the student government association 10% of their earnings. Display
their proceeds Formatted with currency.
Source Code:

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click
txt5.Text = Val((txt1.Text * txt2.Text) * txt3.Text - (txt1.Text * txt4.Text)) / 10
txt6.Text = Val((txt1.Text * txt2.Text) * txt3.Text - (txt1.Text * txt4.Text))
txt5.Text = "$" + txt5.Text
txt6.Text = "$" + txt6.Text
End Sub
End Class

Problem no. 4

Write a program that calculates the take home pay for an employee. The two types of
employees are salaried and hourly. Allow the user to input the employee type. If an
employee is salaried, allow the user to input the salary amount. If an employee is hourly,
allow the user to input the hourly rate and the numbers of hour clocked for the week. For
hourly employees, overtime is paid for hours over 40 at a rate of 1.5 of the base rate. For all
employees take home pay federal tax of 18% is deducted. A retirement contribution of 10%
and social security tax rate of 6% should be deducted. Use an appropriate constant.

Source Code:

Public Class Form1

Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal


e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
If ComboBox1.Text = "Salaried" Then
GroupBox2.Visible = True
GroupBox1.Visible = False
Else
GroupBox1.Visible = True
GroupBox2.Visible = False
End If
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click
Dim A As Integer

If TextBox2.Text = "" Or TextBox3.Text = "" Then


MsgBox("Fill up the missing field", vbInformation, "Information")
Exit Sub
ElseIf IsNumeric(TextBox2.Text) = False Or IsNumeric(TextBox3.Text) = False Then
MsgBox("Only Number is required in this field", vbInformation, "Information")
TextBox2.Text = ""
TextBox3.Text = ""
Exit Sub
End If
A = 40
If ComboBox1.Text = "Hourly" Then
TextBox1.Text = (TextBox2.Text * TextBox3.Text)
If TextBox3.Text > 40 Then

TextBox5.Text = ((TextBox3.Text - A) * (TextBox2.Text * 1.5))


TextBox6.Text = Val(TextBox5.Text) + Val(TextBox1.Text)
TextBox7.Text = ((TextBox6.Text) - (TextBox6.Text * 0.34))
Else
TextBox5.Text = 0
TextBox6.Text = TextBox1.Text
TextBox7.Text = (TextBox1.Text) - ((TextBox1.Text * 0.34))
End If
Else
TextBox8.Text = (TextBox4.Text) - (TextBox4.Text * 0.34)
End If

End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles MyBase.Load
GroupBox1.Visible = False
GroupBox2.Visible = False
End Sub

Private Sub GroupBox2_Enter(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles GroupBox2.Enter

End Sub
End Class
A. Give at least 2 sample code using array.

Sometimes you have an array that needs to keep growing, and you don't know what
the upper bound will end up being. Maybe you are making a crappy MP3 player and need to
ask the user to input song names. You might do something like this:

Dim strSongNames() As String 'Array of song names


Dim blDimensioned As Boolean 'Is the array dimensioned?
Dim strText As String 'To temporarily hold names
Dim lngPosition as Long 'Counting

'The array has not yet been dimensioned:


blDimensioned = False

Do

'Ask for a song name


strText = InputBox("Enter a song name:")

If strText <> "" Then

'Has the array been dimensioned?


If blDimensioned = True Then

'Yes, so extend the array one element large than its current upper bound.
'Without the "Preserve" keyword below, the previous elements in our array would be
erased with the resizing
ReDim Preserve strSongNames(0 To UBound(strSongNames) + 1) As String
Else

'No, so dimension it and flag it as dimensioned.


ReDim strSongNames(0 To 0) As String
blDimensioned = True

End If

'Add the song name to the last element in the array.


strSongNames(UBound(strSongNames)) = strText

End If

Loop Until strText = ""

'Display entered song names:

For lngPosition = LBound(strSongNames) To UBound(strSongNames)

MsgBox strSongNames(lngPosition)

Next lngPosition

'Erase array

Erase strSongName

The following code demonstrates arrays.

Imports System.Console
Module Module1

Sub Main()
Dim sport(5) As String
'declaring an array
sport(0) = "Soccer"
sport(1) = "Cricket"
sport(2) = "Rugby"
sport(3) = "Aussie Rules"
sport(4) = "BasketBall"
sport(5) = "Hockey"
'storing values in the array
WriteLine("Name of the Sport in the third location" & " " & sport(2))
'displaying value from array
End Sub

End Module

B.Research the use of module and class.


 Both class and module are a collection of methods and properties. The major
difference is that instances can be created from a class in the form of objects, but not
from a module. The scope of the members of a class is only for the lifetime of the
object, but the scope of the members of a module exists for the life of the program.
 A Module is equivalent to a Class in which all of the methods, fields and properties
are Shared. In other words, you may use a Module without using New to create an
instance of it.:

C. How the Create new property object.

 To create the form

1. Open Visual Studio .NET.


2. Select Visual Basic Project from the tree-view on the left-hand side of the screen.
3. Select Windows Application as the project template.
4. Set the name of the application to ClassCreation.
5. In the Solution Explorer window, select the Form1.vb form and rename it to
frmLineTest.vb. To rename a form in the Solution Explorer window, right-click the
form and choose Rename on the shortcut menu.
6. Create the form shown in Figure 1 by adding the appropriate controls and setting the
properties of those controls as outlined in Table 2.

To create the Line class

1. Open the Add New Item dialog box by clicking Project and then clicking Add Class.
2. Set the Name property to Line and click OK.

You will now see a new file appear in your project and a code window within the Visual
Studio .NET environment. In the Code window, there will be some code that looks like this

Você também pode gostar