keep a tally in VB .net??

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dugdug
    New Member
    • Mar 2008
    • 3

    keep a tally in VB .net??

    I need a function that will count how many times a user clicks a certain control.

    For an example, there is a button that randomly displays 1 of 4 messages in a text box. I want another label to tally how many times one of the messages is displayed?

    vb .net
  • demaus
    New Member
    • Dec 2007
    • 6

    #2
    You didn't specify how your text was stored originally. Here is a quick example using a string array. This will tally how many times the first text string shows up.

    Code:
    Public Class Form1
    Dim TextShown As Integer
     
    Dim TextToShow() As String = {"First line of Text to show.", "Second line of Text to show.", "Third line of Text to show.", "Fourth line of Text to show."}
     
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnChange.Click
     
    Try
     
    Dim rd As New Random(Now.Millisecond)
     
    Dim intValue As Integer = rd.Next(0, 3)
     
    txtToChange.Text = TextToShow(intValue)
     
    If intValue = 0 Then TextShown += 1
     
    lblCount.Text = TextShown.ToString
     
    Catch ex As Exception
     
    End Try
     
    End Sub
     
    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
     
    lblCount.Text = ""
     
    TextShown = 0
     
    End Sub
     
    End Class

    Comment

    Working...