NEEDING ANSWERED AS SOON AS POSSIBLE! KJPR-Radio Each year, KJPR-Radio polls its
ID: 3820414 • Letter: N
Question
NEEDING ANSWERED AS SOON AS POSSIBLE!
KJPR-Radio
Each year, KJPR-Radio polls its audience to determine the best Super Bowl commercial. The choices are as follows: Cheerios, Doritos, T-Mobile, and RadioShack. Create an application using Visual Studios 2015, that the station manager can use to save each caller’s choice in a sequential access file. The application should display the number of votes for each commercial as well as the percentage of the total contributed by each choice. Use the following names for the solution and project, respectively: Commercial Solution and Commercial Project. Change the form file’s name to Main Form.vb
Needing the layout of the user interface with the names of the labels, buttons, etc. And the code that makes the program work.
Explanation / Answer
MainForm.vb
___________________________________
Option Explicit On
Option Strict On
Option Infer Off
Public Class MainForm
'declaring variables
Private total_Cheerios As Integer
Private total_Option Explicit On
Option Strict On
Option Infer Off
Public Class MainForm
'declaring variables
Private total_Cheerios As Integer
Private total_radioshack As Integer
Private total_doritos As Integer
Private total_tmobile As Integer
'code for exit button
Private Sub exitButton_Click(sender As Object, e As EventArgs) Handles exitButton.Click
Me.Close()
End Sub
Private Sub MainForm_Load(sender As Object, e As EventArgs) Handles Me.Load
commercialListBox.Items.Add("Cheerios")
commercialListBox.Items.Add("Doritos")
commercialListBox.Items.Add("T-Mobile")
commercialListBox.Items.Add("RadioShack")
End Sub
Private Sub savevoteButton_Click(sender As Object, e As EventArgs) Handles savevoteButton.Click
Dim vote As Integer
vote = commercialListBox.SelectedIndex
If (vote = 0) Then
total_Cheerios += 1
ElseIf (vote = 1) Then
total_doritos += 1
ElseIf (vote = 2) Then
total_tmobile += 1
ElseIf (vote = 3) Then
total_radioshack += 1
End If
'writes the data to a text file
Dim outFile As IO.StreamWriter
Dim heading As String =
"Commercial" & Strings.Space(5) & "Votes"
outFile = IO.File.CreateText("Commercial.txt")
outFile.WriteLine(heading)
outFile.WriteLine("Cheerios = " & Strings.Space(5) & total_Cheerios)
outFile.WriteLine("TMobile = " & Strings.Space(5) & total_tmobile)
outFile.WriteLine("RadioShack = " & Strings.Space(5) & total_radioshack)
outFile.WriteLine("Doritos = " & Strings.Space(5) & total_doritos)
outFile.Close()
End Sub
Private Sub displayButton_Click(sender As Object, e As EventArgs) Handles displayButton.Click
radioshackdisplayLabel.Text = total_radioshack.ToString
doritosdisplayLabel.Text = total_doritos.ToString
tmobiledisplayLabel.Text = total_tmobile.ToString
cheeriosdisplayLabel.Text = total_Cheerios.ToString
End Sub
End Class As Integer
Private total_doritos As Integer
Private total_tmobile As Integer
'code for exit button
Private Sub exitButton_Click(sender As Object, e As EventArgs) Handles exitButton.Click
Me.Close()
End Sub
Private Sub MainForm_Load(sender As Object, e As EventArgs) Handles Me.Load
commercialListBox.Items.Add("Cheerios")
commercialListBox.Items.Add("Doritos")
commercialListBox.Items.Add("T-Mobile")
commercialListBox.Items.Add("RadioShack")
End Sub
Private Sub savevoteButton_Click(sender As Object, e As EventArgs) Handles savevoteButton.Click
Dim vote As Integer
vote = commercialListBox.SelectedIndex
If (vote = 0) Then
total_Cheerios += 1
ElseIf (vote = 1) Then
total_doritos += 1
ElseIf (vote = 2) Then
total_tmobile += 1
ElseIf (vote = 3) Then
total_radioshack += 1
End If
'writes the data to a text file
Dim outFile As IO.StreamWriter
Dim heading As String =
"Commercial" & Strings.Space(5) & "Votes"
outFile = IO.File.CreateText("Commercial.txt")
outFile.WriteLine(heading)
outFile.WriteLine("Cheerios = " & Strings.Space(5) & total_Cheerios)
outFile.WriteLine("TMobile = " & Strings.Space(5) & total_tmobile)
outFile.WriteLine("RadioShack = " & Strings.Space(5) & total_radioshack)
outFile.WriteLine("Doritos = " & Strings.Space(5) & total_doritos)
outFile.Close()
End Sub
Private Sub displayButton_Click(sender As Object, e As EventArgs) Handles displayButton.Click
radioshackdisplayLabel.Text = total_radioshack.ToString
doritosdisplayLabel.Text = total_doritos.ToString
tmobiledisplayLabel.Text = total_tmobile.ToString
cheeriosdisplayLabel.Text = total_Cheerios.ToString
End Sub
End Class
____________________________________________________
MainForm.Designer.vb
_____________________________________________________
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()>
Partial Class MainForm
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.savevoteButton = New System.Windows.Forms.Button()
Me.displayButton = New System.Windows.Forms.Button()
Me.exitButton = New System.Windows.Forms.Button()
Me.cheeriosLabel = New System.Windows.Forms.Label()
Me.radioshackLabel = New System.Windows.Forms.Label()
Me.doritosLabel = New System.Windows.Forms.Label()
Me.tmobileLabel = New System.Windows.Forms.Label()
Me.cheeriosdisplayLabel = New System.Windows.Forms.Label()
Me.radioshackdisplayLabel = New System.Windows.Forms.Label()
Me.doritosdisplayLabel = New System.Windows.Forms.Label()
Me.tmobiledisplayLabel = New System.Windows.Forms.Label()
Me.commercialListBox = New System.Windows.Forms.ListBox()
Me.CommercialLabel = New System.Windows.Forms.Label()
Me.SuspendLayout()
'
'savevoteButton
'
Me.savevoteButton.Location = New System.Drawing.Point(371, 112)
Me.savevoteButton.Name = "savevoteButton"
Me.savevoteButton.Size = New System.Drawing.Size(89, 23)
Me.savevoteButton.TabIndex = 0
Me.savevoteButton.Text = "&Save vote"
Me.savevoteButton.UseVisualStyleBackColor = True
'
'displayButton
'
Me.displayButton.Location = New System.Drawing.Point(371, 159)
Me.displayButton.Name = "displayButton"
Me.displayButton.Size = New System.Drawing.Size(89, 23)
Me.displayButton.TabIndex = 1
Me.displayButton.Text = "&Display votes"
Me.displayButton.UseVisualStyleBackColor = True
'
'exitButton
'
Me.exitButton.Location = New System.Drawing.Point(371, 208)
Me.exitButton.Name = "exitButton"
Me.exitButton.Size = New System.Drawing.Size(89, 23)
Me.exitButton.TabIndex = 2
Me.exitButton.Text = "E&xit"
Me.exitButton.UseVisualStyleBackColor = True
'
'cheeriosLabel
'
Me.cheeriosLabel.AutoSize = True
Me.cheeriosLabel.Location = New System.Drawing.Point(58, 270)
Me.cheeriosLabel.Name = "cheeriosLabel"
Me.cheeriosLabel.Size = New System.Drawing.Size(61, 13)
Me.cheeriosLabel.TabIndex = 3
Me.cheeriosLabel.Text = "Cheerios"
'
'radioshackLabel
'
Me.radioshackLabel.AutoSize = True
Me.radioshackLabel.Location = New System.Drawing.Point(167, 270)
Me.radioshackLabel.Name = "radioshackLabel"
Me.radioshackLabel.Size = New System.Drawing.Size(34, 13)
Me.radioshackLabel.TabIndex = 4
Me.radioshackLabel.Text = "RadioShack"
'
'doritosLabel
'
Me.doritosLabel.AutoSize = True
Me.doritosLabel.Location = New System.Drawing.Point(265, 270)
Me.doritosLabel.Name = "doritosLabel"
Me.doritosLabel.Size = New System.Drawing.Size(40, 13)
Me.doritosLabel.TabIndex = 5
Me.doritosLabel.Text = "Doritos:"
'
'tmobileLabel
'
Me.tmobileLabel.AutoSize = True
Me.tmobileLabel.Location = New System.Drawing.Point(380, 270)
Me.tmobileLabel.Name = "tmobileLabel"
Me.tmobileLabel.Size = New System.Drawing.Size(46, 13)
Me.tmobileLabel.TabIndex = 6
Me.tmobileLabel.Text = "T-Mobile"
'
'cheeriosdisplayLabel
'
Me.cheeriosdisplayLabel.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
Me.cheeriosdisplayLabel.Location = New System.Drawing.Point(61, 298)
Me.cheeriosdisplayLabel.Name = "cheeriosdisplayLabel"
Me.cheeriosdisplayLabel.Size = New System.Drawing.Size(58, 24)
Me.cheeriosdisplayLabel.TabIndex = 7
'
'radioshackLabel
'
Me.radioshackdisplayLabel.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
Me.radioshackdisplayLabel.Location = New System.Drawing.Point(170, 298)
Me.radioshackdisplayLabel.Name = "radioshackdisplayLabel"
Me.radioshackdisplayLabel.Size = New System.Drawing.Size(58, 24)
Me.radioshackdisplayLabel.TabIndex = 8
'
'doritosdisplayLabel
'
Me.doritosdisplayLabel.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
Me.doritosdisplayLabel.Location = New System.Drawing.Point(268, 298)
Me.doritosdisplayLabel.Name = "doritosdisplayLabel"
Me.doritosdisplayLabel.Size = New System.Drawing.Size(58, 24)
Me.doritosdisplayLabel.TabIndex = 9
'
'tmobiledisplayLabel
'
Me.tmobiledisplayLabel.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
Me.tmobiledisplayLabel.Location = New System.Drawing.Point(383, 298)
Me.tmobiledisplayLabel.Name = "tmobiledisplayLabel"
Me.tmobiledisplayLabel.Size = New System.Drawing.Size(58, 24)
Me.tmobiledisplayLabel.TabIndex = 10
'
'commercialListBox
'
Me.commercialListBox.FormattingEnabled = True
Me.commercialListBox.Location = New System.Drawing.Point(52, 112)
Me.commercialListBox.Name = "commercialListBox"
Me.commercialListBox.Size = New System.Drawing.Size(244, 147)
Me.commercialListBox.TabIndex = 11
'
'CommercialLabel
'
Me.CommercialLabel.AutoSize = True
Me.CommercialLabel.Location = New System.Drawing.Point(52, 67)
Me.CommercialLabel.Name = "CommercialLabel"
Me.CommercialLabel.Size = New System.Drawing.Size(74, 13)
Me.CommercialLabel.TabIndex = 12
Me.CommercialLabel.Text = "Commercials:"
'
'MainForm
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(494, 358)
Me.Controls.Add(Me.CommercialLabel)
Me.Controls.Add(Me.commercialListBox)
Me.Controls.Add(Me.tmobiledisplayLabel)
Me.Controls.Add(Me.doritosdisplayLabel)
Me.Controls.Add(Me.radioshackdisplayLabel)
Me.Controls.Add(Me.cheeriosdisplayLabel)
Me.Controls.Add(Me.tmobileLabel)
Me.Controls.Add(Me.doritosLabel)
Me.Controls.Add(Me.radioshackLabel)
Me.Controls.Add(Me.cheeriosLabel)
Me.Controls.Add(Me.exitButton)
Me.Controls.Add(Me.displayButton)
Me.Controls.Add(Me.savevoteButton)
Me.Font = New System.Drawing.Font("Segoe UI", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Name = "MainForm"
Me.Text = "KJPR"
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub
Friend WithEvents savevoteButton As System.Windows.Forms.Button
Friend WithEvents displayButton As System.Windows.Forms.Button
Friend WithEvents exitButton As System.Windows.Forms.Button
Friend WithEvents cheeriosLabel As System.Windows.Forms.Label
Friend WithEvents radioshackLabel As System.Windows.Forms.Label
Friend WithEvents doritosLabel As System.Windows.Forms.Label
Friend WithEvents tmobileLabel As System.Windows.Forms.Label
Friend WithEvents cheeriosdisplayLabel As System.Windows.Forms.Label
Friend WithEvents radioshackdisplayLabel As System.Windows.Forms.Label
Friend WithEvents doritosdisplayLabel As System.Windows.Forms.Label
Friend WithEvents tmobiledisplayLabel As System.Windows.Forms.Label
Friend WithEvents commercialListBox As System.Windows.Forms.ListBox
Friend WithEvents CommercialLabel As System.Windows.Forms.Label
End Class
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.