Any incouraging words or just suggestions.

jbreth

Member
Joined
Oct 6, 2005
Messages
7
Location
Kansas
Programming Experience
Beginner
I am brand spanking new to programming. I am taking a class and we are studying visual basic.net. I am not catching on. We are in our third week and things just keep getting harder and harder. I am on the edge of just giving up. I know none of you know me but man I am getting so frustrated. I have done a little web designing and thought that maybe programming would come easy to me. WRONG!!!!! It is one of the hardest things for me to grasp. I don't know if it is because I have been out of school for so long or I am just stubborn but things are clicking. I need some suggestions. I can handle building the forms, it is the calculating and popup buttons, that throw me off I think. The book we are studying out of it Microsoft Visual Basic.net reloaded if any of you are familiar with this book let me know maybe you can help. I am looking for some kind of syntax reference or something similar. I don't know maybe you've got something to help me catch on. PLEASE I am in desperate need of Help!!!!

Thanks for listening to me babble on.
Jason
 
Here is a good example of what I run into everytime I try to program:

This is the problem we were given in class:

Professor Juarez

Create an application that displays a letter grade based on the average of three test scores entered by Professor Juarez. Each test is worth 100 points. Verify that the test scores entered by professor are numeric. Use the following information to complete the procedure:

Test Average Grade

90-100 A
80-89 B
70-79 C
60-69 D
below 60 F


------------------------------------------------------------------------
Here is what I have so far:

PrivateSub frmgrade_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesMyBase.Load
'calculate a letter grade

'declare variables
Dim decgrade1 AsDecimal
Dim decgrade2 AsDecimal
Dim decgrade3 AsDecimal
Dim strgrade AsString

'assign input values to variables
decgrade1 = Convert.ToDecimal(Me.txtgrade1.Text)
decgrade2 = Convert.ToDecimal(
Me.txtgrade2.Text)
decgrade3 = Convert.ToDecimal(
Me.txtgrade3.Text)

'determine whether the textboxes have numbers
If IsNumeric(Me.txtgrade1.Text) AndAlso IsNumeric(Me.txtgrade2.Text) AndAlso IsNumeric _
(
Me.txtgrade3.Text) Then

' calculate grade average
strgrade = decgrade1 + decgrade2 + decgrade3 / 3
EndIf

EndSub
End
Class

------------------------------------------------------------------------
I have attached the form that I created to go with this.

I am sure that this is easy for most of you but I am just continously running into the same problem. If any of you can give me pointers on how to get over this obstacle I would be greatly thankful. As I said this is the same spot on every assignment that I do that I get baffled. I don't know if I have even coded it right. Please help!!!! If I left anything out let me know.

Thanks once again,
Jason



 

Attachments

  • untitled.JPG
    untitled.JPG
    22.8 KB · Views: 70
A couple things:

1. You will want to check to make sure the user has entered numbers BEFORE you try to convert them from text to decimal. The way you have it now, if a user enters text, you will get an error.

2. You will want to place all of that code in your Calculate button's Click Event procedure instead of in the Form's Load procedure.

3. Your calculation has an error. You need parentheses around the three grades: ( decgrade1 + decgrade2 + decgrade3 ) / 3
 
Hey jbreth,

The first thing I'd say is don't panic!! from your code it looks like you're already getting a good grasp of how things work. You need to take that code out of the load event, anything in the load event will run when the form is first loaded. Try making a new sub called CalculateGrade and place your code inside it like this:

VB.NET:
private sub CalculateGrade()
'Paste all your code here
End sub

Then you need to run it when they press the button, so either go to deisign mode and double click on the button, or select the button from the left hand drop down box and select the click event from the right hand dropdown box. This will create a new sub to handle the button click. Inside this simply place CalculateGrade, and your code will be run when they click the button. Sorry if i've over simplified things, but sometimes it helps.

Hope this helps.
 
In order to convert that to a letter, use a Select Case statement.

VB.NET:
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] avgGrade [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Decimal[/COLOR][/SIZE][SIZE=2] = (decgrade1 + decgrade2 + decgrade3) / 3 [/SIZE][SIZE=2][COLOR=#008000]'You should not store that value in your string
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Select [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Case[/COLOR][/SIZE][SIZE=2] avgGrade
[/SIZE][SIZE=2][COLOR=#0000ff]Case [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Is[/COLOR][/SIZE][SIZE=2] >= 90
strGrade = "A"
[/SIZE][SIZE=2][COLOR=#0000ff]Case [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Is[/COLOR][/SIZE][SIZE=2] >= 80
strGrade = "B"
[/SIZE][SIZE=2][COLOR=#0000ff]Case [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Is[/COLOR][/SIZE][SIZE=2] >= 70
strGrade = "C"
[/SIZE][SIZE=2][COLOR=#0000ff]Case [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Is[/COLOR][/SIZE][SIZE=2] >= 60
strGrade = "D"
[/SIZE][SIZE=2][COLOR=#0000ff]Case [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Else
[/COLOR][/SIZE][SIZE=2]strGrade = "F"
[/SIZE][SIZE=2][COLOR=#0000ff]End [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Select[/COLOR][/SIZE]

 
Something like this?

Private Sub btnCalc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalc.Click
'calculate a letter grade
'declare variables
Dim decgrade1 As Decimal
Dim decgrade2 As Decimal
Dim decgrade3 As Decimal
Dim strgrade As String



'determine whether the textboxes have numbers
If IsNumeric(Me.txtgrade1.Text) AndAlso IsNumeric(Me.txtgrade2.Text) AndAlso IsNumeric _
(
Me.txtgrade3.Text) Then
' calculate grade average
Dim avgGrade As Decimal = (decgrade1 + decgrade2 + decgrade3) / 3
Select Case avgGrade
Case Is >= 90
strgrade = "A"
Case Is >= 80
strgrade = "B"
Case Is >= 70
strgrade = "C"
Case Is >= 60
strgrade = "D"
Case Else
strgrade = "F"
End Select
End If
End Sub
End
Class
 
One small suggestion

When you learn .NET, make it a point that from day 1, you view the language as an Object Oriented Language more than viewing it as a normal VB 6 stuff. Get used to the Object oriented concepts as much as you can during your learning phase. Try to use wherever you can. This will help you in near future.

Sivi.
 
Yes, except you forgot your conversion code.

VB.NET:
[COLOR=#008000]'assign input values to variables
[/COLOR][SIZE=2]decgrade1 = Convert.ToDecimal([/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].txtgrade1.Text)
decgrade2 = Convert.ToDecimal([/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].txtgrade2.Text)
decgrade3 = Convert.ToDecimal([/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].txtgrade3.Text)
[/SIZE]
Put that right before
VB.NET:
[COLOR=#0000ff]Dim[/COLOR][SIZE=2] avgGrade [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Decimal[/COLOR][/SIZE][SIZE=2] = (decgrade1 + decgrade2 + decgrade3) / 3
[/SIZE]
 
Then, of course, at the end, you have to do this:

lblLetterGrade.Text = strGrade 'Show the letter grade in your Grade Label.
 
Finally got it to work. Hopefully my next program will come to me a lot easier. I am just having a hard time burning the basic structure, layout into my head. I just ordered a pocket reference book from barnes and noble, maybe and hopefully it will help. I can't thank you guys enough for your help.

Thanks
Jason
 
Back
Top