Qbasicnews.com

Full Version: A little advice please?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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 :???:
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]
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