The user is going to enter the product number, then the program must be able to open the file, read the information of a inventory in the company, capture the information into an structured array and display the specific product with its information in the labels. all this using a multidimensional arrays and also the structures. currently in the execution it reads only one part of the data.

I think that the direct declaration of the array is causing part of the problem, also my program is not reading and capturing well.

Imports System.IO

Public Class frmMain
    Public Structure sInventory
        Public strProductNumber As String
        Public strProductDescription As String
        Public intProductQuantity As Integer
        Public dblProductCost As Double
        Public dblProductMarkup As Double
    End Structure

    Private Sub mnuBuscarProducto_Click(sender As Object, e As EventArgs) Handles mnuBuscarProducto.Click
        ' read the file
        Dim inventarioFile As StreamReader
        inventarioFile = File.OpenText("DatosInventario.txt")

        'Array
        Dim strProductos() As String = {"123", "234", "345", "456", "567", "678"}
        Dim strDescripcion() As String = {"Juego de comedor con 2 sillas", "Sofá cama", "Escritorio", "Cama king", "Librero de 6'", "Mueble para pecera"}
        Dim intCantidad() As Integer = {15, 10, 25, 5, 35, 8}
        Dim dblCostos() As Double = {425.0, 769.0, 250.0, 1875.0, 399.0, 350.0}
        Dim dblProrciento() As Double = {0.25, 0.25, 0.35, 0.2, 0.3, 0.2}
        Dim i As Integer = 0
        Dim intProducto As Integer 'Valor que ingresó el usuario capturado

        'capture and validate
        If Integer.TryParse(txtNumeroProducto.Text, intProducto) Then
            intProducto = CInt(txtNumeroProducto.Text)
        Else
            MessageBox.Show("Debe ingresar un entero de tres dígitos")
        End If

        'Find something in the archive
        Dim blnBuscador As Boolean = False
        Do While blnBuscador = False And i <= (strProductos.Length - 1)
            If strProductos(i) = intProducto Then
                blnBuscador = True
                lblDescripcion.Text = inventarioFile.ReadLine()
                lblInventario.Text = inventarioFile.ReadLine()
                lblCosto.Text = inventarioFile.ReadLine()
                lblPrecioVenta.Text = inventarioFile.ReadLine()
                lblImporteCosto.Text = inventarioFile.ReadLine
                lblImportePrecioVenta.Text = inventarioFile.ReadLine
            End If
        Loop
        i += 1
        inventarioFile.Close()
    End Sub

    Private Sub frmMain_FormClosing(sender As Object, e As FormClosingEventArgs) Handles MyBase.FormClosing
        If MessageBox.Show("Desea cerrar la aplicación?", "Confirmar", MessageBoxButtons.YesNo) = DialogResult.Yes Then
            e.Cancel = False
        Else
            e.Cancel = True
        End If
    End Sub

    Private Sub mnuSalir_Click(sender As Object, e As EventArgs) Handles mnuSalir.Click
        Me.Close()
        frmSplash.Close()
    End Sub

    Private Sub frmMain_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        'Open the file text
        ofdDatosInventario.ShowDialog()
    End Sub
End Class

I found the following in your code:

  1. There is missing a Exit Sub right after Messagebox in between lines 30 and 31.
  2. Line 46 where variable i is incremented, should go before Loop in line 45.
  3. In line 36 you are comparing strProductos(i) (which is a String) with intProducto defined as Integer. You must compare strings with strings or, integers with integers.
    So, you could change line 36
    If strProductos(i) = intProducto Then
    into
    If strProductos(i) = txtNumeroProducto.Text Then
    In this way you will be comparing two strings.
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.