What is wrong with my code?

I am new to VB.net and programming in general. I need some help in figuring out what the problem is with my program. My intention is that I should be able to put in a number in any of the 5 boxes and get my grade calculated. If I launch the program and put in 100 in any of the boxes and calculate the grade I get a 33 with a grade of F. If I hit the Clear button and then try again, I get the expected results. I can't figure out what I have that is causing the bad calculation when I launch the application.

 

 

1    Option Explicit On
2    Option Strict On
3    
4    
5    Public Class frmMain
6    
7        Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
8            Me.Close()
9        End Sub
10   
11       Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
12   
13           ' Clear the Values
14           Me.txtStudentName.Text = String.Empty
15           Me.txtMark1.Text = String.Empty
16           Me.txtMark2.Text = String.Empty
17           Me.txtMark3.Text = String.Empty
18           Me.txtMark4.Text = String.Empty
19           Me.txtMark5.Text = String.Empty
20           Me.lblAverageCalc.Text = String.Empty
21           Me.lblStudent.Text = String.Empty
22           Me.lblGrade.Text = String.Empty
23   
24       End Sub
25   
26       Private Sub btnCalc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalc.Click
27   
28           ' Declare the variables
29           Dim totalAverage As Double
30           Dim mark1 As Double
31           Dim mark2 As Double
32           Dim mark3 As Double
33           Dim mark4 As Double
34           Dim mark5 As Double
35           Dim grade As String
36           Dim average As Double
37   
38   
39           ' Convert the text boxes to Doubles for calculations
40           Double.TryParse(Me.txtMark1.Text, mark1)
41           Double.TryParse(Me.txtMark2.Text, mark2)
42           Double.TryParse(Me.txtMark3.Text, mark3)
43           Double.TryParse(Me.txtMark4.Text, mark4)
44           Double.TryParse(Me.txtMark5.Text, mark5)
45   
46           ' Validate that there is an entry in the text boxes.
47           'If Me.txtMark1.Text = String.Empty Or Me.txtMark2.Text = String.Empty Or Me.txtMark3.Text = String.Empty _
48           ' Or Me.txtMark4.Text = String.Empty Or Me.txtMark5.Text = String.Empty Then
49           'MessageBox.Show("Please enter all 5 grades", "Need more grades", MessageBoxButtons.OK)
50           'End If
51   
52           'Determine how many grades are there
53           If Me.txtMark1.Text <> String.Empty Then
54               average = average + 1
55           End If
56   
57           If Me.txtMark2.Text <> String.Empty Then
58               average = average + 1
59           End If
60   
61           If Me.txtMark3.Text <> String.Empty Then
62               average = average + 1
63           End If
64   
65           If Me.txtMark4.Text <> String.Empty Then
66               average = average + 1
67           End If
68   
69           If Me.txtMark5.Text <> String.Empty Then
70               average = average + 1
71           End If
72   
73           ' Calculate the average
74           totalAverage = (mark1 + mark2 + mark3 + mark4 + mark5) / average
75   
76   
77           ' Display grade based on score from totalAverage
78           Select Case totalAverage
79               Case 80 To 100
80                   grade = "A"
81               Case 65 To 79
82                   grade = "B"
83               Case 40 To 64
84                   grade = "C"
85               Case 40
86                   grade = "D"
87               Case 0 To 39
88                   grade = "F"
89           End Select
90   
91           Me.lblAverageCalc.Text = Convert.ToString(totalAverage)
92           Me.lblGrade.Text = Convert.ToString(grade)
93   
94       End Sub
95   End Class
  
0
nickbtheitguy
1/21/2009 3:08:57 AM
asp.net.visual-basic.net 3721 articles. 0 followers. Follow

2 Replies
508 Views

Similar Articles

[PageSpeed] 47

nickbtheitguy:
Me.txtMark1.Text <> String.Empty

I dont see any problem with your code ...evry thing seems to be alright....

try replacing the above line by

Me.txtMark1.Text.Trim <> ""

 


Sri
Please mark as answer if it helped you
0
jsriharsha
1/21/2009 4:36:42 AM

 I think the probelm is with "average" variable. Check that variable at runtime.

ps: These are Asp.Net forums. I think it's a windows forms question. To get better respone for your windows forms questions, post in following forums..

http://social.msdn.microsoft.com/Forums/en-US/category/netdevelopment/



My Blog


"Don't be afraid to be wrong; otherwise you'll never be right."
0
budugu
1/21/2009 4:59:34 AM
Reply:

Similar Artilces:

Visual Studio .Net? Visual Basic .Net?
Okay, I admit it -- I know nothing about .Net. I'm a Visual Basic and ASP developer. DotNetNuke is my first tentative step into the whole ".Net Thing", and I'm looking for some advice... What do I really need to be able to make some modifications, or new modules for DotNetNuke? Do I need the full, THOUSAND DOLLAR Visual Studio .Net 2003 package, or can I get away with the HUNDRED DOLLAR Visual Basic .Net Standard package?Chameleon Systems, Inc. You can use webmatrix, available here for free. One of the drawbacks of webmatrix however is that it does not support code-be...

Visual Basic.NET or Visual Studio.NET?
OK, this has probably been asked before... I'm a student looking to cut my costs, and I can do this by just purchasing Visual Basic.NET as opposed to the fully-fledged Visual Studio.NET application. Of course, I'll only be able to program in VB, but that's fine with me. I wanted to know if all of the ASP.NET specific options are available, such as using a WYSIWYG editor? I'd also like to know if VB.NET has IntelliSense, or that's a specific option only available to Visual Studio.NET users. Thanks in advance. I'd have to believe that VB.Net has intellisense. What is the price d...

Visual Basic.NET or Visual Studio.NET? #2
I am currently using the Web Matrix to develop ASP.NET applications, but I am keep to upgrade to VS.NET. However, I can't justify spending $1,000 at the moment. I then found the MUCH cheaper "Visual Basic .NET 2003 Standard Edition" which is only $100. I have very little C# knowledge, and use Basic almost all the time. Would this be a good tool to use for web development? Does it support all the code behind stuff that VS users love so much? Thanks!! I use "VB.NET Standard Edition" and I'm happy with it. It has exactly the same features as Visual Studio.NET. Th...

Visual Basic .NET 2003 vs Visual Studio .NET 2003
Hi, If im going to be coding my ASP.NET in just VB.NET then would I be able to go for the cheaper option of buying Visual Basic .NET 2003 ?? - Carl S Yes.Starting with ASP.NET 2.0? Look at:Programming Microsoft Web Forms My Blog Are there any limitations if I was doing my ASP.NET with VB.NET in Visual Basic .NET 2003 than if I was using the full Visual Studio .NET 2003 ?? Or are the only advantages of Visual Studio .NET 2003 in that it supports more programming languages ?? - Carl S You should check the MS Web site, but I believe that, given an edition (Standard, Professional...

ADO.NET Programming in Visual Basic .NET
Has anyone read "ADO.NET Programming in Visual Basic .NET, Second Edition" by Steve Holzner (Author), Bob Howell (Author)? I am trying to working on a project and there are a few things that I need to tie up quickly in my web forms. Is this book a good one? karls------------------------------------'Old and wrinkled is not what I expected to become when I grew up!'...

the code in visual basic.net
how do i make the code stay in place in visual basic.net? when i go to the design view and then back to the code view then my code has all been put to the left side and the structure that i made with tabs is gone.. can i choose somewhere not to make that happen? so i don't have to tab all over again? That's real odd. Mine does the opposite. It auto tabs and makes everything look purty. :)In this world there are 10 types of people, those that know binary and those who don't....

Converting Visual Basic 6 to Visual Basic .NET
Hi, I found this program that would get the mac address of a computer given its IP. I converted it into vb.net and it gave 2 errors. It said that I couldn't use "any" in declarations, so I found out what variable it was tryign to pass and changed the any to that data type. Now, the program will start in vb.net... but when I click the button, it returns the wrong mac address, while the one in vb6 returned the correct one.All you have to do is add 2 textboxes to the form and 1 button, dont change their names.::::::::::VB6 CODE::::::::::Option ExplicitPrivate Const NO_ERROR = 0Private Declare F...

C# Visual Basic.NET JScript.NET what should I choose ?
I'm just a beginner with programing ASP.NET web sistes. Unfortunatelly I don't know any of the languages supported by ASP. (By the time I programmed in DELPHI and SQL) So I should start to learn one of the languages. Could somebody help me to choose the language I should use ? Which and why ? Thanks in advance, Gonzi Use C# or VB.NET, which ever you are comfortable with. Go here to see sample of both in use http://samples.gotdotnet.com/quickstart/aspplus Ultimately, once you get more advanced, you'll really want to become comfortable with both languages. I ...

Convert VBA Code to Visual Basic .NET When Migrating to Visual Studio 2005 Tools for Office
followup to grc.techtalk Convert VBA Code to Visual Basic .NET When Migrating to Visual Studio 2005 Tools for Office http://msdn.microsoft.com/office/default.aspx?pull=/library/en-us/odc_vsto2005_ta/html/OfficeVSTOLanguageMigrationFromVBA.asp ----------------------------------------------------------- Quote ----------------------------------------------------------- Dale Oberg ArtinSoft.com March 2005 Applies to: �����Microsoft�Visual�Studio�2005 �����Microsoft�Visual�Studio�2005�Tools�for�the�Microsoft�Office�System �����Microsoft�Visual�Basic�.NET �����Microsoft�Visual�...

Can I go from VS .NET 2003 to Visual Basic .NET 2003?
Hi, I just developed a commercial application using the trial version of Visual Studio .NET 2003.  My trial is about to expire.  I was hoping .NET 2.0 would be released by now, but that is obviously months away so I'm wondering if I could save a few hundred bucks by buying Visual Basic .NET 2003(around $110 i think) instead of having to buy Visual Studio .NET 2003, which I believe is up around $600 or so.   All my code is Visual Basic, so that's why I'm thinking that's all I need.  And it's mostly web development that I do if that matters.  T...

Translate c#.net code to vb.net code
Hi I can usually do the translation myself, but this time I am a bit stumped  Let us consider to rewrite Urls (more than 16000 links) using a table. Save original url and rewritten url in a table. Now add a class file in App_Code folder. class UrlRewriteModule : IHttpModule{    public void Dispose()    {        // Nothing to dispose    }    public void Init(HttpApplication context)    {        context.BeginRequest += new EventHandler(context...

Visual C#.Net vs Visual Studio.Net
I have read in other posts a lot of people recommending Visual Studio.Net over the Web Matrix. My query is: why is there a £700 difference between VS.Net and Visual C#.Net? As a c# developer, I won't need any VB functionality. I also don't require Visual Source Safe, as projects are generally small and manageable. What features are lacking in Visual c#.net that justifies the price difference? Does it have Intellisense / Dubuggers / Compilers? These are the features that would make me pay for it instead of continuing with WM, but I need to know if tehre is serious functionality missin...

How to convert C#.Net code to VB.Net code ???...
HI, i was searching something new, then i suddenly find some tips to convert C#.Net code to VB.Net but i did not do well. i am puttint its url here plz tell me how to convert C#.Net code to VB.Net. http://www.dotnetspider.com/code/C-273-Convert-C-VB-NET.aspx Jasim...Please remember to click “Mark as Answer” on the post that helps youJasim AkhtarNew Delhi ( INDIA ) It would be better if you write the problem you having, while converting from C# to VB.NET. You cannot completely rely on online converters. ThanksMark post(s) as "Answer" that helped youElectronic ScrewWebsite||Bl...

use VB.NET and C#.NET code in the same C#.NET project
All-- Here is a sample that is "off the beaten path", (at least for me). Is it possible, in an ASP.NET application, using the code-behind page building technique, to have both pages written in VB.NET and pages written C#.NET?At http://www.WebLogicArts.com/DemoList.aspx there is a sample that shows that, (contrary to popular belief), it IS possible to mix ASP.NET pages built with C#.NET with ASP.NET pages built with VB.NET in the same VS.NET 2003 project. Note that this is just a "fun" sample to see if it can be done and I do not recommend this practice as a "standard" way of develo...

What are the diff. visual basic 6 and vb.net ? How to convert the VB6 project to vb.net proj ?
What are the diff. visual basic 6 and vb.net ? How to convert the VB6 project to vb.net proj ? with code and interface too. There are entire forums dedicated to the differences between the two, and to convert your projects you should try the upgrade wizard in Visual Studio....

Web resources about - What is wrong with my code? - asp.net.visual-basic.net

Wrong - Wikipedia, the free encyclopedia
while civil law countries tend to have some additional categories, such as contraventions . Moral wrong is an underlying concept for legal wrong, ...

NASCAR Directs Facebook Users To Wrong TV Network For Pure Michigan 400
Facebook pages are a useful tool for brands to share information, but they may want to ensure that the information being shared is correct, which ...

Ken Ham - Well, our new “Thank God You're Wrong” billboard... - Facebook
Well, our new “Thank God You're Wrong” billboard campaign began with a big bang (☺ ) yesterday—which we praise the Lord for. As expected, many ...

Facebook says bug caused wrong contact syncing on some users’ phones
A contact synchronization bug, combined with Facebook’s latest changes to users’ email visibility settings , led some mobile phones to update ...

What Went Wrong (@AmericaWWW) on Twitter
Sign in Sign up To bring you Twitter, we and our partners use cookies on our and other websites. Cookies help personalize Twitter content, tailor ...

Scripting News: Silicon Valley is wrong about college.
Lately I've been thinking a lot about startup culture, and am reminded of its nobility having started three companies in my career, and learned ...

Scripting News: Why Charles Pierce is wrong about Ezra Klein being wrong.
... Pierce's attitude many times, from all kinds of ink-stained pros, some very accomplished. The arrogance is impressive, but they're still wrong. ...

Scripting News: I had to get a NYT Digital Subscription to figure out what's wrong.
Yesterday I posted a tweet with some feedback for the NY Times marketers. Getting a NYT Digital Subscription should open up something new and ...

Scripting News: Privacy is the sometimes wrong word.
You can talk about the security of your personal information in a different ways, each of which suggests a different set of issues. If I call ...

Don’t Take the Wrong Paths to Power
... it, and hoard it. If you have to bruise egos along the way, so what? No one will care or even remember how you got to the Don’t Take the Wrong ...

Resources last updated: 1/18/2016 3:28:47 AM