• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Compare string in two different textbox

lckuan

New Member
Hi all


I need to compare string text using two different textbox. The user have to copy the source (text) first. After this the user have to type the text in the First textbox (this textbox disable pasting to prevent the copy text to be paste), after finished typing click the compare button at the user form. this will return the result by a messagebox whether it matched or not. this can be done using the Instr function but what I need was after the messagebox, it need to highlighted the result which text was not matched (the second textbox rather than the background colour change). thanks for the help and guidance in advance.

the code as follow:-

[pre]
Code:
If InStr(1, txtverify.Text, txtmaker.Text, vbTextCompare) Then
MsgBox "Good and Perfect, all matched", vbInformation, "Well Done"
Else
MsgBox "Woops, NOT MATCH, REJECT and CHECK AGAIN", vbCritical, "ERROR"
txtverify.BackColor = vbRed
txtmaker.BackColor = vbRed
Beep
End If
[/pre]
 
Hi Ickuan


Free text which has to be identical without copy and paste, that is asking a lot of your users. Here is an idea, have the second text box linked to the first as the user types into the first text box that text appears in the second text box. That way the text is always identical and you will never have a problem of text not matching. Put two active X Control text boxes into a workbook originally titled textbox1 and textbox2 (I thought that up myself). Now in design mode double click on the first text box. Put the following code into the worksheet object.


'Private Sub TextBox1_Change()

TextBox2.Text = TextBox1.Text

End Sub'


when you get out of design mode you will notice that as you type in textbox1, textbox2 updates with the same and identical information. Problem goes away.


Take care


Smallman
 
Hi, Ickuan!


First of all welcome to Chandoo's website Excel forums. Thank you for your joining us and glad to have you here.


As a starting point I'd recommend you to read the green sticky topics at this forums main page. There you'll find general guidelines about how this site and community operates (introducing yourself, posting files, netiquette rules, and so on).


Among them you're prompted to perform searches within this site before posting, because maybe your question had been answered yet.


Feel free to play with different keywords so as to be led thru a wide variety of articles and posts, and if you don't find anything that solves your problem or guides you towards a solution, you'll always be welcome back here. Tell us what you've done, consider uploading a sample file as recommended, and somebody surely will read your post and help you.


And about questions in general...


If you haven't performed yet the search herein, try going to the topmost right zone of this page (Custom Search), type the keywords used in Tags field when creating the topic or other proper words and press Search button. You'd retrieve many links from this website, like the following one(s) -if any posted below-, maybe you find useful information and even the solution. If not please advise so as people who read it could get back to you as soon as possible.


And about this question in particular...


You might use too the clause:

Option Compare {Binary | Text | Database}

as first line (in fact before any procedure) of a module.

If you omit it Binary is assumed and this order is used for character comparison:

A < B < E < Z < a < b < e < z < À < Ê < Ø < à < ê < ø

If you specify Text it uses this order:

(A=a) < ( À=à) < (B=b) < (E=e) < (Ê=ê) < (Z=z) < (Ø=ø)

Database parameter is only allowed in MS Access and uses the order specified by the DB local identifier.


Regards!


Regards!
 
Thank you for the reply, but I still could not get the result I wanted.


Basically it start like this, there were two textboxes, the First textbox (visible to user at the user form)- was the first input textbox while the second textbox was only visible after the user click the compare button, which only serve as a display purpose and result.


There were two users here, the first user had already input the text at a different excel sheet. while the second user need to ensure that the data entry by the first user actually correct. so I had design such a user form which consist of two textboxes. The first textbox was the second user input while the second textbox was the first user entry (which was copy before the second user input at the First textbox).


the end result wanted is to ensure the correctness of the input, if not prompt / highlighted the differences in red colour and not the whole textbox in red.
 
Hi, Ickuan!

Consider uploading a sample file (including manual examples of desired output if applicable), it'd be very useful for those who read this and might be able to help you. Thank you. Give a look at the green sticky posts at this forums main page for uploading guidelines.

Regards!
 
Back
Top