|
-
May 10th, 2007, 06:56 AM
#1
Thread Starter
New Member
adding to my array(some help plz :)
Code:
Dim intx As Integer
Dim intmark As Integer
Dim inttotalmarks As Integer
Dim intstudents As Integer
Dim inttotal As Integer
Dim dblpercent As Double
Dim chargrade(30) As Char
Dim strgrade As String
intstudents = Convert.ToInt32(txtnoofstudents.Text)
For intx = 0 To (intstudents - 1)
intmark = InputBox("Please enter the students mark")
inttotal = Convert.ToInt32(txtmarksavailable.Text)
dblpercent = intmark / inttotal * 100
If Me.radday.Checked Then
If dblpercent > 89 Then
strgrade = "A"
ElseIf dblpercent > 79 Then
strgrade = "B"
ElseIf dblpercent > 69 Then
strgrade = "C"
ElseIf dblpercent > 59 Then
strgrade = "D"
ElseIf dblpercent > 1 Then
strgrade = "F"
End If
Else
If dblpercent > 84 Then
strgrade = "A"
ElseIf dblpercent > 74 Then
strgrade = "B"
ElseIf dblpercent > 64 Then
strgrade = "C"
ElseIf dblpercent > 49 Then
strgrade = "D"
ElseIf dblpercent > 1 Then
strgrade = "F"
End If
End If
chargrade(intx) = Convert.ToChar(strgrade)
next
ok well thats my code and the problem i am having is with the last line, what i need is that after each grade is calculated to be passed into the array chargrade for futher processing later on....any suggestions on how to make that line work?
-
May 10th, 2007, 07:18 AM
#2
Re: adding to my array(some help plz :)
You code looks ok to me, what is the problem exactly?
If you put MessageBox.Show(chargrade(intx).ToString) directly after the last line you should see that each value is being correctly added to the array. Is that not the case when you run it?
-
May 10th, 2007, 07:27 AM
#3
Re: adding to my array(some help plz :)
your are setting the calculated value to an locally declared array, if you need to have those values outside this Sub, you have to declare the array in the general section. Also you have declared a fixed length array, are the 30 entries enough?
You're welcome to rate this post!
If your problem is solved, please use the Mark thread as resolved button
Wait, I'm too old to hurry!
-
May 10th, 2007, 07:51 AM
#4
Thread Starter
New Member
Re: adding to my array(some help plz :)
ok thanks for replyin...but the line i had the problem with has fixed itself some how...what i need now is for the line to display each grade below each other this is the line i have currently in which displays them beside each other
Code:
Label1.Text = Label1.Text & chargrade & ControlChars.NewLine
-
May 10th, 2007, 07:59 AM
#5
Re: adding to my array(some help plz :)
vb Code:
Me.Label1.Text &= charGrade & Environment.NewLine
-
May 10th, 2007, 08:01 AM
#6
Thread Starter
New Member
Re: adding to my array(some help plz :)
unfortunately that code also brings the grades up on the same line
-
May 10th, 2007, 08:12 AM
#7
Re: adding to my array(some help plz :)
Looking above your last post i see charGrade is actually an array so just referring to it by charGrade doesn't really make sense.
Do you want them displayed at the end once they have all entered their grades or while they are inputting them.
For example this works fine:
vb Code:
charGrade(0) = "A"c
charGrade(1) = "B"c
charGrade(2) = "C"c
charGrade(3) = "D"c
For i As Integer = 0 To 3
Me.Label1.Text &= charGrade(i) & Environment.NewLine
Next
-
May 10th, 2007, 08:16 AM
#8
Thread Starter
New Member
Re: adding to my array(some help plz :)
what i need is once all the marks are input they are then transferred into grades using my if statements. i am not all that great with programming but i think i put it outside the loop so it would display after everything is input...looking at that code it would display them as i input the marks i think
-
May 10th, 2007, 08:21 AM
#9
Re: adding to my array(some help plz :)
If you add this after everything has been completed (all marks have been entered and converted) then it will work (obviously rename the controls or variables as you need).
vb Code:
Me.Label1.Text = String.Empty
For i As Integer = 0 To charGrade.Length - 1
Me.Label1.Text &= charGrade(i) & Environment.NewLine
Next
-
May 10th, 2007, 08:47 AM
#10
Thread Starter
New Member
Re: adding to my array(some help plz :)
ok ty v much that works...they next stage of the program is for me to count the amount of each grade so if i have b,b,b,c,d,c i need to display that i have 3 bs, 2 cs and 1 d anyone have any ideas how to do that?
-
May 10th, 2007, 09:10 AM
#11
Re: adding to my array(some help plz :)
Well you could have 5 counters for each of the grades. Loop through each character in the gradeChar array and increase the counter by 1 if found at that index. Display them all at the end.
Although JMC posted something last night which was used to count the number of occurences of a letter using a dictionary. Something like this:
vb Code:
Dim gradeCount As New Dictionary(Of Char, Integer)
For Each c As Char In charGrade
If gradeCount.ContainsKey(c) Then
gradeCount(c) += 1
Else
gradeCount.Add(c, 1)
End If
Next
For Each itm As KeyValuePair(Of Char, Integer) In gradeCount
MessageBox.Show("Grade " & itm.Key.ToString & " : " & itm.Value.ToString & " times")
Next
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|