Trabajando Con Estructuras En Visual Basic

Trabajando Con Estructuras En Visual Basic

<p>Proyecto: ManejarRobot Nombre del Form: Form1</p><p>Public Class Form1 Inherits System.Windows.Forms.Form Dim oRobot As NASA.Robot</p><p>Private Sub btnConectar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConectar.Click 'Se le pasa los valores a los argumentos del constructor 'definido en la Clase Robot Dim Datos As NASA.DatosConexion With Datos .Contraseña = "ABC" .Puerto = 100 .Velocidad = 1000 End With End Sub</p><p>Private Sub btnArriba_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnArriba.Click Dim strMensaje As String = oRobot.Mover(NASA.Movimiento.MoverArriba) MessageBox.Show(strMensaje) End Sub</p><p>Private Sub btnAdelante_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdelante.Click Dim strMensaje As String = oRobot.Mover(NASA.Movimiento.MoverAdelante) MessageBox.Show(strMensaje) End Sub</p><p>Private Sub btnAbajo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAbajo.Click Dim strMensaje As String = oRobot.Mover(NASA.Movimiento.MoverAbajo) MessageBox.Show(strMensaje) End Sub</p><p>Private Sub btnAtras_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAtras.Click Dim strMensaje As String = oRobot.Mover(NASA.Movimiento.MoverAtras) MessageBox.Show(strMensaje) End Sub Private Sub btnValidar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnValidar.Click Try Dim cRes As String = oRobot.ValidarContraseña(txtContraseña.Text) MessageBox.Show("CONTRASEÑA CORRECTA" & cRes.ToString)</p><p>Catch ex As Exception MessageBox.Show(ex.Message) Finally txtContraseña.Text = "" btnConectar.Enabled = True End Try End Sub</p><p>Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load oRobot = New NASA.Robot(1, "10-220-30") End Sub</p><p>Private Sub txtContraseña_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtContraseña.TextChanged If txtContraseña.Text <> "" Then btnConectar.Enabled = True Else btnConectar.Enabled = False End If End Sub End Class</p><p>Proyecto: NASA</p><p>Nombre de la Clase: Robot</p><p>Public Class Robot Private Const nombreInicial As String = "Marte"</p><p>#Region "Constructores" Public Sub New(ByVal Correlativo As String, ByVal SerieRobot As String) 'Constructor 'En la siguiente linea muestra la fecha y hora actual de hoy Me.Nombre = nombreInicial & DateTime.Now.ToString & Correlativo Me.NumeroSerie = SerieRobot End Sub #End Region 'TODO Falta verificar los metodos</p><p>Private mSerie As String Public Function Mover(ByVal Opcion As Movimiento) As String Dim strMensaje As String Select Case Opcion Case Opcion.MoverAbajo strMensaje = "Abajo" Case Opcion.MoverAdelante strMensaje = "Adelante" Case Opcion.MoverArriba strMensaje = "Arriba" Case Opcion.MoverAtras strMensaje = "Atras" End Select</p><p>Return "Mover " & strMensaje</p><p>End Function</p><p>Public Property NumeroSerie() As String Get Return mSerie End Get Set(ByVal Value As String) mSerie = Value End Set End Property Private mNombre As String Public Property Nombre() As String Get Return mNombre End Get Set(ByVal Value As String) mNombre = Value End Set End Property</p><p>Public Function ConectarRobot(ByVal Datos As DatosConexion) As String 'La funcion me retorna el valor, en cambio el sub no retorna el valor Return "Conectado al Puerto" End Function</p><p>Public Function ValidarContraseña(ByVal contraseña As String) As String If contraseña.Length = 3 Then Dim password As String = " (ES VALIDA)" Return password Else Throw New Exception("CONTRASEÑA NO VALIDA") End If End Function End Class</p><p>Nombre de la Clase: Enumerados.vb</p><p>Public Enum Movimiento 'Creamos un tipo enumerado para tener una descripcion completa 'que manejemos dentro del codigo MoverArriba MoverAbajo MoverAtras MoverAdelante End Enum</p><p>Nombre de la Clase: Estructura.vb</p><p>Public Structure DatosConexion Public Puerto As Integer Public Velocidad As Integer Public Contraseña As String End Structure</p>

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    4 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us