Programming with Microsoft Visual Basics Create an application that displays the
ID: 3667483 • Letter: P
Question
Programming with Microsoft Visual Basics
Create an application that displays the number of round tables needed to seat only the guests at a wedding reception. (In other words, the bridal party does not need to be included in this calculation.) Each round table can accommodate a maximum of 8 guests. he interface should provide a text box for the user to enter the total number of guests who need to be seated. Display the number of tables in a label. Use the following names for the solution and project, respectively: Wedding Solution and Wedding Project. Save the application in the VB2015Chap04 folder. When the text box receives the focus, its existing text should be selected. he text box should accept only numbers and the Backspace key. he output should be cleared when a change is made to the contents of the text box. est the application appropriately. (Hint: If the number of guests is 235, the number of required tables is 30.)
Explanation / Answer
Option Explicit On
Option Strict On
Public Class WeddingProject
Dim numberOfTables As Integer
Dim totalNumberOfGuests as Integer
Sub Main()
Dim oneTable as Integer
> 'calculating number of tables and getting integer value
numberOfTables =Math.Ceiling((totalNumberOfGuests /oneTable ))
'convert the number of tables to string
'then display it in label
Label2.Text=CStr(numberOfTables)
End Sub
'Text box 1 got focused
Private Sub Text1_GotFocus(sender as Object, e as EventArgs) _
Handles Text1.GotFocus
'selecting the existing text
Text1.SelectionStart = 0;
Text1.SelectionLength = Text1.Text.Length;
'convert to integer and assign to number of guests
totalNumberOfGuests =val(Text1.Text)
End Sub
Private Sub Text1_TextChanged(sender As Object, _
e As EventArgs) Handles Text1.TextChanged
'clear output label whenever Text box 1 content get changed
Label2.Text=""
'If the key is not back space and not a numberic value then error
If (Not e.KeyChar = ChrW(Keys.Back) And ("0123456789.").IndexOf(e.KeyChar) = -1) Then
e.Handled = True
End If
End Sub
End Module
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.