Wednesday 20 March 2013

Net Run Rate Calculator | Source Code

So here is our first application, a simple VB 6 application to calculate the Net Run Rate for Cricket Matches. We hope that this would be useful for anyone who manages small scale Cricket Tournaments or such. :)

'Declaring the required variables

Dim t1, t2, ov, rr1, rr2, nrr1, nrr2
______________________________________________________________________________
'Program to Calculate the Net Run Rate and Display on Click of Button

Private Sub Command1_Click()

t1 = Val(Text1.Text)
t2 = Val(Text2.Text)
ov = Val(Text3.Text)

'--- To Avoid Error when button clicked without Entering values to calculate ---
'<---Starts here---

Select Case ov
Case ov = ""
ov = 1
End Select

Select Case t1
Case t1 = ""
t1 = 0
End Select

Select Case t2
Case t2 = ""
t2 = 0
End Select
'--- Ends here--->
'--- Run Rate Calculation ---
rr1 = t1 / ov
rr2 = t2 / ov

nrr1 = rr1 - rr2
nrr2 = rr2 - rr1

Text4.Text = nrr1
Text5.Text = nrr2

End Sub

______________________________________________________________________________


This is the only Coding part. It is very simple, once you get the hang of it.

Here,

Command1 is the Button on which the Calculation Takes place

Text1 is the Text Field used to get the Team 1's score, Text2 is the Text Field for Team 2's score, Text3 is where you input the number of overs.

Text4 and Text5 are used to display the Net Run Rate Calcuated.

This is what the end program looks like


No comments:

Post a Comment