Qbasicnews.com
July 25, 2021, 01:20:28 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: A little advice please?  (Read 1738 times)
NashKat
New Member

Posts: 13


« on: March 16, 2003, 10:13:57 PM »

Why doesn't this work?

IF amount$ = CHAR$(64-122) THEN
         END
END IF

I am trying to get the program to end if you type a letter from the keybord. I already go it to end if you put nothing into it but now trying for letters.

What am I doing wrong :Huh:
Logged
pr0gger
I hold this place together
*****
Posts: 775


« Reply #1 on: March 16, 2003, 10:36:27 PM »

IF amount$ = CHAR$(64-122) THEN
END
END IF

Alright, here's one of your problems: CHAR$ is not a function (at least not in QB).  There is a CHR$ though.

Also, I assume you are trying to define a range of characters by putting CHAR$(64-122).  What this actually does is subtracts 122 from 64, which should give an error.

There are two ways of fixing this:

Code:

IF amount$ >= CHR$(64) AND amount$ <= CHR$(122) THEN
END
END IF


This tells says to end if amount$ has a alphabetical value between CHR$(64) and CHR$(122).

The second way:

Code:

SELECT CASE amount$
 CASE CHR$(64) TO CHR$(122)
  END
END SELECT


This, uses select case and a range to check the value.  Both should work.
[/code]
Logged

size=9]"To announce that there must be no criticism of the president, or that we are to stand by the president, right or wrong, is not only unpatriotic and servile, but is morally treasonable to the American public." -- Theodore Roosevelt[/size]
NashKat
New Member

Posts: 13


« Reply #2 on: March 17, 2003, 04:06:14 PM »

Thank you

didn't realize I was subtracting the ASC value I was just trying to be in that range to eliminate the letters

Thanks again
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!