473,386 Members | 1,823 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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
4 6211
scripto
143 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
143 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

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

Similar topics

7
by: Pavils Jurjans | last post by:
Hallo, I have been programming for restricted environments where Internet Explorer is a standard, so I haven't stumbled upon this problem until now, when I need to write a DOM-compatible code. ...
3
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. function imgOff(menu, num) { if (document.images) {...
39
by: Mike MacSween | last post by:
Just spent a happy 10 mins trying to understand a function I wrote sometime ago. Then remembered that arguments are passed by reference, by default. Does the fact that this slowed me down...
6
by: Max | last post by:
Last time I tried to explain this on another forum it didn't go too well, so I'll try my best and if you know what I'm talking about then please tell me how to do this. I have a class, inside I...
7
by: Bonzo | last post by:
>From within a function, I want to pass a/some parameters to another function, AND all arguments, passed into this function. e.g. function firstFunction(){ //this function may have been...
7
by: John Layton | last post by:
Hi there, Is it possible to pass null to a function taking an "out" (or "ref") parameter in C#. I'd like to do something like the following (which doesn't compile of course). Thanks in advance....
4
by: simon | last post by:
hi, I would like to separate my javascript completely from my xhtml. in the end there should be only <script type="text/javascript" src="javalib.js"></script> in the head-tag to my javascript....
10
by: Janus | last post by:
Hi, Is there a way to pass arguments to the callback function used inside an addEventListener? I see that I can only list the name of the callback function. For eg, I use this: var...
1
by: johnjsforum | last post by:
Buddies, I have a web page to create HTML buttons dynamically as in the “formDivColorPicker” function ////////////////////////////////////////////////////////////////////////////////////...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.