467,161 Members | 859 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,161 developers. It's quick & easy.

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.EventArgs) Handles CmdCount.Click
Dim instotal, sentotal As Integer
Lblins.Text = incount(instotal)
LblCount.Text = incount(sentotal)
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.Text
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
Oct 31 '06 #1
  • viewed: 5825
Share:
4 Replies
scripto
100+
I have written the following code:
Public Class Form1

Private Sub CmdCount_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdCount.Click
Dim instotal, sentotal As Integer
Lblins.Text = incount(instotal)
LblCount.Text = incount(sentotal)
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.Text
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(instotal, sentotal)
LblCount.Text = incount(instotal, sentotal)
Oct 31 '06 #2
Your reply:
Lblins.Text = incount(instotal, sentotal)
LblCount.Text = incount(instotal, 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.Text
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
Oct 31 '06 #3
scripto
100+
I have written the following code:
Public Class Form1

Private Sub CmdCount_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdCount.Click
Dim instotal, sentotal As Integer
Lblins.Text = incount(instotal)
LblCount.Text = incount(sentotal)
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
Nov 1 '06 #4
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!!!)
Nov 1 '06 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

7 posts views Thread by Pavils Jurjans | last post: by
7 posts views Thread by John Layton | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.