public class form1
const smax as integer = 100
structure studenttype
dim strid as string
dim strname as string
dim sngscore as single
end structure
dim udtstudent(smax) as studenttype
dim intcount as integer = 0
private sub btnnew_click(byval sender as system.object, byval e as system.eventargs) handles btnnew.click
dgvscore.rows.add(txtid.text, txtname.text, txtscore.text)
txtid.focus()
udtstudent(intcount).strid = txtid.text
udtstudent(intcount).strname = txtname.text
udtstudent(intcount).sngscore = csng(txtscore.text)
intcount = intcount + 1
txtid.text = ""
txtname.text = ""
txtscore.text = ""
end sub
private sub btnsum_click(byval sender as system.object, byval e as system.eventargs) handles btnsum.click
dim intpos as integer
dim intsum as integer
dim dgvavg as double
intsum = 0
for intpos = 0 to intcount - 1
intsum = intsum + udtstudent(intpos).sngscore
next
if intcount > 0 then dgvavg = intsum / intcount
msgbox("平均分数:" + dgvavg.tostring)
private sub btnexit_click(byval sender as system.object, byval e as system.eventargs) handles btnexit.click
end
private sub btndelete_click(byval sender as system.object, byval e as system.eventargs) handles btndelete.click
if me.dgvscore.selectedrows.count > 0 andalso _
not me.dgvscore.selectedrows(0).index = _
me.dgvscore.rows.count - 1 then _
me.dgvscore.rows.removeat(me.dgvscore.selectedrows(0).index)
end class