Comparing text

  • Thread starter Thread starter Dan
  • Start date Start date
D

Dan

I have a text box and I need to compare only the top 2
lines and determine if they are equal to each other.

I also want to determine if the top line is equal to any
other line.
 
First, define "top 2 lines".

This may work, if "top 2 lines" means what I think it means:

Dim str, strmod, str1, str2 as string

str = Forms!FormName!textbox1
str1 = Mid(str,1,Instr(str,vbCrLf)-1) 'this is line 1
strmod = Mid(str,Len(str1)+2) 'the rest of the text
str2 = Mid(strmod,1,Instr(strmod,vbCrLf)-1) 'this is line 2

if str1 = str2 then
....
end if

Naturally, you can do this with fewer variables and you
need to check for Null values. If you are not using
AccessVB, this is more complicated, but it can still be
done. The keys are learning the Mid, Len and Instr
functions and knowing the vbCrLf constant.
 
Something isn't working quite right. I think that there
must be an extra blank line in front of the second line
and maybe one after it
 
You have to be more specific about what "top 2 lines"
means. Are they always text lines followed by a carriage
return + line break combination, hence vbCrLf? Use the
Chr(##) function to figure out what is actually there and
replace the vbCrLf constant. Look up the ASCII character
map for more help.
 
I have a text box where I insert the date followed by
vbCrLf. So each date appears on a new line. I have used
your code to checks to see if the "top 2" (that appear in
the text box) dates are not equal as long as there is
already more than one date entered. It gives an error if
there is two dates entered in this command:

line2 = Mid(strmod, 1, InStr(strmod, vbCrLf) - 1) 'this
is line 2

I believe it gives the error because there is not a
second vbCrLf
 
Back
Top