corsasport.co.uk
 

Corsa Sport » Message Board » Off Day » Geek Day » Anyone here good with coding Visual Studio.net?


New Topic

New Poll
  Subscribe | Add to Favourites

You are not logged in and may not post or reply to messages. Please log in or create a new account or mail us about fixing an existing one - register@corsasport.co.uk

There are also many more features available when you are logged in such as private messages, buddy list, location services, post search and more.


Author Anyone here good with coding Visual Studio.net?
Ash_EP3
Member

Registered: 15th May 07
Location: Melksham, Wiltshire
User status: Offline
9th May 08 at 13:13   View User's Profile U2U Member Reply With Quote

I need some help with working out averages of values entered!!!

Please help if you can

Thanks
James
Member

Registered: 1st Jun 02
Location: Surrey
User status: Offline
9th May 08 at 13:21   View User's Profile U2U Member Reply With Quote

Yes I do it for a living - what language?
Paul_J
Member

Registered: 6th Jun 02
Location: London
User status: Offline
9th May 08 at 13:53   View User's Profile U2U Member Reply With Quote

averages of values entered?

average = ((value1 + value2 + value3) / 3)



p.s. Got any more detail? how many values? how are they inputted? what language?
Ash_EP3
Member

Registered: 15th May 07
Location: Melksham, Wiltshire
User status: Offline
9th May 08 at 14:23   View User's Profile U2U Member Reply With Quote

Hi guys,

Im trying to upload my code onto this page but the bloody program won't open in the library

College shite

Basically its a "Car Voting Program" the user will select a car (in a listbox) and a picture is displayed...

They will then vote on it using a scrollbar (value 1-10) they then need to submit the value (which is then stored using the write file command & a counter is used to show the amount of votes)

The sum is something like:

score1 = score1 + val(txtrating.text) (value of rating)
counter1 = txtvotes.text
counter1 = counter1 + 1
average = score1 / counter1

I would like to have an average score for each car (which is in a list) so when they click on the next car the current values are stored and boxes are reset (cleared)

I will send the code as soon as I can thanks
Paul_J
Member

Registered: 6th Jun 02
Location: London
User status: Offline
9th May 08 at 14:24   View User's Profile U2U Member Reply With Quote

this in vb.net?
Ash_EP3
Member

Registered: 15th May 07
Location: Melksham, Wiltshire
User status: Offline
9th May 08 at 14:26   View User's Profile U2U Member Reply With Quote

^^ Yes mate

Im using Visual Studio 2005
Paul_J
Member

Registered: 6th Jun 02
Location: London
User status: Offline
9th May 08 at 14:28   View User's Profile U2U Member Reply With Quote

I don't 100% get what you're trying to do. Do you have to use text files to hold the 'data'? Can't you use a database back end?

Ash_EP3
Member

Registered: 15th May 07
Location: Melksham, Wiltshire
User status: Offline
9th May 08 at 14:33   View User's Profile U2U Member Reply With Quote

The data is stored to a text file, using the Steamwriter and writefile command (sorry mate I can't remember off the top of my head)

I will post up the code asap but the bloody program isn't loaded on these machines
Paul_J
Member

Registered: 6th Jun 02
Location: London
User status: Offline
9th May 08 at 14:38   View User's Profile U2U Member Reply With Quote

Just what i'm saying is, a file will essentially be a list of sequential data. So you can load that data from the text file into say a list...

So a text file containing names of cars, could be loaded and then displayed in a list.

but then when you click say the 'ferrari' in the list, there will be no method of fetching the data relative to the ferrari. i.e. to fetch the ferrari's previous average score etc.

With a database, you could have a table of cars and data relative to the car on number of votes and total vote amount.

So when the application loads, it calls to the database, loads the contents of 'car' table into a list - giving you a list of cars. Then you click a car, it queries the data base and fetches for that car, a count and total vote value.

Then you can do the sums from that easily and display it to the user.
Paul_J
Member

Registered: 6th Jun 02
Location: London
User status: Offline
9th May 08 at 14:41   View User's Profile U2U Member Reply With Quote

So for example. you end up with something like this (v.basic example)



Basically it's gathered data from db to populate the car list. You click the car, it fetches car picture / details, votes and average. Then you click submit and it updates the vote / count value back in the database.
Ash_EP3
Member

Registered: 15th May 07
Location: Melksham, Wiltshire
User status: Offline
9th May 08 at 14:45   View User's Profile U2U Member Reply With Quote

Well done that man, lol nice picture yea thats a good example of what I have done.

I shall ask my tutor if I am able to use a database to store the data (not entirely sure on this yet)

How long did that just take you btw?
Paul_J
Member

Registered: 6th Jun 02
Location: London
User status: Offline
9th May 08 at 14:52   View User's Profile U2U Member Reply With Quote

2 minutes

hmm... it could work with files, but you'd probably have to have multiple files...

So you'd have for instance.

carlist.txt = list of cars (for listbox).
nameofcar1.txt
nameofcar2.txt
nameofcar3.txt
nameofcar4.txt

etc

So in my example above you'd have

carlist.txt =

"
Ferrari_355
106_Gti
Porsche_911
"

then you'd have files

Ferrari_355.txt
106_Gti.txt
Porsche_911.txt

Then in each individual car file - like Ferrari_355.txt you could have number for vote total, number of votes, image name?

Then you just do something which goes

when clicking on item in list, open file name of (listbox1.SelectedItems.Item + ".txt") ... read in each into a variable (seperated by commas or whatever).

so you inport ferrari_355.txt which contains

104,11,Ferrari.jpg

score = 104
counter = 11
image = Ferrari.jpg

and go from there.

Then when you click submit, it takes the currently loaded information adds the new count to counter and new vote to score ... writes it all back to a file (overwriting any file existing or creating a new one if it doesn't exist).

That'd work, but it's not very good or scalable. A database would make your life much easier.

[Edited on 09-05-2008 by Paul_J]
Ash_EP3
Member

Registered: 15th May 07
Location: Melksham, Wiltshire
User status: Offline
9th May 08 at 14:55   View User's Profile U2U Member Reply With Quote

Cheers Paul, im useless at programming
Paul_J
Member

Registered: 6th Jun 02
Location: London
User status: Offline
9th May 08 at 14:58   View User's Profile U2U Member Reply With Quote

no prob. Find out what constraints you have to how you can do it. I hate how school / college can sometimes put annoying constraints on how you should do something which makes it harder.

If you have to use files as import, a xml file may be better than just a .txt file, at least then there's some structure to the data.
James
Member

Registered: 1st Jun 02
Location: Surrey
User status: Offline
9th May 08 at 15:01   View User's Profile U2U Member Reply With Quote

XML FTW!
Paul_J
Member

Registered: 6th Jun 02
Location: London
User status: Offline
9th May 08 at 15:05   View User's Profile U2U Member Reply With Quote

Hmm... I suppose if it's a really small example, just to get it to load and save to 1 single file. You could use a big multi dimensional array.

not the ideal solution, but would work.

So like cars[10,4] for 10 cars.

It reads the data from the file seperated by commas...

for each line of the file increment y, for each comma increment x

cars[y,x] = whatever

cars[0,0] = carname
cars[0,1] = votes
cars[0,2] = score
cars[0,3] = imagesrc

new line of file increment incremenet y

cars[1,0] = car name
cars[1,1] = votes
cars[1,2] = counter

etc etc

Then you basically compile a list for all elements [0,0], [1,0], [2,0], [3,0], [4,0] etc

that'd give you a list of the car names.

Then when they click on the list, get the index value of that list item, and use it to access the rest of the car details.

so if you've clicked on the 4th car

[4,0] = name
[4,1] = votes
[4,2] = counter

etc...
Paul_J
Member

Registered: 6th Jun 02
Location: London
User status: Offline
9th May 08 at 15:06   View User's Profile U2U Member Reply With Quote

quote:
Originally posted by James
XML FTW!


yeh I have a feeling though, they won't be allowed to use xml, databases or anything like that.

I've got a feeling they will have to read and write plain text, to a text file
James
Member

Registered: 1st Jun 02
Location: Surrey
User status: Offline
9th May 08 at 15:09   View User's Profile U2U Member Reply With Quote

.txt FTW!
ed
Member

Registered: 10th Sep 03
User status: Offline
9th May 08 at 15:11   View User's Profile U2U Member Reply With Quote

When I learned stuff like this first time round I was only allowed to use a flat file system. Bit of an arse because there are so many better ways of doing it...
ed
Member

Registered: 10th Sep 03
User status: Offline
9th May 08 at 15:12   View User's Profile U2U Member Reply With Quote

.dat FTW...
Ash_EP3
Member

Registered: 15th May 07
Location: Melksham, Wiltshire
User status: Offline
14th May 08 at 08:55   View User's Profile U2U Member Reply With Quote

Here is the code for the button which I need to work (for calculating the average scores)

Private Sub cmdAverage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAverage.Click
Dim carfile As New System.IO.StreamWriter("H:\ITP\Assignment 3\Car Voting (assignment 3)\test.txt")
carfile.WriteLine(score1)
carfile.WriteLine(score2)
carfile.WriteLine(score3)
carfile.WriteLine(score4)
carfile.WriteLine(score5)

score1 = score1 + Val(txtrating.Text)
counter1 = counter1 + 1
txtvotes.Text = counter1
lstAverage.Text = score1 / counter1

End Sub

Should this work? if this is not enough code I will add more thanks
Paul_J
Member

Registered: 6th Jun 02
Location: London
User status: Offline
14th May 08 at 09:45   View User's Profile U2U Member Reply With Quote

well where's counter value coming from?

Ash_EP3
Member

Registered: 15th May 07
Location: Melksham, Wiltshire
User status: Offline
14th May 08 at 10:55   View User's Profile U2U Member Reply With Quote

Public Class frmCarVoting
Dim counter As Integer
Dim counter1 As Integer
Dim counter2 As Integer
Dim counter3 As Integer
Dim counter4 As Integer
Dim counter5 As Integer
Dim cars(4) As String
Dim score1 As Integer
Dim score2 As Integer
Dim score3 As Integer
Dim score4 As Integer
Dim score5 As Integer
Dim car1 As String
Dim average As Integer

Private Sub HScrollBar1_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles HScrollBar1.Scroll
txtrating.Text = HScrollBar1.Value
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
PictureBox1.Image = My.Resources.ariel_atom
End Sub
Private Sub cmdRegister_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdRegister.Click
counter = counter + 1
txtvotes.Text = counter

HScrollBar1.Value = 1
txtrating.Text = ""

End Sub

Private Sub txtrating_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtrating.TextChanged
txtrating.Text = HScrollBar1.Value
End Sub

Private Sub lstCars_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstCars.SelectedIndexChanged
If lstCars.SelectedIndex = 0 Then
PictureBox1.Image = My.Resources.ariel_atom
lblName.Text = lstCars.SelectedItem
End If
If lstCars.SelectedIndex = 1 Then
PictureBox1.Image = My.Resources.civic_type_r
lblName.Text = lstCars.SelectedItem
End If
If lstCars.SelectedIndex = 2 Then
PictureBox1.Image = My.Resources.golf_w12_650
lblName.Text = lstCars.SelectedItem
End If
If lstCars.SelectedIndex = 3 Then
PictureBox1.Image = My.Resources.lambo_gallardo
lblName.Text = lstCars.SelectedItem
End If
If lstCars.SelectedIndex = 4 Then
PictureBox1.Image = My.Resources.porsche_carrera_gt
lblName.Text = lstCars.SelectedItem
End If
End Sub

Private Sub cmdAverage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAverage.Click
Dim carfile As New System.IO.StreamWriter("H:\ITP\Assignment 3\Car Voting (assignment 3)\test.txt")
carfile.WriteLine(score1)
carfile.WriteLine(score2)
carfile.WriteLine(score3)
carfile.WriteLine(score4)
carfile.WriteLine(score5)

score1 = score1 + Val(txtrating.Text)
counter1 = counter1 + 1
txtvotes.Text = counter1
lstAverage.Text = score1 / counter1

End Sub
End Class

This is my full code, counter value is being calculated on how many times someone presses the "register rating" button

 
New Topic

New Poll

  Related Threads Author Forum Replies Views Last Post
Computers geeks look in here Sam Geek Day 8 1052
7th May 05 at 15:46
by Sam
 
Visual Studio 2005 James Geek Day 8 678
18th Nov 05 at 12:27
by Andrew
 
What software do you lot use to make web pages? Pablo Geek Day 34 1291
9th Dec 05 at 01:12
by Ian
 
Anyone use VB.NET? Pablo Geek Day 3 116
19th Apr 07 at 08:10
by Pablo
 
Visual Studio 6 - How much is it worth? Welsh Dan Geek Day 3 91
10th Nov 07 at 03:27
by Welsh Dan
 

Corsa Sport » Message Board » Off Day » Geek Day » Anyone here good with coding Visual Studio.net? 29 database queries in 0.0173700 seconds