|
-
Jul 19th, 2006, 10:13 AM
#1
Thread Starter
Member
[RESOLVED] Asc(65)
I have a string that i am cutting up.
the string is looped through looking at each character (MyStr)
VB Code:
If MyStr = Asc(65) Or Asc(66) Or Asc(67) Or Asc(68) Or Asc(69) Or
Asc(70) Or Asc(71) Or Asc(72) Or Asc(73) Or Asc(74) Or Asc(75) Or Asc(76)
Or Asc(77) Or Asc(78) Or Asc(79) Or Asc(80) Or Asc(81) Or Asc(82) Or
Asc(83) Or Asc(84) Or Asc(85) Or Asc(86) Or Asc(87) Or Asc(88) Or Asc(89)
Or Asc(90) Or Asc(97) Or Asc(98) Or Asc(99) Or Asc(100) Or Asc(101) Or
Asc(102) Or Asc(103) Or Asc(104) Or Asc(105) Or Asc(106) Or Asc(107) Or
Asc(108) Or Asc(109) Or Asc(110) Or Asc(111) Or Asc(112) Or Asc(113) Or
Asc(114) Or Asc(115) Or Asc(116) Or Asc(117) Or Asc(118) Or Asc(119) Or
Asc(120) Or Asc(121) Or Asc(122) Then
the above code lists the ascii numbers for A-Z & a-z only! So it should only execute if the character in MyStr is A-Z or a-z but when the character in MyStr is space, or tab it is still processed!!
can anyone tell me why?
-
Jul 19th, 2006, 10:18 AM
#2
Re: Asc(65)
You cannot do that (as you are not comparing values, just doing boolean checks with non-zero values [which are therefore all True - so the If is always True]), it would need to be like this instead:
VB Code:
If (MyStr = Asc(65)) Or (MyStr = Asc(66)) Or (MyStr =Asc(67)) Or ....
or alternatively, you could use more efficient code like this:
VB Code:
IF ((Asc(MyStr) >= 65) And (Asc(MyStr) <= 90)) Or ((Asc(MyStr) >= 97) And (Asc(MyStr) <= 122)) Then
or even better:
VB Code:
Select Case MyStr
Case "A" to "Z", "a" to "z"
'code here
End Select
-
Jul 19th, 2006, 10:21 AM
#3
Re: Asc(65)
?? Asc(65) = 54, Chr(65) = "A"
I dont understand what u are doing?
only allow capitals / lowercase letters?
or u could do this.. but I like the select case better as shown above
VB Code:
If InStr(UCase(MyStr), "ABCDEFGHIJKLMNOPQRSTUVWXYZ") <> 0 Then
End If
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Jul 19th, 2006, 10:24 AM
#4
Re: Asc(65)
but I still dont undertand why Asc() is being used.. thats not the correct way to use it???
Asc()
Returns anInteger representing the character code corresponding to the first letter in a string.
Asc("A") would be correct...
Chr(65) would be to test for "A"
right??
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Jul 19th, 2006, 10:25 AM
#5
Thread Starter
Member
Re: Asc(65)
Doh! Thanks people
to hot to think straight is my excuse today
-
Jul 19th, 2006, 10:35 AM
#6
Re: Asc(65)
if you're looping through every character of a string you'd be better off using a byte array.
-
Jul 19th, 2006, 10:43 AM
#7
Re: Asc(65)
 Originally Posted by Static
but I still dont undertand why Asc() is being used.. thats not the correct way to use it???
Doh!! Why didn't I spot that!
-
Jul 19th, 2006, 10:46 AM
#8
Re: Asc(65)
"to hot to think straight", si.
The most difficult part of developing a program is understanding the problem.
The second most difficult part is deciding how you're going to solve the problem.
Actually writing the program (translating your solution into some computer language) is the easiest part.
Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.
Please Help Us To Save Ana
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
|