|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
I am working on a project to calculate curved and uncurved grades of 20 students. To calculate the curved grade I have to find mean and standard deviation. Also I have to grab the grades from a text file that contains student names and grades and load the grades into arrays. I think I have got the mean and standard deviation functions coded but I am having problems in loading the arrays from the textfile and also calling the mean and standard deviation functions. I am not a very good programmer so I am not sure to what I am doing wrong or I guess I dont know what to do next? So if anyone can please help me out I will be highly grateful. I have the project due by sunday afternoon so please help me out. I am pasting the code that I have Please feel free to comment and give suggestions.
PublicClass Form1 Inherits System.Windows.Forms.Form Dim fileinfo AsString PublicFunction calcmean(ByVal i() AsInteger) AsInteger Dim grade AsInteger Dim mean AsInteger For grade = 1 To 20 mean = mean + i(grade) Next calcmean = mean / 20 Return calcmean EndFunction PublicFunction SDev(ByVal calcmean()) AsDouble Dim num AsDouble Dim values() AsDouble Dim Difference AsDouble Dim total AsDouble Dim Temp AsDouble Dim STD AsDouble Difference = 0 DoWhile num < 20 Difference = ((values(num) - (CDbl(calcmean(num)))) ^ 2) Temp += Difference Difference = 0 num += 1 Loop total = (Temp / 20) STD = Math.Round(Math.Sqrt(total), 2) Return STD EndFunction PrivateSub MenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem2.Click Dim gdr As IO.StreamReader Dim grade AsInteger Dim openfiledialog1 AsNew OpenFileDialog openfiledialog1.ShowDialog() Try fileinfo = openfiledialog1.FileName gdr = IO.File.OpenText("grades9.txt") Catch openerr As IO.FileNotFoundException Catch openerr As IO.DirectoryNotFoundException EndTry DoWhile (gdr.Peek <> -1) grade = Int(gdr.ReadLine) ListBox1.Items.Add(grade) Loop EndSub PrivateSub MenuItem3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem3.Click Dim gdr As IO.StreamReader Dim grade AsInteger Dim j AsInteger Dim info AsInteger Dim openfiledialog1 AsNew OpenFileDialog openfiledialog1.ShowDialog() Try fileinfo = openfiledialog1.FileName gdr = IO.File.OpenText("grades9.txt") Catch openerr As IO.FileNotFoundException Catch openerr As IO.DirectoryNotFoundException EndTry DoWhile (gdr.Peek <> -1) grade = Int(gdr.ReadLine) For j = 1 To 20 grade = info Next calcmean(info) HEre is where i get the errorLoop EndSub EndClass Also the text fiel that i have to open is Smith 59 Anderson 60 Williams 65 Carter 75 Green 56 Fredricks 90 Hughes 66 Texan 62 Miller 98 Jones 72 Billings 95 Killian 71 Lane 63 Reed 77 Utter 65 Otter 77 Nugent 65 Ingles 50 Peters 85 Quinton 62 Please help me out I been working on this for a long time. I am attaching the whole project if anyone wants to look at it. LILISa |
|
#2
|
|||
|
|||
|
Hello,
Myself shefali,Make these changes in your code will work fine.Hope this will help you.Your calcmean and SDev ,calcmean is fine. PrivateSub MenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem2.Click Dim gdr As IO.StreamReader Dim grade AsInteger Dim openfiledialog1 AsNew OpenFileDialog openfiledialog1.ShowDialog() Try fileinfo = openfiledialog1.FileName gdr = IO.File.OpenText("Data.txt") Catch openerr As IO.FileNotFoundException Catch openerr As IO.DirectoryNotFoundException EndTry DoWhile (gdr.Peek <> -1) 'your text file also contains text If Val(gdr.Read) <> -1 Then grade = Int(gdr.Read) ListBox1.Items.Add(grade) EndIf Loop EndSub PrivateSub MenuItem3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem3.Click Dim gdr As IO.StreamReader Dim grade AsInteger Dim j AsInteger '************************************************* ** 'you have declared 'Dim info As Integer 'To be declared Dim info(1) AsInteger Dim openfiledialog1 AsNew OpenFileDialog openfiledialog1.ShowDialog() Try fileinfo = openfiledialog1.FileName gdr = IO.File.OpenText("Data.txt") Catch openerr As IO.FileNotFoundException Catch openerr As IO.DirectoryNotFoundException EndTry DoWhile (gdr.Peek <> -1) If Val(gdr.Read) <> -1 Then grade = Int(gdr.Read) For j = 1 To 20 '************************************************* ** 'Rediming info 'To be declared ReDimPreserve info(UBound(info) + 1) info(j) = grade Next calcmean(info) EndIf Loop EndSub |
|
#3
|
|||
|
|||
|
Quote:
|
![]() |
| Viewing: Dev Articles Community Forums > Programming > .NET Development > VB.net big problem with arrays |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|