Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Average with VB?

  • 14-01-2004 10:54pm
    #1
    Registered Users, Registered Users 2 Posts: 4,946 ✭✭✭


    Right, i got a dart board off of my gf for christmas and i got sick of having to do maths to keep score, also the score gets a lil sloppy when drunk so i made a program to take the scores down.

    It works a treat, but i want to make the program that lil bit better by adding some lil touches to it. One of these methods is to get My average score going!

    Basicly ive tried making 2 new doubles to take the target that was hit, then add it to the previous targets, then have a interger (that starts at 0) add 1 to its value, which will inturn mean that each dart thrown will be divided into the score - simple as!
    Dim total As Integer
    Dim total2 As Integer
    Dim name1 As String
    Dim name2 As String
    End Sub

    Private Sub newgame_Click()
    total = 301
    total2 = 301
    score.Caption = total
    score2.Caption = total2
    End Sub


    Private Sub Command96_Click()
    total2 = score2 - 20
    score2.Caption = total2
    End If
    End Sub

    That there is the relivant code. The first section declaring the intergers/doubles, the second section starts a new game and sets the values of the intergers/doubles and the third section is a single 20.

    How can i make this so that when i click on 20 it will print the sum 20/average darts thrown?

    Cheers

    reD.


Comments

  • Registered Users, Registered Users 2 Posts: 4,946 ✭✭✭red_ice


    ive tried to make a simple program that adds 20's and 40's together which seems to be doing something... but not getting the average
    Private Sub Command1_Click()
    total1 = 0
    score.Caption = total1
    average.Caption = 0
    End Sub

    Private Sub Form_Load()
    Dim total1 As Integer
    Dim Average1 As Integer
    Dim Onemore1 As Integer
    End Sub

    Private Sub s20_Click()
    total1 = score + 20
    score.Caption = total1
    Onemore1 = average + 1
    average.Caption = total1 / Onemore1
    End Sub

    Private Sub s40_Click()
    total1 = score + 40
    score.Caption = total1
    Onemore1 = average + 1
    average.Caption = total1 / Onemore1
    End Sub

    Any ideas why this is printing decimals with numbers that are even?

    some help would be great

    thanks


  • Registered Users, Registered Users 2 Posts: 629 ✭✭✭str8_away


    Have not look into your math properly but
    When you "Dim" in Form_Load() do not make variable globel

    In each function/sub when you try to access your variable is create a new new one with type variant and when it treated as integer the value is 0.

    Try this code
    Private Sub Command1_Click()
    xval = 1
    End Sub

    Private Sub Command2_Click()
    Debug.Print "xval has value of " & xval
    Debug.Print "xval has integer value of " & cint(xval)
    End Sub

    Private Sub Form_Load()
    Dim xval As Integer
    End Sub

    try add this line at the very beginning of your code
    option explicit

    and also declare your globle variable at the top of your code.
    option explicit

    Dim xval As Integer

    Private Sub Command1_Click()
    xval = 1
    End Sub

    Private Sub Command2_Click()
    Debug.Print "xval has value of " & xval
    End Sub


  • Registered Users, Registered Users 2 Posts: 4,946 ✭✭✭red_ice


    Im only doing VB about 4 months in college, and at that, ive been to about 2 lectures... so i think im doin alright :p

    ok, thanks, but what will xval be? Is that going to be the varialble that i will show my answer through?


  • Registered Users, Registered Users 2 Posts: 629 ✭✭✭str8_away


    Here is what you need to change for your 2nd example to work
    'Out of Form_Load
    Dim total1 As Integer
    Dim Average1 As Integer
    Dim Onemore1 As Integer

    Private Sub Command1_Click()
    total1 = 0
    score.Caption = total1
    Onemore1 = 0
    average.Caption = 0
    End Sub

    Private Sub s20_Click()
    total1 = score + 20
    score.Caption = total1

    'Onemore1 = average + 1
    Onemore1 = Onemore1 + 1

    average.Caption = total1 / Onemore1
    End Sub

    Private Sub s40_Click()
    total1 = score + 40
    score.Caption = total1

    'Onemore1 = average + 1
    Onemore1 = Onemore1 + 1

    average.Caption = total1 / Onemore1
    End Sub


Advertisement