Separating Words in a string (VB5)... 
Author Message
 Separating Words in a string (VB5)...

I am using the following code to separate and count the number
of words in the string.

However, I get a "Argument no optional" Err Msg on this line
(<<<<<<)
when I call this function.  Any ideas where I am screwing up????

All help graciously accepted!!
Cliff

Option Explicit
Public Function SepWords(ByVal Text As String, RetArr()_
As String, Optional ByVal Delim As String = " ") As Integer

On Error Resume Next

Dim Offset As Integer
Dim NumFound As Integer
Dim Lg As Integer

If Trim$(Text) = "" Then Exit Function

Lg = Len(Delim)
NumFound = 0

Do
 Offset = InStr(Text, Delim)
 If Offset = 0 Then Exit Do
 NumFound = NumFound + 1
 ReDim Preserve RetArr(NumFound - 1) As String
 RetArr(NumFound - 1) = Left$(Text, Offset - 1)
 Text = Mid$(Text, Offset + Lg)
Loop
NumFound = NumFound + 1
ReDim Preserve RetArr(NumFound - 1) As String
RetArr(NumFound - 1) = Text

SepWords = NumFound

End Function

Private Sub Command1_Click()
Dim Text As String
Text = Text1.Text
Call SepWords
Text2.Text = NumFound
End Sub

Private Sub cmdSepWords_Click()
Call SepWords                   '(<<<<<<<<<<<<)
Text2.Text = SepWords
End Sub
--
****************************************
ICQ - 16957341
****************************************
If I had to live my life again, I'd make
the same mistakes again--ONLY SOONER!!!!
****************************************
Last night I dreamt I ate a 10 pound
marshmallow, when I woke up my pillow
was gone.
****************************************



Wed, 31 Jan 2001 03:00:00 GMT  
 Separating Words in a string (VB5)...


Quote:
>I am using the following code to separate and count the number
>of words in the string.

>However, I get a "Argument no optional" Err Msg on this line
>(<<<<<<)
>when I call this function.  Any ideas where I am screwing up????

>All help graciously accepted!!
>Cliff

>Option Explicit
>Public Function SepWords(ByVal Text As String, RetArr()_
>As String, Optional ByVal Delim As String = " ") As Integer

>On Error Resume Next

>Dim Offset As Integer
>Dim NumFound As Integer
>Dim Lg As Integer

>If Trim$(Text) = "" Then Exit Function

>Lg = Len(Delim)
>NumFound = 0

>Do
> Offset = InStr(Text, Delim)
> If Offset = 0 Then Exit Do
> NumFound = NumFound + 1
> ReDim Preserve RetArr(NumFound - 1) As String
> RetArr(NumFound - 1) = Left$(Text, Offset - 1)
> Text = Mid$(Text, Offset + Lg)
>Loop
>NumFound = NumFound + 1
>ReDim Preserve RetArr(NumFound - 1) As String
>RetArr(NumFound - 1) = Text

>SepWords = NumFound

>End Function

>Private Sub Command1_Click()
>Dim Text As String
>Text = Text1.Text
>Call SepWords
>Text2.Text = NumFound
>End Sub

>Private Sub cmdSepWords_Click()
>Call SepWords                       '(<<<<<<<<<<<<)
>Text2.Text = SepWords
>End Sub
>--
>****************************************
>ICQ - 16957341
>****************************************
>If I had to live my life again, I'd make
>the same mistakes again--ONLY SOONER!!!!
>****************************************
>Last night I dreamt I ate a 10 pound
>marshmallow, when I woke up my pillow
>was gone.
>****************************************

 Cliff,

Yeah ... you're function is looking for parameters that you seem to not be passing.  Include the necessary parameters, or
remove the parameters from the argument list of the function.

-Richard



Wed, 31 Jan 2001 03:00:00 GMT  
 Separating Words in a string (VB5)...
Richard,

How do I CORRECTLY insert the parameters?
Would you give me an example please...

Thanks
Cliff

Quote:



> >I am using the following code to separate and count the number
> >of words in the string.

> >However, I get a "Argument no optional" Err Msg on this line
> >(<<<<<<)
> >when I call this function.  Any ideas where I am screwing up????

> >All help graciously accepted!!
> >Cliff

> >Option Explicit
> >Public Function SepWords(ByVal Text As String, RetArr()_
> >As String, Optional ByVal Delim As String = " ") As Integer

> >On Error Resume Next

> >Dim Offset As Integer
> >Dim NumFound As Integer
> >Dim Lg As Integer

> >If Trim$(Text) = "" Then Exit Function

> >Lg = Len(Delim)
> >NumFound = 0

> >Do
> > Offset = InStr(Text, Delim)
> > If Offset = 0 Then Exit Do
> > NumFound = NumFound + 1
> > ReDim Preserve RetArr(NumFound - 1) As String
> > RetArr(NumFound - 1) = Left$(Text, Offset - 1)
> > Text = Mid$(Text, Offset + Lg)
> >Loop
> >NumFound = NumFound + 1
> >ReDim Preserve RetArr(NumFound - 1) As String
> >RetArr(NumFound - 1) = Text

> >SepWords = NumFound

> >End Function

> >Private Sub Command1_Click()
> >Dim Text As String
> >Text = Text1.Text
> >Call SepWords
> >Text2.Text = NumFound
> >End Sub

> >Private Sub cmdSepWords_Click()
> >Call SepWords                  '(<<<<<<<<<<<<)
> >Text2.Text = SepWords
> >End Sub
> >--
> >****************************************
> >ICQ - 16957341
> >****************************************
> >If I had to live my life again, I'd make
> >the same mistakes again--ONLY SOONER!!!!
> >****************************************
> >Last night I dreamt I ate a 10 pound
> >marshmallow, when I woke up my pillow
> >was gone.
> >****************************************

>  Cliff,

> Yeah ... you're function is looking for parameters that you seem to not be passing.  Include the necessary parameters, or
> remove the parameters from the argument list of the function.

> -Richard

--
****************************************
ICQ - 16957341
****************************************
If I had to live my life again, I'd make
the same mistakes again--ONLY SOONER!!!!
****************************************
Last night I dreamt I ate a 10 pound
marshmallow, when I woke up my pillow
was gone.
****************************************


Wed, 31 Jan 2001 03:00:00 GMT  
 Separating Words in a string (VB5)...

Cliff,

Okay ... all I can go on is what you have provided, but ...

Your SepWords function looks for three parameters - Text, RetArr(), and an optional Delim - but when you call the function
in your code, you don't provide these parameters; you simply "Call SepWords"; VB requires that you provide the necessary
arguments or it will give you the "Argument not optional" errory that you are receiving.  You will need to determine from
your code what needs to be passed to the function.

And as to an example, I couldn't tell you; I am not versed in passing arrays as function arguments.  Keep reading however, I
think you can simplify your process.

However, it looks like you are trying to write a function that already exists.  Take a look at the INSTR statement in the
help topics.  You can search for the spaces with this statement and count the number of words.

Take your string: "This is the string being checked.",
Create a Do Until Loop where your exit clause checks the position within the string; the INSTR statement will return zero if
no space is found,
Increment a Word Counter for each space, and set the initial value to one; REASON - in the above example, there is no space
after "checked." but you need to include that word.

Hope this helps.
-Richard

Quote:


>Richard,

>How do I CORRECTLY insert the parameters?
>Would you give me an example please...

>Thanks
>Cliff




>> >I am using the following code to separate and count the number
>> >of words in the string.

>> >However, I get a "Argument no optional" Err Msg on this line
>> >(<<<<<<)
>> >when I call this function.  Any ideas where I am screwing up????

>> >All help graciously accepted!!
>> >Cliff

>> >Option Explicit
>> >Public Function SepWords(ByVal Text As String, RetArr()_
>> >As String, Optional ByVal Delim As String = " ") As Integer

>> >On Error Resume Next

>> >Dim Offset As Integer
>> >Dim NumFound As Integer
>> >Dim Lg As Integer

>> >If Trim$(Text) = "" Then Exit Function

>> >Lg = Len(Delim)
>> >NumFound = 0

>> >Do
>> > Offset = InStr(Text, Delim)
>> > If Offset = 0 Then Exit Do
>> > NumFound = NumFound + 1
>> > ReDim Preserve RetArr(NumFound - 1) As String
>> > RetArr(NumFound - 1) = Left$(Text, Offset - 1)
>> > Text = Mid$(Text, Offset + Lg)
>> >Loop
>> >NumFound = NumFound + 1
>> >ReDim Preserve RetArr(NumFound - 1) As String
>> >RetArr(NumFound - 1) = Text

>> >SepWords = NumFound

>> >End Function

>> >Private Sub Command1_Click()
>> >Dim Text As String
>> >Text = Text1.Text
>> >Call SepWords
>> >Text2.Text = NumFound
>> >End Sub

>> >Private Sub cmdSepWords_Click()
>> >Call SepWords                  '(<<<<<<<<<<<<)
>> >Text2.Text = SepWords
>> >End Sub
>> >--

>>  Cliff,

>> Yeah ... you're function is looking for parameters that you seem to not be passing.  Include the necessary parameters, or
>> remove the parameters from the argument list of the function.

>> -Richard



Thu, 01 Feb 2001 03:00:00 GMT  
 Separating Words in a string (VB5)...
Your function is declared with 2 NON-optional parameters.  The line in
question is calling the function with neither of these 2 required parameters,
hence the error message.  Your code indicates that you do not understand how
functions work.  Write back if you want some help.

Lee Weiner
weiner AT fuse DOT net



Quote:
>I am using the following code to separate and count the number
>of words in the string.

>However, I get a "Argument no optional" Err Msg on this line
>(<<<<<<)
>when I call this function.  Any ideas where I am screwing up????

>All help graciously accepted!!
>Cliff

>Option Explicit
>Public Function SepWords(ByVal Text As String, RetArr()_
>As String, Optional ByVal Delim As String = " ") As Integer

>On Error Resume Next

>Dim Offset As Integer
>Dim NumFound As Integer
>Dim Lg As Integer

>If Trim$(Text) = "" Then Exit Function

>Lg = Len(Delim)
>NumFound = 0

>Do
> Offset = InStr(Text, Delim)
> If Offset = 0 Then Exit Do
> NumFound = NumFound + 1
> ReDim Preserve RetArr(NumFound - 1) As String
> RetArr(NumFound - 1) = Left$(Text, Offset - 1)
> Text = Mid$(Text, Offset + Lg)
>Loop
>NumFound = NumFound + 1
>ReDim Preserve RetArr(NumFound - 1) As String
>RetArr(NumFound - 1) = Text

>SepWords = NumFound

>End Function

>Private Sub Command1_Click()
>Dim Text As String
>Text = Text1.Text
>Call SepWords
>Text2.Text = NumFound
>End Sub

>Private Sub cmdSepWords_Click()
>Call SepWords                   '(<<<<<<<<<<<<)
>Text2.Text = SepWords
>End Sub



Fri, 09 Feb 2001 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Separate strings into different fields

2. Separate Address from string

3. separate strings to variables in array

4. Separating Strings

5. Parsing a string with data separated by variable numbers of blanks (NEWBIE ALERT)

6. Winsock not recognizing separate strings

7. Separate 2 strings

8. separate string

9. Separating Strings

10. separating pages into separate documents

11. Getting Tab separated data from Word to Access, Excel or simply process it from VB

12. Getting Tab separated data from Word to Access, Excel or process it from VB

 

 
Powered by phpBB® Forum Software