Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Automatic covertion to ASCII problem

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-8051
View previous topic :: View next topic  
Author Message
schtygnedec

Bascom Member



Joined: 23 Jan 2014
Posts: 4

PostPosted: Thu Jan 23, 2014 6:50 pm    Post subject: Automatic covertion to ASCII problem Reply with quote

Hi, i'm new here Smile

I need to make a program but i have problems with ASCII converting... I need to input the key from number 1 to 100, but if i input letter key, it automatictly converts it to ASCII and that's not what it should be... Please help me, what's the easiest way to disable converting (which action)?

Sorry for my bad english, and thanks in advance Very Happy
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5091
Location: Holland

blank.gif
PostPosted: Wed Jan 29, 2014 4:09 pm    Post subject: Reply with quote

i have no idea what you mean Very Happy
where do you get the letter from ?
Do you read this from the serial port or keyboard or what?
Anyway say you have a string with value "100" ., you can use VAL() to convert it to a numeric value.

Say you have "1" you can use ASC() to get the ascii value and the subtract 48 from it.
Just some ideas.

_________________
Mark
Back to top
View user's profile Visit poster's website
schtygnedec

Bascom Member



Joined: 23 Jan 2014
Posts: 4

PostPosted: Sat Feb 01, 2014 11:02 pm    Post subject: Reply with quote

albertsm wrote:
i have no idea what you mean Very Happy
where do you get the letter from ?
Do you read this from the serial port or keyboard or what?
Anyway say you have a string with value "100" ., you can use VAL() to convert it to a numeric value.

Say you have "1" you can use ASC() to get the ascii value and the subtract 48 from it.
Just some ideas.


Well i'm a student, working my second program in Bascom...

I need to type the number from 1 to 100 (on keyboard) but there's a problem when i press letter (it's just PC, i'm not programming a microcontroller or smtg)... When i press it program runs like i've typed acsii value (it's converting it automatic) so i need to make IF - ELSE condition to test variable declaring... I just don't know how to write that IF - ELSE condition that could test variable type, that's all Very Happy

Anyone can give me exaple or smtg? BCZ i DON'T NEED converting to ASCII code or from ASCII code to letter...
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5091
Location: Holland

blank.gif
PostPosted: Sun Feb 02, 2014 7:58 pm    Post subject: Reply with quote

you say on PC but you mean the terminal emulator? when you enter a key on the keyboard of your PC, how will it end up at the micro?
you use some serial connection ?
in that case this would work :
dim x as byte, s as string * 3
do
x=waitkey()
s=s + chr(x)
if len(s)=3 then
x=val(s) 'now the value is stored in byte value into x
print "got " ; x
s="" ' reset for next time
end if
loop

_________________
Mark
Back to top
View user's profile Visit poster's website
schtygnedec

Bascom Member



Joined: 23 Jan 2014
Posts: 4

PostPosted: Wed Feb 05, 2014 5:39 pm    Post subject: Reply with quote

I don't use any connection....

It's just a simple program, here :

Code:

Dim A As Word
Dim C As Word
Dim X As Word
B:
Print "ENTER A NUMBER IN RANGE FROM 1 TO 100"
Input A
If A >= 1 And A <= 100 Then
For X = A To 100
Print X
Next X
Else
Print "NUMBER IS NOT IN THE RANGE FROM 1 TO 100"
Gosub B
End If
Print "DO YOU WANT TO START PROGRAM AGAIN.TYPE 1 FOR YES ."
Input C
If C = 1 Then
Gosub B
Else
End
End If
 


But when i type letter (lets say "a" ...) it prints from ASCII code number of a to 100, how to edit that (i want to turn it to B when you type letter(string...)?
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5091
Location: Holland

blank.gif
PostPosted: Thu Feb 06, 2014 10:58 am    Post subject: Reply with quote

aha, you mean you want input validation?
in that case you can input a string :
input "number?" , sSomeString

and then you check all characters in the string to be valid. you could use the mid() function for that.
here is some pseudo code:
J=len(sSomestring)
for a=1 to J
krk=mid(sSomestring,a,1) 'get character
p=instr("0123456789", krk) 'get pos
if p=0 then ' illegal data
....
end if
next

_________________
Mark
Back to top
View user's profile Visit poster's website
schtygnedec

Bascom Member



Joined: 23 Jan 2014
Posts: 4

PostPosted: Thu Feb 06, 2014 3:33 pm    Post subject: Reply with quote

Thanks, it works great Very Happy
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-8051 All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum