Question:
How can I make the user input percents in this VB application?
Follow @deni_in_al
2012-03-28 14:38:59 UTC
The output is correct when you click 'Calculate Final Average', but if I change the text box input property or whatever to percent, the equation won't bring out the proper outcome.

Basically, if the user inputs "93," I want it to be seen as a percent, and register in the equation as .93, which would be the decimal/integer (idk which word) for 93%.

Here is the link:
http://www.2shared.com/file/moEtq_6Z/Visual_Basic_Programming_Assig.html

Here is my source code, and ' Calculate the final average' equation may have to change as well for the calculation to be correct.:

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

' Declare variables we will use in the calculations.

Dim dblTests As Double
Dim dblFinalExam As Double
Dim dblQuizzes As Double
Dim dblComputerPrograms As Double
Dim dblResearchPaper As Double
Dim dblDatabaseAssignment As Double
Dim dblInclassPresentation As Double
Dim dblHomeworkLabAssignments As Double
Dim dblSummaryPaper As Double
Dim dblFinalAverage As Double

' Get the test grade from the TextBox control.
dblTests = Tests.Text

' Get the final exam grade from the TextBox control.
dblFinalExam = FinalExam.Text

' Get the quiz grade from the TextBox control.
dblQuizzes = Quizzes.Text

' Get the computer programs exam grade from the TextBox control.
dblComputerPrograms = ComputerPrograms.Text

' Get the research paper grade from the TextBox control.
dblResearchPaper = ResearchPaper.Text

' Get the database assignment grade from the TextBox control.
dblDatabaseAssignment = DatabaseAssignment.Text

' Get the in-class presentation grade from the TextBox control.
dblInclassPresentation = InclassPresentation.Text

' Get the homework lab assignments grade from the TextBox control.
dblHomeworkLabAssignments = HomeworkLabAssignments.Text

' Get the summary paper grade from the TextBox control.
dblSummaryPaper = SummaryPaper.Text

' Calculate the final average.
dblFinalAverage = (dblTests * 0.2) + (dblFinalExam * 0.2) + (dblQuizzes * 0.1) + (dblComputerPrograms * 0.1) + (dblResearchPaper * 0.1) + (dblDatabaseAssignment * 0.1) + (dblInclassPresentation * 0.1) + (dblHomeworkLabAssignments * 0.05) + (dblSummaryPaper * 0.05)

' Assign the final average to a Label control,
' with percent formatting.
FinalAverage.Text = dblFinalAverage

End Sub
Three answers:
Kornfan71
2012-03-28 14:43:43 UTC
After each number, you could add an if statement something like:



if number > 1 then

number = number / 100

end if



That would convert any number over 100% to a decimal percentage. However, this would not account for any values over 100!
?
2016-11-11 01:34:44 UTC
Public Sub EnforceNumeric(ByRef viKeyAscii As Integer, optionally available ByVal vbAllowBackspace As Boolean = authentic, optionally available ByVal vbAllowTab As Boolean = authentic, optionally available ByVal vbAllowDecimal As Boolean = fake) If (viKeyAscii > fifty seven Or viKeyAscii < 40 8) Then elect Case viKeyAscii Case vbKeyBack viKeyAscii = IIf(vbAllowBackspace, viKeyAscii, 0) Case viKeyAscii = vbKeyTab viKeyAscii = IIf(vbAllowTab, viKeyAscii, 0) Case 40 six 'Decimal viKeyAscii = IIf(vbAllowDecimal, viKeyAscii, 0) Case Else viKeyAscii = 0 end elect end If end Sub
texasmaverick
2012-03-29 05:53:12 UTC
I would do it as follows (multiply the dblFinalAverage by 100)



'

' Assign the final average to a Label control,

' with number formatting.

FinalAverage.Text = dblFinalAverage* 100.ToString("### %")



TexMav


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...