Hi Everyone
I am new to this forum
I need a help in VB
i need a code for Find previous option
I am having one RichTextBox and two Command buttons [Find Previous and Find Next] in the Form
I have done the code for Find Next but not able to do for Find Previous Option
Please help me on this issue
I need to finish this work very soon
Thanks in Advance
17 2543
Hi Everyone
help me on this
Hi Everyone
help me on this
Can you post, what you done in your code and explain little bit more (What you find next and previous). So that we can get what you need.
Similar to InStr exists:
Function InStrRev(StringCheck As String, StringMatch As String, [Start As Long = -1], [Compare As VbCompareMethod = vbBinaryCompare]) As Long
It will search in reverse direction as the name suggests. Set the "Start" parameter to the textbox's current .SelStart.
Example (untested): - ret=instrrev(text1.text, "mysearchtext", text1.selstart)
-
if ret <> 0 then
-
text1.selstart=ret
-
text1.sellen=len("mysearchtext")
-
else
-
msgbox "Not found."
-
end if
Hi All,
This is my coding for Find Next option Find Next:
Dim goptions, srch, str, result, start As Variant
goptions = rtfWholeWord + rtfMatchCase
srch = Trim(RichTextBox2.Text)
RichTextBox1.SelBold = False
RichTextBox1.SelColor = vbBlack
result = RichTextBox1.Find(srch, start, , goptions)
If result >= 0 Then
RichTextBox1.SelBold = True
RichTextBox1.SelColor = vbBlue
Else
str = MsgBox("Specific Region is Searched, Do you want to continue from the top", vbYesNo, "Information'")
If str = 7 Then
Exit Sub
Else
Call clear_formatting
start = 0
Exit Sub
End If
End If
start = result + Len(srch)
Is that possible to have similar kind of coding for Find Previous
Thanks in Advance
Hi All,
This is my coding for Find Next option Find Next:
Dim goptions, srch, str, result, start As Variant
goptions = rtfWholeWord + rtfMatchCase
srch = Trim(RichTextBox2.Text)
RichTextBox1.SelBold = False
RichTextBox1.SelColor = vbBlack
result = RichTextBox1.Find(srch, start, , goptions)
If result >= 0 Then
RichTextBox1.SelBold = True
RichTextBox1.SelColor = vbBlue
Else
str = MsgBox("Specific Region is Searched, Do you want to continue from the top", vbYesNo, "Information'")
If str = 7 Then
Exit Sub
Else
Call clear_formatting
start = 0
Exit Sub
End If
End If
start = result + Len(srch)
Is that possible to have similar kind of coding for Find Previous
Thanks in Advance
i think, the code posted by danap129 will help you and its short.
Hi
Will it work with RichTextBox also
Hi
Will it work with RichTextBox also
let you to try somthing(Yes, it will).
Dim result, srch As Variant
srch = RichTextBox2.Text
RichTextBox1.SelBold = False
RichTextBox1.SelColor = vbBlack
result = InStrRev(RichTextBox1.Text, srch, RichTextBox1.SelStart)
If result <> 0 Then
RichTextBox1.SelStart = result
RichTextBox1.SelBold = True
RichTextBox1.SelColor = vbGreen
Else
MsgBox "Not found."
End If
I have used dnap coding but i couldn't get the result itself please let me know if i missed out anything
Thanks in Advance
Dim result, srch As Variant
srch = RichTextBox2.Text
RichTextBox1.SelBold = False
RichTextBox1.SelColor = vbBlack
result = InStrRev(RichTextBox1.Text, srch, RichTextBox1.SelStart)
If result <> 0 Then
RichTextBox1.SelStart = result
RichTextBox1.SelBold = True
RichTextBox1.SelColor = vbGreen
Else
MsgBox "Not found."
End If
I have used dnap coding but i couldn't get the result itself please let me know if i missed out anything
Thanks in Advance
okay, don't confuse.
i think the below method will work -
-
Private Sub SearchMe()
-
goptions = rtfWholeWord + rtfMatchCase
-
srch = Trim(RichTextBox2.Text)
-
RichTextBox1.SelBold = False
-
RichTextBox1.SelColor = vbBlack
-
result = RichTextBox1.Find(srch, start - (Len(Trim(RichTextBox2.Text)
-
) + 1), , goptions)
-
If result >= 0 Then
-
RichTextBox1.SelBold = True
-
RichTextBox1.SelColor = vbBlue
-
Else
-
str = MsgBox("Specific Region is Searched, Do you want to continue from the top", vbYesNo, "Information'")
-
If str = 7 Then
-
Exit Sub
-
Else
-
'Call clear_formatting
-
start = 0
-
Exit Sub
-
End If
-
End If
-
start = result - Len(srch)
-
-
End Sub
i think this will help you
- Option Explicit
-
-
Private Sub Command1_Click()
-
Dim result As Long, srch As Variant
-
Dim lngStart As Long
-
srch = RichTextBox2.Text
-
-
'RichTextBox1.SelBold = False
-
'RichTextBox1.SelColor = vbBlack
-
If RichTextBox1.SelStart = 0 Then lngStart = 1 Else lngStart = RichTextBox1.SelStart
-
result = InStrRev(RichTextBox1.Text, srch, lngStart, vbTextCompare)
-
-
If result <> 0 Then
-
RichTextBox1.SelStart = result - 1
-
RichTextBox1.SelLength = Len(srch)
-
'RichTextBox1.SelBold = True
-
'RichTextBox1.SelColor = vbGreen
-
Else
-
MsgBox "Not found."
-
End If
-
-
End Sub
-
-
Private Sub Form_Load()
-
RichTextBox1.HideSelection = False
-
End Sub
Hi dnap,
I have used ur previous coding and it is working really very fine
thanks for the help
with your previous code is there any way to find whole word because i am able to case-sensitive search but i cant do whole word
please help me on this Find Previous Code: - Dim result1 As Variant
-
RichTextBox1.SelBold = False
-
RichTextBox1.SelColor = vbBlack
-
If RichTextBox1.SelStart <> 0 Then
-
result1 = InStrRev(RichTextBox1.Text, RichTextBox2.Text, RichTextBox1.SelStart, vbTextCompare)
-
End If
-
If result1 <> 0 Then
-
result1 = result1 - 1
-
RichTextBox1.SelStart = result1
-
RichTextBox1.SelLength = Len(RichTextBox2.Text)
-
RichTextBox1.SelBold = True
-
RichTextBox1.SelColor = vbBlue
-
result1 = result1 + 1
-
Else
-
str = MsgBox("Specific Region is Searched, Do you want to continue from the Bottom", vbYesNo, "Information'")
-
If str = 7 Then
-
Exit Sub
-
Else
-
Call clear_formatting
-
RichTextBox1.SelStart = Len(RichTextBox1.Text)
-
result1 = 1
-
Exit Sub
-
End If
-
End If
-
start = result1 // this is for find next option
thanks in advance
Can you describe in detail what you mean by "finding whole word"? There might be different ways of interpreting this. Or to put it another way, can you describe (preferably showing examples) what situations you would consider to be a "whole word" match, and what you would not?
Hi
For Example i am having text like below shown in my textbox
hi
hii
If I want to find "hi" with wholeword option then
only "hi" has to select and not "hii"
Hi
For Example i am having text like below shown in my textbox
hi
hii
If I want to find "hi" with wholeword option then
only "hi" has to select and not "hii"
just add space front and back of the text which you are getting it from the user.
Hi hariharanmca
ur logic is not working
is there any other way to do
Hi hariharanmca
ur logic is not working
is there any other way to do
why not?
you have to search in three condition - No 1
-
srch1 = trim(RichTextBox2.Text) & " "
-
-
No 2
-
srch2 = " " & trim(RichTextBox2.Text) & " "
-
-
No 3
-
srch3 = " " & trim(RichTextBox2.Text) & "."
I suppose you just do your normal search. Each time you find a match, you check either side of it. If both sides are either start/end of the text or a delimiter (space, comma, dot, whatever) then accept it. Otherwise, keep looking.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: janice_2k |
last post by:
Dear Sir/Mdm,
I am writing this on behalf of my company. We bought the Visual Studio .NET Enterprise version but currently we need to use Visual Basic 6 for a small development. We are not able to...
|
by: Dishan Fernando |
last post by:
Plz help
How to find my previous topic??
Cheers
Dishan
|
by: Stegano |
last post by:
I am learning C Programming after working with Java for 5 years. I
want to know where can I find the source files for C language itself.
For example strcat is a function, which concatenates two...
|
by: Sontu |
last post by:
Consider the following code:
int main(void)
{
char buffer;
func(buffer);
}
void func(char *bufpas)
{
|
by: Steffen Loringer |
last post by:
Hi all,
I'm using a linked list (double). The program is growing(windows xp task
manager) if the showAllListNodes function is activated. But I can't
figure out why. Any ideas???
Thanks...
|
by: Mike Labosh |
last post by:
In VB 6, the Form_QueryUnload event had an UnloadMode parameter that let me
find out *why* a form is unloading, and then conditionally cancel the event.
In VB.NET, the Closing event passes a...
|
by: gurusshetty |
last post by:
Hi
Is there any way to find previous value of data column or text in c#.
Regards,
Guru
|
by: emily224 |
last post by:
Hello,
I have been trying to understand this source code, which I retreived from my online course test. I would like to know how to find the answer for the question on the test. Im sure the answer...
|
by: emily224 |
last post by:
Hello,
I have been trying to understand this source code, which I retreived from my online course test. I would like to know how to find the answer for the question on the test. Im sure the answer...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
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...
|
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,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
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,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |