Getting the case (upper or lower) of a string character in V

ScottNiag

Active Member
Joined
Sep 3, 2002
Messages
260
Hi. I am trying to learn VBA for Excel from a textbook at home. I have MOUS Excel expert. I am wasting huge amounts of time trying to find the answers to niggling liitle problems that seem to continually stuimp me.

I am currently doing an exercise where a user inputs a password. I store it as a string variable. The characters are all SUPPOSED to be upper case. You then have to check. There must be something which returns the CASE property of a character but I'll be darned if I can find it. Any ideas gratefully and lovingly accepted.

On a more general note, for those who have really conquered VBA - how did you learn it?
A class? Online course? Books? Just picked it up? I find that without an instructor to help out, the textbbok method is proving to be an exercise in continual frustration.
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.

zacemmel

Well-known Member
Joined
Apr 29, 2002
Messages
636
Just convert the string to upper case using ucase.

ucase("hi") would return "HI"
 

ScottNiag

Active Member
Joined
Sep 3, 2002
Messages
260
No, that isn't quite it. I need to reject the password if any part of it wasn't entered as uppercase in the first place.

Ex. STUMpED

How to tell that one or more of the letters is lower case?
 

Seti

Well-known Member
Joined
May 19, 2002
Messages
2,916
How about using the worksheet function CODE, it returns the code number for each character. If the value is between 65 (A) and 90 (Z), accept that letter, otherwise it is either lowercase or non-alpha, Or how about checking to see if UCASE(password)=password? You might need to loop through all characters though. The first solution allows you to exit before you check all characters once you find an invalid value.
 

zacemmel

Well-known Member
Joined
Apr 29, 2002
Messages
636

ADVERTISEMENT

How about doing something a lot easier?

If ucase(string)=string then...
 

ScottNiag

Active Member
Joined
Sep 3, 2002
Messages
260
zace - it worked, thx. I actually tried about the same thing, where I stored Ucase(variable) as another variable2, then said if variable = variable2 then... but for some reason it didn't work that way. Thx again.
 

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
Surely you do not need to compare each letter:

If EnteredString = Pwd then

'your code

End if
 

ScottNiag

Active Member
Joined
Sep 3, 2002
Messages
260
Vog

Actually the problem is more the setting up of a new pwd rather than comparing to an existing pwd. It's just an exercise in a textbook.
 

Forum statistics

Threads
1,143,708
Messages
5,720,388
Members
422,282
Latest member
psunith

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top