.NET Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgramming.NET Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old March 10th, 2004, 09:41 PM
lilisa lilisa is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 1 lilisa User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question VB.net big problem with arrays

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 error

Loop







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
Attached Files
File Type: zip Project 9.zip (30.4 KB, 365 views)

Reply With Quote
  #2  
Old March 20th, 2004, 10:37 AM
ShefaliAgrawal ShefaliAgrawal is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 4 ShefaliAgrawal User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thumbs up Do following changes

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








Reply With Quote
  #3  
Old March 20th, 2004, 10:38 AM
ShefaliAgrawal ShefaliAgrawal is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 4 ShefaliAgrawal User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Quote:
Originally Posted by ShefaliAgrawal
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








Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgramming.NET Development > VB.net big problem with arrays


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT