evaluating text using chr$()

T

TonyT

Hi,

I'm trying to Inport Text to populate a form by pasting into an unbound text
box and then parsing the information through code. My problem is that I can't
identify Upper & Lower Case letters using Chr$() as I thought I'd be able to,
as test in the immediate window i've tried the following;
"a" = chr$(90) - Answer True (correct)
"A" = Chr$(90) - Answer True (incorrect UCase A = Chr$(65)
to make it even more complicated I'm trying to identify if 2 following
spaces are Capitals using Mid(Me![Text24], PosCnt + 1, 1) and
Mid(Me![Text24], PosCnt + 2, 1) and using >= Chr$(65) And <=Chr$(90) etc.,
but ? Chr$(65) = Chr$(97) evaluates to True also incorrectly, What other
method should I employ?

Thx TonyT.
 
A

Allen Browne

For a case-sensitive comparision, use StrComp().

For a module, you can change the Option Compare statement.
 
T

TonyT

I've figured a way of doing it by passing variable to Instr() function and
comparing it to 2 variables containing "abcdefgh.." and "ABCDEFGHI.." etc.
more coding but effective enough, just found out that by old method I'm
losing . (fullstop) Chr$(46) when I try to remove , (comma) Chr$(44) - doh!
more Instr() variables to come!

sorry to waste anyones time.
 
T

TonyT

If I'm reading the Help correctly, to use StrComp() within a form sub I have
to check for the exact character to get a result - testing it I get the same
result using StrComp(myUC,myCh1) as StrComp(myUC,myCh2) where myUC is
"ABCDEF..." and myCh1 = "A" and myCh2 = "." (fullstop) ie 1 exists and the
other doesn't, regardless of the Comparison swith selected. presumably I'd
have to check myCh1 against A and B and C etc to get a result?
If I write a module using an Option Compare statement, can I just compare my
variables against Chr$() values as per my original post?

thx TonyT.

Allen Browne said:
For a case-sensitive comparision, use StrComp().

For a module, you can change the Option Compare statement.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

TonyT said:
I'm trying to Inport Text to populate a form by pasting into an unbound
text
box and then parsing the information through code. My problem is that I
can't
identify Upper & Lower Case letters using Chr$() as I thought I'd be able
to,
as test in the immediate window i've tried the following;
"a" = chr$(90) - Answer True (correct)
"A" = Chr$(90) - Answer True (incorrect UCase A = Chr$(65)
to make it even more complicated I'm trying to identify if 2 following
spaces are Capitals using Mid(Me![Text24], PosCnt + 1, 1) and
Mid(Me![Text24], PosCnt + 2, 1) and using >= Chr$(65) And <=Chr$(90) etc.,
but ? Chr$(65) = Chr$(97) evaluates to True also incorrectly, What other
method should I employ?

Thx TonyT.
 
D

Dirk Goldgar

TonyT said:
Hi,

I'm trying to Inport Text to populate a form by pasting into an
unbound text box and then parsing the information through code. My
problem is that I can't identify Upper & Lower Case letters using
Chr$() as I thought I'd be able to, as test in the immediate window
i've tried the following; "a" = chr$(90) - Answer True (correct)
"A" = Chr$(90) - Answer True (incorrect UCase A = Chr$(65)
to make it even more complicated I'm trying to identify if 2 following
spaces are Capitals using Mid(Me![Text24], PosCnt + 1, 1) and
Mid(Me![Text24], PosCnt + 2, 1) and using >= Chr$(65) And <=Chr$(90)
etc., but ? Chr$(65) = Chr$(97) evaluates to True also incorrectly,
What other method should I employ?

Thx TonyT.

Your comparisons involving Chr() are going about it backwards -- you're
converting an ASCII value to character and then making a text
comparison. You'd have better luck taking the character you want to
test, converting it to its ASCII (decimal) value, and comparing that.
Consider:

?"a" = Chr$(97)
True
?"A" = Chr$(97)
True
?Asc("a") = 97
True
?Asc("A") = 97
False

If you want to test whether some character is a capital letter, you
could use a function like this:

'----- start of code -----
Function IsCapitalLetter(X As String) As Boolean

Select Case Asc(X)
Case Is < 65
Case Is > 90
Case Else
IsCapitalLetter = True
End Select

End Function
'----- end of code -----

Or, as Allen Browne pointed out, you can use the StrComp() function --
but what you have to do is compare the original value with its up-cased
value, like this:

'----- start of code 2 -----
Function IsCapitalLetter2(X As String) As Boolean

If StrComp(X, UCase(X), vbBinaryCompare) = 0 Then
IsCapitalLetter2 = True
End If

End Function
'----- end of code 2 -----
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top