Re: Console app, reading lines etc.

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Hi,

I'm sure there are more ways to make this more robust. I just added the
following case:
Case ConsoleKey.Backspace
If input.Length > 0 Then
input = input.Remove(input.Length - 1, 1)
Console.Write(ControlChars.Back)
Console.Write(" ")
Console.Write(ControlChars.Back)
justtabbed = False
End If

With use I'll probably add more.

"Family Tree Mike" wrote:

"Paul" <vis@xxxxxxxxxxxxx> wrote in message
news:FB6E48D4-5F25-408D-BC67-71D284FC1188@xxxxxxxxxxxxxxxx
Hi,

In a console app, using VB2008, I'm trying to emulate some of the
functionality available in cmd.exe. Specifically, if in cmd.exe, and you
type
"cd <TAB>" it toggles between folder names.

I need to read information that the user types, or, alternatively, if user
hits the TAB key, I want to toggle the text displayed between a list of
strings I have ready in the app.

Any idea of an available framework for this sort of thing. I'm struggling
with my code, getting myself confused by readkey and readline, and
handling
backspaces etc.

Regards
Paul


I believe the only way to do this is to suppress the keys going to the
console when typed, and only utilizing console.write, bypassing console
input. The following code shows an example:

Sub Main()
Dim input As String = "ok"
Dim idx As Integer = 0
Dim words As List(Of String) = New List(Of String)

words.Add("Green")
words.Add("Blue")
words.Add("Volvo")

While (input <> String.Empty)
input = String.Empty
Dim key As ConsoleKeyInfo
Dim flag As Boolean = True
Dim justtabbed As Boolean = False

While flag
' suppress key going to console
key = Console.ReadKey(True)
Select Case key.Key
Case ConsoleKey.Enter
flag = False
justtabbed = False
Case ConsoleKey.Tab
If (justtabbed) Then
' erase previous word
For j As Integer = 1 To words(idx).Length
Console.Write(ControlChars.Back)
Console.Write(" ")
Console.Write(ControlChars.Back)
Next
input = input.Substring(0,
input.Length - words(idx).Length)
End If
idx = idx + 1
If (idx = words.Count) Then idx = 0
Console.Write(words(idx))
justtabbed = True
input = input + words(idx)
Case Else
Console.Write(key.KeyChar)
input = input + key.KeyChar
justtabbed = False
End Select
End While
Console.WriteLine()
Console.WriteLine("-> [" & input & "]")
End While
End Sub

Hopefully this helps.

--
Mike

.



Relevant Pages

  • Re: Task Scheduler - Quick Question - Code Included
    ... > 'If this flag is clear, ... > Public Function AddScheduleTask(strTime As String, strCommand As String, _ ... > Dim strComputerName As String ...
    (microsoft.public.vb.general.discussion)
  • Task Scheduler - Quick Question - Code Included
    ... 'If this flag is clear, ... Public Function AddScheduleTask(strTime As String, strCommand As String, _ ... Dim strComputerName As String ...
    (microsoft.public.vb.general.discussion)
  • hack that key validation.
    ... Public Sub New(ByVal code As String) ... Dim flag As Boolean = False ... Private Function CheckMiszung(ByVal kodProduktu As String, ...
    (microsoft.public.dotnet.languages.vb)
  • Re: hack that key validation.
    ... Public Sub New(ByVal code As String) ... Dim flag As Boolean = False ... Private Function CheckMiszung(ByVal kodProduktu As String, ...
    (microsoft.public.dotnet.languages.vb)
  • RE: Update SQL Error
    ... I am doing it this way because I have 9 flag fields and I don't want to have ... Private Sub btn_ClFlag_Click ... Dim flgFieldNo As String ...
    (microsoft.public.access.formscoding)