|
-
Apr 29th, 2006, 03:11 AM
#1
Thread Starter
New Member
Do not understand this function stand for???
i'm newbie in VB6. Can somebody explain what is this function for? I get this function from internet and for learning knowledge. Thank you.
VB Code:
Public Function BreakStr(ByVal Text As String, ByVal Char As String, ByVal Where As Integer) As String 'Very useful function
Dim i As Long, temp As String, m As Long
For i = 1 To Len(Text)
temp = Mid(Text, i, Len(Char))
If temp = Char Then
m = i
If Where = 1 Then 'before
temp = Mid(Text, 1, m - 1)
BreakStr = temp
Exit Function
Else
temp = Mid(Text, m + Len(Char), Len(Text))
BreakStr = temp
Exit Function
End If
End If
Next
If Where = 1 Then BreakStr = Text
End Function
Last edited by MartinLiss; Apr 29th, 2006 at 02:11 PM.
-
Apr 29th, 2006, 03:31 AM
#2
Addicted Member
Re: Do not understand this function stand for???
hav u tried to test it... you can also make your own function
im sorry i cant understand this code bcoz it seems have errors [somebody correct me if im wrong]
the condition if WHERE = 1 - i think this will produce syntax error
-
Apr 29th, 2006, 04:42 AM
#3
Re: Do not understand this function stand for???
As the name suggests the function is used to break string at a specified character position.
for example, if you write
VB Code:
Debug.Print BreakStr("this is a test", "s", 0)
Then the result will be is a test. What the function will do is that it will take all the characters after the first s and print return them. Now if you write anyother value apart from 0 then it will take all the characters that are to the left of the first occurence of the character.
This can be achieved by using the built-in vb functions like Mid, Instr & Left. There is no need to write the function.
Use [code] source code here[/code] tags when you post source code.
My Articles
-
Apr 29th, 2006, 09:17 AM
#4
Thread Starter
New Member
Re: Do not understand this function stand for???
 Originally Posted by Shuja Ali
As the name suggests the function is used to break string at a specified character position.
for example, if you write
VB Code:
Debug.Print BreakStr("this is a test", "s", 0)
Then the result will be is a test. What the function will do is that it will take all the characters after the first s and print return them. Now if you write anyother value apart from 0 then it will take all the characters that are to the left of the first occurence of the character.
This can be achieved by using the built-in vb functions like Mid, Instr & Left. There is no need to write the function.
temp = Mid(Text, i, Len(Char))
If temp = Char Then
m = i
Why we need to check the length of character?
-
Apr 29th, 2006, 10:41 AM
#5
Re: Do not understand this function stand for???
it's not checking the length, it's returning a string the same length as Char (in case Char is longer than one - it's a bit misnamed)
This function should be using Split, and can be done a lot easier with it
-
Apr 29th, 2006, 02:12 PM
#6
Re: Do not understand this function stand for???
I added vbcode tags to your post to make it easier to read.
-
Apr 30th, 2006, 12:04 AM
#7
Thread Starter
New Member
Re: Do not understand this function stand for???
 Originally Posted by bushmobile
it's not checking the length, it's returning a string the same length as Char (in case Char is longer than one - it's a bit misnamed)
This function should be using Split, and can be done a lot easier with it
Ok..thank you friend.
Do you have any example to show how this code works?
Example: string => "I am a boy"
How it runs?
Any idea. Shariing is caring.
-
Apr 30th, 2006, 05:10 AM
#8
Re: Do not understand this function stand for???
I would suggest, try to execute it yourself. It wil be easier to understand when you debug through the function.
Use [code] source code here[/code] tags when you post source code.
My Articles
-
Apr 30th, 2006, 10:58 AM
#9
Thread Starter
New Member
Re: Do not understand this function stand for???
Between, is it this same like the origin example??
if no then what is the difference? Thank you.
<vb code>
Public Function BreakStrEx(ByVal Text As String, ByVal Char As String, ByVal Where As Integer) As String
Dim i As Long, temp As String, m As Long
For i = Len(Text) To 1 Step -1
temp = Mid(Text, i, Len(Char))
If temp = Char Then
m = i
If Where = 1 Then 'before
temp = Mid(Text, 1, m - Len(Char))
BreakStrEx = temp
Exit Function
Else
temp = Mid(Text, m + Len(Char), Len(Text))
BreakStrEx = temp
Exit Function
End If
End If
Next
If Where = 0 Then BreakStrEx = Text
End Function
<vb code>
Last edited by newhondacivic; Apr 30th, 2006 at 11:01 AM.
-
Apr 30th, 2006, 12:06 PM
#10
Re: Do not understand this function stand for???
You almost got the vbcode tags right, the one at the end should be [/vbcode]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|