You're Browsing As A Guest! Register Now... |
||
|
Become a VB Expert!
Join 414,938 VB Programmers for FREE! Get instant access to thousands
of VB experts, tutorials, code snippets, and more! There are 2,680 people online right now.Registration is fast and FREE... Join Now!
|
||
Page 1 of 1
Converting Values recieved from Console.Readkey to ASCII
#1
Converting Values recieved from Console.Readkey to ASCII
Posted 20 April 2007 - 04:52 PM
I am trying to output the number of times a person hit the enter key after submitting 5 keystrokes. I am trying to convert the input to ascii, but everything I try returns an error message when I try to do the conversion to ascii. It states the Console function can not have an integer value. By the way this is a console application. This is what I have so far:
Dim inputVal As ConsoleKeyInfo
Console.WriteLine("Enter 5 keystrokes")
Dim counter As Integer
Dim i As Integer
For i = 1 To 5
inputVal = Console.ReadKey
If inputVal = Asc("cr") Then
counter = counter + 1
End If
Next
Console.WriteLine()
Console.WriteLine("You clicked Enter " & counter & " times")
Console.Write("Hit any key to continue...")
Console.ReadKey()
I think I am missing something in the conversion process, because the logic I am using seems correct. Any guidance would greatly be appreciated.
Dim inputVal As ConsoleKeyInfo
Console.WriteLine("Enter 5 keystrokes")
Dim counter As Integer
Dim i As Integer
For i = 1 To 5
inputVal = Console.ReadKey
If inputVal = Asc("cr") Then
counter = counter + 1
End If
Next
Console.WriteLine()
Console.WriteLine("You clicked Enter " & counter & " times")
Console.Write("Hit any key to continue...")
Console.ReadKey()
I think I am missing something in the conversion process, because the logic I am using seems correct. Any guidance would greatly be appreciated.
#2
Re: Converting Values recieved from Console.Readkey to ASCII
Posted 20 April 2007 - 06:59 PM
okay...so i figured this out....I converted the inputVal.Key to chr(13) by doing the following
If Char(inputval.Key) = chr(13) then
counter = counter + 1
This solved that problem...now I want it to loop until i hit "x", the ascii chart states the "x" should be chr(120) but it seems as though when I use that it does not correspond to "x". After some experimentation i found that some of the numbers do not correspond to that character.
Below is a code example
Sub Main()
Dim inputVal As ConsoleKeyInfo
Console.WriteLine("Enter 5 keystrokes")
Dim counter As Integer
inputVal = Console.ReadKey
While Chr(inputVal.Key) <> Chr(120)
inputVal = Console.ReadKey
If Chr(inputVal.Key) = Chr(13) Then
counter = counter + 1
End If
End While
Console.WriteLine()
Console.WriteLine("You clicked Enter " & counter & " times")
Console.Write("Hit any key to continue...")
Console.ReadKey()
Do I have wrong value in the Chr() method. According to the chart is seems 120 is the right value. Again any guidance would be greatly appreciated.
If Char(inputval.Key) = chr(13) then
counter = counter + 1
This solved that problem...now I want it to loop until i hit "x", the ascii chart states the "x" should be chr(120) but it seems as though when I use that it does not correspond to "x". After some experimentation i found that some of the numbers do not correspond to that character.
Below is a code example
Sub Main()
Dim inputVal As ConsoleKeyInfo
Console.WriteLine("Enter 5 keystrokes")
Dim counter As Integer
inputVal = Console.ReadKey
While Chr(inputVal.Key) <> Chr(120)
inputVal = Console.ReadKey
If Chr(inputVal.Key) = Chr(13) Then
counter = counter + 1
End If
End While
Console.WriteLine()
Console.WriteLine("You clicked Enter " & counter & " times")
Console.Write("Hit any key to continue...")
Console.ReadKey()
Do I have wrong value in the Chr() method. According to the chart is seems 120 is the right value. Again any guidance would be greatly appreciated.
#4
Re: Converting Values recieved from Console.Readkey to ASCII
Posted 20 April 2007 - 07:13 PM
I know about consolekey.x and I would use that except the lesson is dealing with converting input to chr and theoritically it should work like chr(13) but for some reason chr(120) is not equalling to "x" and according to the ascii chart it should. Any clues about that? Thanks for your help and time.
#5
Re: Converting Values recieved from Console.Readkey to ASCII
Posted 21 April 2007 - 05:10 PM
I wanted to know if anyone had a chance to look at my response to the help I recieved. I am asking again just to see if anyone else may have an idea or may be able to guide me in the right direction. Again, thanks for all of your help.
Page 1 of 1


Ask A New Question
Reply





MultiQuote






|