Capitalising first letter and ensuring a variable

Results 1 to 2 of 2

Thread: Capitalising first letter and ensuring a variable

  1. #1
    Culture Guest

    Default Capitalising first letter and ensuring a variable

    Hi all,<BR>I suppose the title says it all. I am after an effecient way to capitalise the first letter of a string (someone&#039s name) and also to ensure that the variable they have entered (in another part of the form) is a number.<BR>Thanks in advance,<BR>C

  2. #2
    Join Date
    Dec 1969

    Default RE: Capitalising first letter and ensuring a varia

    &nbsp;<BR>Capitalize first letter:<BR><BR>&#060;%<BR>str = "wilkinson" &#039 or whatever<BR>str = UCase(Left(str,1)) & LCase(Mid(str,2))<BR>%&#062;<BR><BR>Ensure a VALUE (not a variable...users can *never* enter variables...they enter values that your code *captures* in varaibles) is a number:<BR><BR>Several ways. My favorite:<BR><BR>&#060;%<BR>userInput = Request.Form("whatever") &#039 or however you get the value<BR><BR>val = "NOT A NUMBER"<BR>On Error Resume Next<BR>val = CDbl( userInput )<BR>On Error GoTo 0<BR>%&#062;<BR><BR>How it works: If the user input is not a number, then CDBL will cause an error. Because of the error, the assignment to "val" does not take place, so val will still contain whatever you put into it before the trial assignment. The On Error Resume Next prevents the error from CDBL from stopping your program/page.<BR><BR>NOTE: This allows *any* kind of number, including even those with scientific notation (e.g., 1.23e-10).<BR><BR>If you want to limit the number to whole numbers (integers) use CLNG in place of CDBL.<BR><BR><BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts