Re: Console app, reading lines etc.

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



"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: Console app, reading lines etc.
    ... In a console app, using VB2008, I'm trying to emulate some of the ... Dim input As String = "ok" ... Dim words As List(Of String) = New List ... Dim flag As Boolean = True ...
    (microsoft.public.dotnet.general)
  • Re: Console app, reading lines etc.
    ... In a console app, using VB2008, I'm trying to emulate some of the ... Dim input As String = "ok" ... Dim words As List(Of String) = New List ...
    (microsoft.public.dotnet.general)
  • Re: Printing from an ASP.NET page
    ... webservice or even simple network socket programming is ok(or if you ... For the console application, do not call it from your ASP.NET application, ... you are doing the samething as you try calling winform printing ... The following code fails at "Dim p As System.Diagnostics.Process." ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Console Application Alternate Windows Credentials
    ... ConsoleApplicationCredentials to the module of my console application ... phtoken As IntPtr) As Boolean ... Dim lpMsgBuf As String ... Dim impersonatedUser As WindowsImpersonationContext ...
    (microsoft.public.dotnet.security)
  • Re: vb6 run from and output to command window
    ... VB doesn't really create true console applications (because the linker ... allocate the console window, and read/write from/to it. ... Private Declare Function AllocConsole Lib "kernel32" As Long ... Dim lResult As Long ...
    (microsoft.public.vb.general.discussion)