Need some help with this code… (VB2015)

What the program is about and what it needs to do: A school is running a competition. Each of the four houses (Alpha, Beta, and Gamma) enters a team of senior pupils. The show is performed on three evenings- Wednesday, Thursday and Friday. The cost of a ticket on the Wednesday and Thursday night is £5 and the cost of the ticket on Friday night is £10. Each order of tickets can only be for one of the nights. Anyone wishing to attend on more than one occasion should make multiple orders. The money raised will go to the top charity suggested by customers/ The school is trying out the sale of the tickets via the school website in addition to being on sale from the school office.

What the program NEEDS to do!

I’ve to write a program that uses sub-programs and parameters to find out which method of purchase has been used most and the total amount of money raised from all sales so far. I was given a test file that contains the data from 300 orders- I should be able to import data from this file for use in my program. So by using that file of data, the program should produce the following output:

“Choral Shield <year> ” “The most popular method of sales is __” “Money raised for charity: £__”

My program should THEN be able to export all of the data for ONLY Friday nights sales to an external file.

An example of the data taken from the CSV file is: (CustomerID, TicketID, TicketNO, METHDofSales) (C001,F5,10,S) (C002,W1,12,W)

Public Class Form1

Dim filestring As String Dim custid(299) As String Dim ticktid(299) As String Dim tickts(299) As Integer Dim sales(299) As String Private Sub cmdend_Click(sender As Object, e As EventArgs) Handles cmdend.Click End End Sub Private Sub cmdprocessdata_Click(sender As Object, e As EventArgs) Handles cmdprocessdata.Click Call processdata(custid, ticktid, tickts, sales) End Sub Private Sub cmdwritedata_Click(sender As Object, e As EventArgs) Handles cmdwritedata.Click Call writedata(custid, ticktid, tickts, sales) End Sub Private Sub cmdreadindata_Click(sender As Object, e As EventArgs) Handles cmdreadindata.Click Call readindata(custid, ticktid, tickts, sales) End Sub Sub readindata(ByRef CustID, ByRef ticktID, ByRef tickts, ByRef sales) filestring = "C:UsersAidan's PCDesktopTest1.csv" Using myreader As New Microsoft.VisualBasic.FileIO.TextFieldParser(filestring) myreader.TextFieldType = FileIO.FieldType.Delimited myreader.SetDelimiters(",") Dim currentrow As String() Dim i As Integer While Not myreader.EndOfData currentrow = myreader.ReadFields() CustID(i) = currentrow(0) ticktID(i) = currentrow(1) tickts(i) = Val(currentrow(2)) sales(i) = currentrow(3) i = i + 1 End While End Using For i = 0 To 299 lstdisplay.Items.Add(CustID(i) & "," & ticktID(i) & "," & tickts(i) & "," & sales(i)) Next End Sub Sub processdata(ByRef CustID, ByRef ticktID, ByRef tickts, ByRef sales) Dim i, popular, total As Integer Dim message As String For i = 0 To 299 If sales(i) = "W" Then popular = popular + 1 If popular > 149 Then message = "The most popular method of sales is via website" Else message = "The most popular method of sales is via school office" End If i = i + 1 Next For i = 0 To 299 total = 0 If Microsoft.VisualBasic.Left(ticktID(i), 1) = "F" Then total = total + tickts(i) * 10 Else total = total + tickts(i) * 5 End If i = i + 1 Next lstdisplay.Items.Add("Year: " & DateTime.Now.Year) lstdisplay.Items.Add(message) lstdisplay.Items.Add("Money Raised: £" & total) End Sub Sub writedata(ByRef CustID, ByRef ticktID, ByRef tickts, ByRef sales) filestring = "C:UsersAidan's PCDesktopTest1.txt" Dim objwriter As New System.IO.StreamWriter(filestring) Dim i As Integer Dim newline As String For i = 0 To 299 If Microsoft.VisualBasic.Left(ticktID(i), 1) = "F" Then newline = CustID(i) & "," & ticktID(i) & "," & tickts(i) & "," & sales(i) objwriter.Write(newline) i = i + 1 End If Next objwriter.Close() End Sub 

End Class

I’m not getting any errors on VB. The process data part of the program doesn’t correctly calculate the total money raised for charity. I’m not so sure why.The Friday data gets written to the .txt file but all in 1 single line instead of on a new line each time. I searched around and couldn’t find anything that could help with this for my specific code.

I don’t know what the specific problem is, so I don’t know what to try or search up ://>

Any ideas on how to help??

submitted by /u/Milney1102
[link] [comments]

Leave a Reply