M
Mayo Weiss
Hello,
I am doing a project using VisualBasic.net in console mode, it is a sort offorms (Rather it is an "emulation" of forms) in which a user enters data will be stored in a database. Hitherto no problem.
The problem is I have a routine keyboard to control the keys and I would dothat by using the arrow keys could get on and off field to field (To modify if you have entered and we're wrong, for example).
Also if anyone knows how to remove items left over to fill the field and I said I would be very helpful.
Also, if someone want to save someone tell me how to get out of this program just by pressing the Esc key and without using "exit".
Now I leave parts of the code I have done (the necessary) to understand that is what I am saying:
Public Sub MostrarCampos(ByRef Campos() As String)
Dim x As Integer = 0
Dim posicion As Integer = 5
longitud = {12, 35, 30, 30, 5, 9, 9, 35, 35, 15, 2, 2, 2}
Console.BackgroundColor = ConsoleColor.Blue
Console.ForegroundColor = ConsoleColor.White
Console.Clear()
Console.CursorLeft = 17
Console.CursorTop = 2
Console.Write("--Parametros Empresa--")
While x < parametroempresa
Console.SetCursorPosition(left:=5, top:=posicion)
Console.WriteLine(Campos(x))
Console.SetCursorPosition(left:=31, top:=posicion)
Console.Write(StrDup(longitud(x), " "))
x = x + 1
posicion = posicion + 1
End While
End Sub
The next part is the part who call the function CapturaCampo:
Public Sub introducirdatos()
Dim x As Integer = 0
Dim posicion As Integer = 5
Dim control_tecla As New Teclado
Console.CursorLeft = 17
Console.CursorTop = 2
Console.Write("--Parametros Empresa--")
While x < parametroempresa
parametros_empresa(x) = control_tecla.CapturaCampo(Fila:=posicion, Campo:=50, Columna:=31, Longitud:=longitud(x), Opcion:=1, Tipo:=2)
x = x + 1
posicion = posicion + 1
End While
End Sub
And now the code of the keyboard routine:
Public Class Teclado
Dim parametros_empresa As New Parametros_empresa
Enum TipoCampo
AlfaNumerico = 0
Numerico = 1
Alfabetico = 2
End Enum
Enum Accion ' nuevo
Nada = 0
Frecuencia = 1
Media = 2
Listar = 3
Final = 4
End Enum
Public Structure Campo
Dim Fila As Integer
Dim ColLit As Integer
Dim ColCam As Integer
Dim Longitud As Integer
Dim Tipo As Integer
Dim Contenido As String
Dim Literal As String
Dim Ayuda As String
End Structure
Structure Tecla
Public Valor As Char
Public Estado As Boolean
Public Opcion As Accion ' nuevo
End Structure
Public V() As Campo ' datos de un campo
Public Pantalla As String
Public Sub New()
End Sub
Public Sub New(ByVal NomFile As String)
Pantalla = NomFile
ReDim V(4)
End Sub
Private Function LeerTecla(ByVal Tipo As TipoCampo) As Tecla
Dim Tecla As ConsoleKeyInfo
LeerTecla.Estado = False
Tecla = Console.ReadKey(True)
Select Case Tecla.Key
Case ConsoleKey.F1 ' acciones de programa
LeerTecla.Opcion = Accion.Frecuencia
Case ConsoleKey.F2 ' acciones de programa
LeerTecla.Opcion = Accion.Media
Case ConsoleKey.F3 ' acciones de programa
LeerTecla.Opcion = Accion.Listar
Case ConsoleKey.Escape ' acciones de programa
LeerTecla.Opcion = Accion.Final
Case ConsoleKey.Tab
Select Case Tecla.Modifiers
Case ConsoleModifiers.Control
Case ConsoleModifiers.Shift
Case ConsoleModifiers.Alt
End Select
Case Else
Select Case Tipo
Case TipoCampo.AlfaNumerico
Select Case Asc(Tecla.KeyChar)
Case 13, 8
LeerTecla.Valor = Tecla.KeyChar
LeerTecla.Estado = False
Case 32 To 255
LeerTecla.Valor = Tecla.KeyChar
LeerTecla.Estado = True
Case Else
End Select
Case TipoCampo.Alfabetico
Select Case Tecla.KeyChar
Case ControlChars.Cr
LeerTecla.Valor = Tecla.KeyChar
LeerTecla.Estado = False
Case ControlChars.Back
LeerTecla.Valor = Tecla.KeyChar
LeerTecla.Estado = False
Case CChar("a") To CChar("z"), CChar("ñ")
LeerTecla.Valor = Tecla.KeyChar
LeerTecla.Estado = True
Case CChar("A") To CChar("Z"), CChar("Ñ")
LeerTecla.Valor = Tecla.KeyChar
LeerTecla.Estado = True
Case CChar(" ")
LeerTecla.Valor = Tecla.KeyChar
LeerTecla.Estado = True
Case Else
End Select
Case TipoCampo.Numerico
Select Case Tecla.KeyChar
Case ControlChars.Cr
LeerTecla.Valor = Tecla.KeyChar
LeerTecla.Estado = False
Case ControlChars.Back
LeerTecla.Valor = Tecla.KeyChar
LeerTecla.Estado = False
Case CChar("."), CChar(","), CChar("-"), CChar("+"), CChar("0") To CChar("9")
LeerTecla.Valor = Tecla.KeyChar
LeerTecla.Estado = True
Case Else
End Select
End Select
End Select
End Function
Public Function CapturaCampo(ByVal Fila As Integer, _
ByVal Columna As Integer, _
ByVal Longitud As Integer, _
ByVal Tipo As Integer, _
ByRef Campo As String, _
ByRef Opcion As Accion) As String
Dim TipoDato As TipoCampo
Dim Tec As Tecla
Dim Cuantos As Integer = 0
Campo = Space(Longitud)
Console.CursorTop = Fila
Console.CursorLeft = Columna
Console.SetCursorPosition(Columna, Fila)
Console.WriteLine(StrDup(Longitud, "."))
Opcion = Accion.Nada
Select Case Tipo
Case 0
TipoDato = TipoCampo.AlfaNumerico
Case 1
TipoDato = TipoCampo.Numerico
Case 2
TipoDato = TipoCampo.Alfabetico
End Select
Select Case Tec.Valor
Case ControlChars.Back
Case ControlChars.Cr
Case ControlChars.NullChar
End Select
'Tec = LeerTecla(TipoDato)
'While Tec.Valor <> ControlChars.Cr
Do
Console.CursorSize = 100
Console.SetCursorPosition(Columna + Cuantos, Fila)
Tec = LeerTecla(TipoDato)
Select Case Cuantos < Longitud
Case True
Select Case Tec.Estado
Case True
Select Case Tec.Valor
Case ControlChars.Cr
Case Else
Console.CursorTop = Fila
Console.CursorLeft = Columna + Cuantos
Console.Write(Tec.Valor)
Cuantos = Cuantos + 1
Mid(Campo, Cuantos, 1) = Tec.Valor ' no estaba
End Select
End Select
End Select
Select Case Tec.Valor
Case ControlChars.Back
If Cuantos > 0 Then
Mid(Campo, Cuantos, 1) = " " ' no estaba
Cuantos = Cuantos - 1
Console.CursorTop = Fila
Console.CursorLeft = Columna + Cuantos
Console.Write(".")
End If
End Select
Loop Until Tec.Opcion <> Accion.Nada Or Tec.Valor = ControlChars.Cr
' Tec = LeerTecla(TipoDato)
'End While
Campo = Trim(Campo)
Opcion = Tec.Opcion
Return Campo
End Function
End Class
If you need anything else or is there something I have not explained well or do not understand... Tells me and I try to reexplain.
Thanks you and sorry for my bad level of english
I am doing a project using VisualBasic.net in console mode, it is a sort offorms (Rather it is an "emulation" of forms) in which a user enters data will be stored in a database. Hitherto no problem.
The problem is I have a routine keyboard to control the keys and I would dothat by using the arrow keys could get on and off field to field (To modify if you have entered and we're wrong, for example).
Also if anyone knows how to remove items left over to fill the field and I said I would be very helpful.
Also, if someone want to save someone tell me how to get out of this program just by pressing the Esc key and without using "exit".
Now I leave parts of the code I have done (the necessary) to understand that is what I am saying:
Public Sub MostrarCampos(ByRef Campos() As String)
Dim x As Integer = 0
Dim posicion As Integer = 5
longitud = {12, 35, 30, 30, 5, 9, 9, 35, 35, 15, 2, 2, 2}
Console.BackgroundColor = ConsoleColor.Blue
Console.ForegroundColor = ConsoleColor.White
Console.Clear()
Console.CursorLeft = 17
Console.CursorTop = 2
Console.Write("--Parametros Empresa--")
While x < parametroempresa
Console.SetCursorPosition(left:=5, top:=posicion)
Console.WriteLine(Campos(x))
Console.SetCursorPosition(left:=31, top:=posicion)
Console.Write(StrDup(longitud(x), " "))
x = x + 1
posicion = posicion + 1
End While
End Sub
The next part is the part who call the function CapturaCampo:
Public Sub introducirdatos()
Dim x As Integer = 0
Dim posicion As Integer = 5
Dim control_tecla As New Teclado
Console.CursorLeft = 17
Console.CursorTop = 2
Console.Write("--Parametros Empresa--")
While x < parametroempresa
parametros_empresa(x) = control_tecla.CapturaCampo(Fila:=posicion, Campo:=50, Columna:=31, Longitud:=longitud(x), Opcion:=1, Tipo:=2)
x = x + 1
posicion = posicion + 1
End While
End Sub
And now the code of the keyboard routine:
Public Class Teclado
Dim parametros_empresa As New Parametros_empresa
Enum TipoCampo
AlfaNumerico = 0
Numerico = 1
Alfabetico = 2
End Enum
Enum Accion ' nuevo
Nada = 0
Frecuencia = 1
Media = 2
Listar = 3
Final = 4
End Enum
Public Structure Campo
Dim Fila As Integer
Dim ColLit As Integer
Dim ColCam As Integer
Dim Longitud As Integer
Dim Tipo As Integer
Dim Contenido As String
Dim Literal As String
Dim Ayuda As String
End Structure
Structure Tecla
Public Valor As Char
Public Estado As Boolean
Public Opcion As Accion ' nuevo
End Structure
Public V() As Campo ' datos de un campo
Public Pantalla As String
Public Sub New()
End Sub
Public Sub New(ByVal NomFile As String)
Pantalla = NomFile
ReDim V(4)
End Sub
Private Function LeerTecla(ByVal Tipo As TipoCampo) As Tecla
Dim Tecla As ConsoleKeyInfo
LeerTecla.Estado = False
Tecla = Console.ReadKey(True)
Select Case Tecla.Key
Case ConsoleKey.F1 ' acciones de programa
LeerTecla.Opcion = Accion.Frecuencia
Case ConsoleKey.F2 ' acciones de programa
LeerTecla.Opcion = Accion.Media
Case ConsoleKey.F3 ' acciones de programa
LeerTecla.Opcion = Accion.Listar
Case ConsoleKey.Escape ' acciones de programa
LeerTecla.Opcion = Accion.Final
Case ConsoleKey.Tab
Select Case Tecla.Modifiers
Case ConsoleModifiers.Control
Case ConsoleModifiers.Shift
Case ConsoleModifiers.Alt
End Select
Case Else
Select Case Tipo
Case TipoCampo.AlfaNumerico
Select Case Asc(Tecla.KeyChar)
Case 13, 8
LeerTecla.Valor = Tecla.KeyChar
LeerTecla.Estado = False
Case 32 To 255
LeerTecla.Valor = Tecla.KeyChar
LeerTecla.Estado = True
Case Else
End Select
Case TipoCampo.Alfabetico
Select Case Tecla.KeyChar
Case ControlChars.Cr
LeerTecla.Valor = Tecla.KeyChar
LeerTecla.Estado = False
Case ControlChars.Back
LeerTecla.Valor = Tecla.KeyChar
LeerTecla.Estado = False
Case CChar("a") To CChar("z"), CChar("ñ")
LeerTecla.Valor = Tecla.KeyChar
LeerTecla.Estado = True
Case CChar("A") To CChar("Z"), CChar("Ñ")
LeerTecla.Valor = Tecla.KeyChar
LeerTecla.Estado = True
Case CChar(" ")
LeerTecla.Valor = Tecla.KeyChar
LeerTecla.Estado = True
Case Else
End Select
Case TipoCampo.Numerico
Select Case Tecla.KeyChar
Case ControlChars.Cr
LeerTecla.Valor = Tecla.KeyChar
LeerTecla.Estado = False
Case ControlChars.Back
LeerTecla.Valor = Tecla.KeyChar
LeerTecla.Estado = False
Case CChar("."), CChar(","), CChar("-"), CChar("+"), CChar("0") To CChar("9")
LeerTecla.Valor = Tecla.KeyChar
LeerTecla.Estado = True
Case Else
End Select
End Select
End Select
End Function
Public Function CapturaCampo(ByVal Fila As Integer, _
ByVal Columna As Integer, _
ByVal Longitud As Integer, _
ByVal Tipo As Integer, _
ByRef Campo As String, _
ByRef Opcion As Accion) As String
Dim TipoDato As TipoCampo
Dim Tec As Tecla
Dim Cuantos As Integer = 0
Campo = Space(Longitud)
Console.CursorTop = Fila
Console.CursorLeft = Columna
Console.SetCursorPosition(Columna, Fila)
Console.WriteLine(StrDup(Longitud, "."))
Opcion = Accion.Nada
Select Case Tipo
Case 0
TipoDato = TipoCampo.AlfaNumerico
Case 1
TipoDato = TipoCampo.Numerico
Case 2
TipoDato = TipoCampo.Alfabetico
End Select
Select Case Tec.Valor
Case ControlChars.Back
Case ControlChars.Cr
Case ControlChars.NullChar
End Select
'Tec = LeerTecla(TipoDato)
'While Tec.Valor <> ControlChars.Cr
Do
Console.CursorSize = 100
Console.SetCursorPosition(Columna + Cuantos, Fila)
Tec = LeerTecla(TipoDato)
Select Case Cuantos < Longitud
Case True
Select Case Tec.Estado
Case True
Select Case Tec.Valor
Case ControlChars.Cr
Case Else
Console.CursorTop = Fila
Console.CursorLeft = Columna + Cuantos
Console.Write(Tec.Valor)
Cuantos = Cuantos + 1
Mid(Campo, Cuantos, 1) = Tec.Valor ' no estaba
End Select
End Select
End Select
Select Case Tec.Valor
Case ControlChars.Back
If Cuantos > 0 Then
Mid(Campo, Cuantos, 1) = " " ' no estaba
Cuantos = Cuantos - 1
Console.CursorTop = Fila
Console.CursorLeft = Columna + Cuantos
Console.Write(".")
End If
End Select
Loop Until Tec.Opcion <> Accion.Nada Or Tec.Valor = ControlChars.Cr
' Tec = LeerTecla(TipoDato)
'End While
Campo = Trim(Campo)
Opcion = Tec.Opcion
Return Campo
End Function
End Class
If you need anything else or is there something I have not explained well or do not understand... Tells me and I try to reexplain.
Thanks you and sorry for my bad level of english