# Visual basic practice Problems with Solution, Text Box,String Formatting

VB practice Problems with Solution these problems cover GUI in VB ,user input from Text box and string formatting
Question 1

1) Write an event procedure that calculate and displays the wage of an employee along with his first name when the command button Command1 is clicked. The program allows the user to enter its full name through Textbox1, his/her daily salary through Textbox2, and number of days worked through Textbox3. The result is displayed in the picture box Picture1 as follows:( Past Mid Question)

<given name>’s wage is Rs. <amount rounded to nearest integer>
<given name>’s wage is \$. <amount>
e.g: Hina’s wage is Rs. 50054
e.g: Hina’s wage is. \$645

Dim name As String
Dim salary As Single
Dim days As Integer
Dim wages As Single

name = Text1.Text
salary = Text2.Text
days = Text3.Text

wages = salary * days

Picture1.Print name + "'s wage is Rs. "; Int(wages)

Picture1.Print name + "'s wage is "; Format\$(wages / 77, "Currency")

Question 2

Write a program in VB that takes a small letter charater a-z from text box and print the following output at Label. Using Asc() and Chr() function only.
Example:
Input:   a                          b                  m
Output: Abba                     BCcb             MNnm

Dim inputtext As String
Dim asciivalue As Integer
Dim result As String

inputtext = Text1.Text
asciivalue = Asc(inputtext)
result = Chr(asciivalue - 32) + Chr(asciivalue - 31) + Chr(asciivalue + 1) + Chr(asciivalue)
Label1.Caption = result

Question 3
Write a program to randomly select a month and a year during the 2000s (from 2000 to 2009). A typical outcome would be 7/2004.
(Pre lab Question)

Picture1.Print Int((Rnd * 12)) + 1; " / "; Int((Rnd * 10)) + 2000

Question 4

Write a program that take Input Name, Roll No, date, midterm marks and total midterm marks and shows the result in following format. Using string function and formart\$() function.
A)

Dim name As String
Dim rolno As String
Dim Tdate As String
Dim mmarks As Single
Dim tmarks As Single

Dim fname As String
Dim lname As String
Dim per As String
Dim frolno As String
Dim fTdate per As String

name = Text1.Text
rolno = Text2.Text
Tdate = Text3.Text
mmarks = Val(Text4.Text)
tmarks = Val(Text5.Text)

fname = Left\$(name, InStr(name, " ") - 1)
lname = Right\$(name, Len(name) - InStr(name, " "))
frolno = Format\$(rolno, "##-###-###")
fTdate = Format\$(Tdate, "Long Date")
per = Format\$(mmarks / tmarks, "Percent")

Picture1.Print "First Name: " + fname
Picture1.Print "Last Name: " + lname
Picture1.Print "Roll No: " + frolno
Picture1.Print "Date: " + fTdate
Picture1.Print "Percentage: " + per

B)

Dim name As String
Dim rolno As String
Dim Tdate As String
Dim mmarks As Single
Dim tmarks As Single

Dim fname As String
Dim lname As String
Dim per As String
Dim frolno As String
Dim fTdate per As String

name = Text1.Text
rolno = Text2.Text
Tdate = Text3.Text
mmarks = Val(Text4.Text)
tmarks = Val(Text5.Text)

fname = Left\$(name, InStr(name, " ") - 1)
lname = Right\$(name, Len(name) - InStr(name, " "))
frolno = Format\$(rolno, "##-###-###")
fTdate = Format\$(Tdate, "Long Date")
per = Format\$(mmarks / tmarks, "Percent")

'Picture1.Print "First Name: " + fname
'Picture1.Print "Last Name: " + lname
'Picture1.Print "Roll No: " + frolno
'Picture1.Print "Date: " + fTdate
'Picture1.Print "Percentage: " + per

Picture1.Print Format\$("First Name:", "@@@@@@@@@@@@@");
Picture1.Print Tab(19);
Picture1.Print fname
Picture1.Print Format\$("Last Name:", "@@@@@@@@@@@@");
Picture1.Print Tab(19);
Picture1.Print lname
Picture1.Print Format\$("Roll No:", "@@@@@@@@@@");
Picture1.Print Tab(19);
Picture1.Print frolno
Picture1.Print Format\$("Date:", "@@@@@@@");
Picture1.Print Tab(19);
Picture1.Print fTdate
Picture1.Print Format\$("Percentage:", "@@@@@@@@@@@@@");
Picture1.Print Tab(19);
Picture1.Print per

• Title : Visual basic practice Problems with Solution, Text Box,String Formatting
• Posted by :
• Date : 11:33
• Labels :