VB.NET Code Examples for Arrays and Timer Controls

Classified in Computers

Written on in English with a size of 2.92 KB

Weight Calculation and Session Management in VB.NET

This example demonstrates how to handle weight data using arrays and manage application sessions with timers.

Public Class Form1
    Dim PESOPERSONA(1) As Integer
    Dim PESOTOTAL As Integer

    Private Sub Form1_Load(...)
        Me.Text = "CÁLCULO DE PESO"
        Label1.Text = "RESULTADO"
        Label2.Text = "" & vbCrLf
        PESOPERSONA(0) = 105
        PESOPERSONA(1) = 55

        For i = 0 To 7
            If PESOPERSONA(i) < 10 Or PESOPERSONA(i) > 100 Then
                Label2.Text = Label2.Text & "EL DATO DE PESO " & i & " no es válido por no estar entre 10 y 100 " & vbCrLf
            Else
                PESOTOTAL = PESOTOTAL + PESOPERSONA(i)
            End If
        Next i
        Label3.Text = "EL PESO MEDIO ES " & PESOTOTAL / 2
    End Sub

    Private Sub Timer1_Tick(...)
        Label1.Text = "Cerrar sesión"
        Timer1.Stop()
        Timer2.Start()
    End Sub

    Private Sub Timer2_Tick(...)
        Label1.Text = "Cerrando aplicación"
        Timer2.Stop()
        Timer3.Start()
    End Sub

    Private Sub Timer3_Tick(...)
        Label1.Visible = False
        End
    End Sub

    Private Sub Button1_Click(...)
        Timer1.Start()
    End Sub
End Class

Array Handling and Data Filtering in Visual Basic

The following code illustrates how to use a vector to store user input and filter values based on specific conditions.

Public Class Form1
    Dim n As Integer
    Dim y As Integer
    Dim vector(0 To 1000) As Integer

    Private Sub Button1_Click(...)
        n = Convert.ToInt16(Me.TextBox1.Text)
        For i = 0 To n
            vector(i) = InputBox("Número " & i)
        Next

        For i = 0 To n
            y = vector(i) / 2
            If vector(i) Mod y = 0 Then
                ListBox1.Items.Add(vector(i))
            End If
        Next

        For i = 0 To n
            If vector(i) > 100 Then
                ListBox2.Items.Add(vector(i))
            End If
        Next
    End Sub
End Class

Additional Array Processing Example

Below is a repeated instance of the array logic as provided in the source document to ensure all content is preserved.

Public Class Form1
    Dim n As Integer
    Dim y As Integer
    Dim vector(0 To 1000) As Integer

    Private Sub Button1_Click(...)
        n = Convert.ToInt16(Me.TextBox1.Text)
        For i = 0 To n
            vector(i) = InputBox("Número " & i)
        Next

        For i = 0 To n
            y = vector(i) / 2
            If vector(i) Mod y = 0 Then
                ListBox1.Items.Add(vector(i))
            End If
        Next

        For i = 0 To n
            If vector(i) > 100 Then
                ListBox2.Items.Add(vector(i))
            End If
        Next
    End Sub
End Class

Related entries: