passing multiple arguments in a function to a click event

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lab3terch
    New Member
    • Oct 2006
    • 22

    #1

    passing multiple arguments in a function to a click event

    I have written the following code:
    Public Class Form1

    Private Sub CmdCount_Click( ByVal sender As System.Object, ByVal e As System.EventArg s) Handles CmdCount.Click
    Dim instotal, sentotal As Integer
    Lblins.Text = incount(instota l)
    LblCount.Text = incount(sentota l)
    End Sub

    Private Function incount(ByVal instotal As Integer, ByVal sentotal As Integer) As Integer

    Dim pos, lastfound, total As Integer
    Dim sSentence As String = Txtsentence.Tex t
    Dim sWord As String = txtWord.Text
    Dim ignorecase As Boolean
    'ignorecase true is not case sensitive
    pos = InStr(1, sSentence, sWord, vbTextCompare)
    If pos > 0 And ignorecase = True Then
    total = 1
    lastfound = pos
    Do While pos <> 0
    pos = InStr(lastfound + 1, sSentence, sWord, vbTextCompare)
    If pos > 0 Then
    lastfound = pos
    instotal = (total + 1)
    End If
    Loop
    Return instotal
    End If
    If pos > 0 And ignorecase = False Then
    total = 1
    lastfound = pos
    Do While pos <> 0
    pos = InStr(lastfound + 1, sSentence, sWord, vbTextCompare)
    If pos > 0 Then
    lastfound = pos
    sentotal = (total + 1)
    End If
    Loop
    Return sentotal
    End If

    End Function
    End Class
    I get an "argument not specified" message whenI enter the information in the click event. What do I need to do to get both values printed in two separate labels?

    Thank you
  • scripto
    New Member
    • Oct 2006
    • 143

    #2
    Originally posted by lab3terch
    I have written the following code:
    Public Class Form1

    Private Sub CmdCount_Click( ByVal sender As System.Object, ByVal e As System.EventArg s) Handles CmdCount.Click
    Dim instotal, sentotal As Integer
    Lblins.Text = incount(instota l)
    LblCount.Text = incount(sentota l)
    End Sub

    Private Function incount(ByVal instotal As Integer, ByVal sentotal As Integer) As Integer

    Dim pos, lastfound, total As Integer
    Dim sSentence As String = Txtsentence.Tex t
    Dim sWord As String = txtWord.Text
    Dim ignorecase As Boolean
    'ignorecase true is not case sensitive
    pos = InStr(1, sSentence, sWord, vbTextCompare)
    If pos > 0 And ignorecase = True Then
    total = 1
    lastfound = pos
    Do While pos <> 0
    pos = InStr(lastfound + 1, sSentence, sWord, vbTextCompare)
    If pos > 0 Then
    lastfound = pos
    instotal = (total + 1)
    End If
    Loop
    Return instotal
    End If
    If pos > 0 And ignorecase = False Then
    total = 1
    lastfound = pos
    Do While pos <> 0
    pos = InStr(lastfound + 1, sSentence, sWord, vbTextCompare)
    If pos > 0 Then
    lastfound = pos
    sentotal = (total + 1)
    End If
    Loop
    Return sentotal
    End If

    End Function
    End Class
    I get an "argument not specified" message whenI enter the information in the click event. What do I need to do to get both values printed in two separate labels?

    Thank you
    function incount() takes 2 arguments
    your click event should be:

    Lblins.Text = incount(instota l, sentotal)
    LblCount.Text = incount(instota l, sentotal)

    Comment

    • lab3terch
      New Member
      • Oct 2006
      • 22

      #3
      Your reply:
      Lblins.Text = incount(instota l, sentotal)
      LblCount.Text = incount(instota l, sentotal)

      Thank you for your guidance. However, I have some additional questions. Won't the above print the same result in both labels? I want the instotal to print in the lblins.text label and the sentotal to print in the lblcount.text label. Also, I cannot get the case sensitive logic to work. Any idea as to where I am making my error? That section of the code is:
      Dim pos, lastfound, total As Integer
      Dim sSentence As String = Txtsentence.Tex t
      Dim sWord As String = txtWord.Text
      Dim ignorecase As Boolean
      'ignorecase true is not case sensitive
      pos = InStr(1, sSentence, sWord, vbTextCompare)
      If pos > 0 And ignorecase = True Then
      total = 1
      lastfound = pos
      Do While pos <> 0
      pos = InStr(lastfound + 1, sSentence, sWord, vbTextCompare)
      If pos > 0 Then
      lastfound = pos
      instotal = (total + 1)
      End If
      Loop
      Return instotal
      End If
      If pos > 0 And ignorecase = False Then
      total = 1
      lastfound = pos
      Do While pos <> 0
      pos = InStr(lastfound + 1, sSentence, sWord, vbTextCompare)
      If pos > 0 Then
      lastfound = pos
      sentotal = (total + 1)
      End If
      Loop
      Return sentotal
      End If

      End Function
      End Class

      Comment

      • scripto
        New Member
        • Oct 2006
        • 143

        #4
        Originally posted by lab3terch
        I have written the following code:
        Public Class Form1

        Private Sub CmdCount_Click( ByVal sender As System.Object, ByVal e As System.EventArg s) Handles CmdCount.Click
        Dim instotal, sentotal As Integer
        Lblins.Text = incount(instota l)
        LblCount.Text = incount(sentota l)
        End Sub

        Private Function incount(ByVal instotal As Integer, ByVal sentotal As Integer) As Integer


        Thank you
        Change your function like this:

        Private Sub incount(ByRef instotal As Integer, ByRef sentotal As Integer)

        and change this:

        incount instotal, sentotal
        Lblins.Text = instotal
        LblCount.Text = sentotal


        as far as the case thing, what is the error? the code looks ok

        Comment

        • lab3terch
          New Member
          • Oct 2006
          • 22

          #5
          Originally posted by scripto
          Change your function like this:

          Private Sub incount(ByRef instotal As Integer, ByRef sentotal As Integer)

          and change this:

          incount instotal, sentotal
          Lblins.Text = instotal
          LblCount.Text = sentotal


          as far as the case thing, what is the error? the code looks ok
          Thanks for your help! The problem was not in the code, but in how I was getting the results; what you gave me solved that problem (many thanks!!!)

          Comment

          Working...