Dim random As New Random
Dim student As New List(Of students)
Sub savedata(ByVal result As Integer)
Dim found As Boolean = False
Dim PositionInList As Integer
For counter As Integer = 0 To student.Count - 1
If student(counter).name = NameBox.Text Then
found = True
PositionInList = counter
End If
Next
If found = True Then
Dim Updatestudents As students = student(PositionInList)
Updatestudents.name = NameBox.Text
Updatestudents.result = result
student(PositionInList) = Updatestudents
Else
Dim newstudent As New students
newstudent.result = result
newstudent.name = NameBox.Text
student.Add(newstudent)
End If
Dim filename As String = "C:\Users\kieron\Documents\Visual Studio 2013\Projects\maths quiz 2\Class_1.txt" '
Dim writer As New StreamWriter(filename, False)
For counter1 As Integer = 0 To student.Count - 1
writer.WriteLine(student(counter1).name & "," & student(counter1).result)
Next
writer.Close()
End Sub
Sub GetData()
Dim filename As String = "C:\Users\kieron\Documents\Visual Studio 2013\Projects\maths quiz 2\Class_1.txt"
Dim reader As New StreamReader(filename)
While Not reader.EndOfStream
Dim nextrecord As String = reader.ReadLine
Dim recordparts() As String = nextrecord.Split(",")
Dim newstudent As New students
newstudent.name = recordparts(0)
newstudent.result = recordparts(1)
End While
reader.Close()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles start_Button.Click
If NameBox.Text = "" Then
MsgBox("Name has been left blank!!!")
Else
MsgBox(" Hello " & NameBox.Text)
GetRandom(Num1)
GetRandom(Num2)
GetRandom(Num16)
GetRandom(Num3)
GetRandom(Num4)
GetRandom(Num5)
GetRandom(Num6)
GetRandom(Num7)
GetRandom(Num8)
GetRandom(Num9)
GetRandom(Num10)
GetRandom(Num11)
GetRandom(Num12)
GetRandom(Num13)
GetRandom(Num14)
GetRandom(Num15)
GetRandom(Num17)
GetRandom(Num18)
GetRandom(Num19)
GetRandom(Num21)
GetData()
End If
End Sub
please can someone help me comment my code
Page 1 of 17 Replies - 1268 Views - Last Post: 04 February 2015 - 04:47 AM
#1
please can someone help me comment my code
Posted 03 February 2015 - 02:40 AM
Replies To: please can someone help me comment my code
#2
Re: please can someone help me comment my code
Posted 03 February 2015 - 02:42 AM
You wrote the code, you are in the best position to add some comments to it. What is stopping you from doing this?
It is also a requirement of this forum that you demonstrate some effort.
It is also a requirement of this forum that you demonstrate some effort.
This post has been edited by andrewsw: 03 February 2015 - 02:45 AM
#3
Re: please can someone help me comment my code
Posted 03 February 2015 - 02:45 AM
Think your learning a lesson the hard way here
#4
Re: please can someone help me comment my code
Posted 03 February 2015 - 02:53 AM
in future you should comment your code as you write it, it's almost integral to the process, but if you are confused where and how to comment your code see:
https://msdn.microso...y/bx185bk6.aspx
but if you want to improve overall readability of your code commenting shouldn't be the only practise you implement,
https://msdn.microso...y/h63fsef3.aspx
https://msdn.microso...y/bx185bk6.aspx
but if you want to improve overall readability of your code commenting shouldn't be the only practise you implement,
https://msdn.microso...y/h63fsef3.aspx
#5
Re: please can someone help me comment my code
Posted 03 February 2015 - 02:55 AM
frazereastm, on 03 February 2015 - 02:53 AM, said:
in future you should comment your code as you write it, it's almost integral to the process, but if you are confused where and how to comment your code see:
https://msdn.microso...y/bx185bk6.aspx
but if you want to improve overall readability of your code commenting shouldn't be the only practise you implement,
https://msdn.microso...y/h63fsef3.aspx
https://msdn.microso...y/bx185bk6.aspx
but if you want to improve overall readability of your code commenting shouldn't be the only practise you implement,
https://msdn.microso...y/h63fsef3.aspx
thanks
#6
Re: please can someone help me comment my code
Posted 04 February 2015 - 01:31 AM
I dont know if you need it but i was bored so here you go.
'set random variable to function called Random
Dim random As New Random
'set variable student to a list of students
Dim student As New List(Of students)
'make a sub
Sub savedata(ByVal result As Integer)
'set found to a false boolean
Dim found As Boolean = False
'set variable PositionInList to be an integer
Dim PositionInList As Integer
'set integer variable counter to 0 and do until student.count = -1
For counter As Integer = 0 To student.Count - 1
'if student(number) name equals the text in namebox.text then do
If student(counter).name = NameBox.Text Then
'set found to true
found = True
'set PositionInList to the counter number
PositionInList = counter
End If
Next
'if found is true run code
If found = True Then
'set Updatestudents As a students array to the student(number of position in list)
Dim Updatestudents As students = student(PositionInList)
'set the name of that student to the text in namebox
Updatestudents.name = NameBox.Text
'set the students result to the text in result
Updatestudents.result = result
'update the info from the student that is in PositionInList number and set info to Updatestudents info
student(PositionInList) = Updatestudents
Else
'Set a newstudent to a students array
Dim newstudent As New students
'set the results of this new student to result
newstudent.result = result
set the name of the new student to namebox
newstudent.name = NameBox.Text
'add the student with the information to a list
student.Add(newstudent)
End If
'set the filename as a string to a path on the computer
Dim filename As String = "C:\Users\kieron\Documents\Visual Studio 2013\Projects\maths quiz 2\Class_1.txt" '
'set writer to be a streamwriter that can write to directory of filename
Dim writer As New StreamWriter(filename, False)
'run until counter1 equals to number of students in list -1 becaus you have an array that starts with 0
For counter1 As Integer = 0 To student.Count - 1
'write the information of the student that is selected
'write name and result to the text file with a comma inbetween
writer.WriteLine(student(counter1).name & "," & student(counter1).result)
Next
'close the writer
writer.Close()
End Sub
Sub GetData()
'set filename to a path
Dim filename As String = "C:\Users\kieron\Documents\Visual Studio 2013\Projects\maths quiz 2\Class_1.txt"
'set a reader to a streamreader that can read the file
Dim reader As New StreamReader(filename)
'do while reader is not at the end of the stream
While Not reader.EndOfStream
'set nextrecord to contains a readed line from the reader
Dim nextrecord As String = reader.ReadLine
'set recordsparts to a string that has the next record splitted by a comma
'im not sure if this line underneath here works because split(",")
'mostly generates an array of items that are splitted
'and here it says as string but it is used on line 79 and 80 as an array
Dim recordparts() As String = nextrecord.Split(",")
'set newstudent to containt students information wich is not be set
Dim newstudent As New students
'set the student name to the first item in the array
newstudent.name = recordparts(0) 'error may occure here see line 71 to 74
'set the result of this new student to the second item in the array
newstudent.result = recordparts(1)'error may occure here see line 71 to 74
End While
'clos the reader
reader.Close()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles start_Button.Click
'if the namebox is empty then
If NameBox.Text = "" Then
'a message box is shown with the text: name has been left black!!!
MsgBox("Name has been left blank!!!")
'if the namebox is not empty do
Else
'show a message box that says: Hello NameOfStudent
MsgBox(" Hello " & NameBox.Text)
'call a GetRandom function wich returns data
GetRandom(Num1)
GetRandom(Num2)
GetRandom(Num16)
GetRandom(Num3)
GetRandom(Num4)
GetRandom(Num5)
GetRandom(Num6)
GetRandom(Num7)
GetRandom(Num8)
GetRandom(Num9)
GetRandom(Num10)
GetRandom(Num11)
GetRandom(Num12)
GetRandom(Num13)
GetRandom(Num14)
GetRandom(Num15)
GetRandom(Num17)
GetRandom(Num18)
GetRandom(Num19)
GetRandom(Num21)
'run the sub getData wich adds a new student
GetData()
End If
End Sub
#7
Re: please can someone help me comment my code
Posted 04 February 2015 - 02:27 AM
It is against the policy of dream-in-code to provide complete coded solutions or, in this case, a complete commented solution. However, this is a very poor example of commenting code. The comments add very little that cannot be interpreted directly from the code, so just add unnecessary clutter. For example,
Most of the comments are like this.
'a message box is shown with the text: name has been left black!!!
MsgBox("Name has been left blank!!!")
Most of the comments are like this.
#8
Re: please can someone help me comment my code
Posted 04 February 2015 - 04:47 AM
sorry didnt know it is against the policy i only knew they may not ask us for the code. but i was bored xD so had to do something...
This post has been edited by andrewsw: 04 February 2015 - 04:49 AM
Reason for edit:: Removed previous quote, just press REPLY
Page 1 of 1

New Topic/Question
Reply


MultiQuote


|