Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ASCII Conversion Problems
#1
Hey Guys... Im having a problem with this code I also wrote... It says "ITEM SHARED" and it highlights "ASC"...

Here is the code:

Code:
CLS
'Start of Declarations
DIM num AS INTEGER
DIM CHR AS STRING
DIM ASC AS INTEGER
DIM num1 AS STRING
'End of Declarations

start:

PRINT "ASCII code -- ASCII Character & ASCII Character -- ASCII Code Converter"
PRINT
PRINT "1) ASCII code -- ASCII Character"
PRINT
PRINT "2) ASCII Character -- ASCII code"
PRINT
INPUT "Enter your choice"; selection

SELECT CASE selection

   CASE 1
   CLS
   PRINT "ASCII code -- ASCII Character"
   PRINT
   INPUT "Enter ASCII code"; num
   PRINT
   CHR = CHR$(num)
   PRINT "The ASCII Character is:"; CHR

   CASE 2
   CLS
   PRINT "ASCII Character -- ASCII Code Converter"
   PRINT
   INPUT "Enter ASCII Character"; num1
   PRINT
   ASC = ASC$(num1)
   PRINT "The ASCII Code is:"; num1

CASE ELSE

PRINT "Invalid Selection"
GOTO start

END SELECT[/code]
img]http://img213.imageshack.us/img213/6104/sig1jb.gif[/img]
Reply
#2
Think your problem is that ASC is a function in qbasic.
ormal service may never be resumed
Reply
#3
Yeah, you need to pick different names for ASC and maybe CHR.
Reply
#4
CHR$ is a function that takes an integer as an argument and returns a string.

For example
s$= chr$(1) ' stupid smiley
s$= chr$(13) ' carriage return character

x=27
s$=chr$(x) 'escape

ASC is a function that takes a STRING as an argument
and returns an integer specifying the ASCII code value of the first character in the string.

x=asc("I")
s$="Montana"
x=asc(s$)


x=asc(chr$(x)) 'this would set x to the value of x

The problem with your code is in this line

ASC = ASC$(num1)

1: ASC is the name of a function and is a reserved word in QB.
2: ASC$ is not a standard function in any basic implementation.
3: You program uses input to store an INTEGER in num1
4: The line "PRINT "The ASCII Code is:";num1" outputs the value of num1, which hasn't been altered by any code after it was set by the preceding input statement.
What you want to do is input a character to a STRING, then pass that string to ASC
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)