By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,988 Members | 1,476 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,988 IT Pros & Developers. It's quick & easy.

passing multiple arguments in a function to a click event

P: 22
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
Share this Question
Share on Google+
4 Replies


scripto
100+
P: 143
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

P: 22
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+
P: 143
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

P: 22
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.