|
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
| |
Share:
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)
| | |
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
| | 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
| | |
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!!!)
| | 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
|
3 posts
views
Thread by domeceo |
last post: by
|
39 posts
views
Thread by Mike MacSween |
last post: by
|
6 posts
views
Thread by Max |
last post: by
|
7 posts
views
Thread by Bonzo |
last post: by
|
7 posts
views
Thread by John Layton |
last post: by
|
4 posts
views
Thread by simon |
last post: by
|
10 posts
views
Thread by Janus |
last post: by
| | | | | | | | | | | |