Results 1 to 10 of 10

Thread: Structures, arrays and files

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2020
    Posts
    4

    Exclamation Structures, arrays and files

    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 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.

    Code:
     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
    Last edited by Mcek; Dec 13th, 2020 at 08:32 AM.

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,413

    Re: Structures, arrays and files

    When you post a code block here, select the block of text and click the # (code) button in the message editor. Your code formatting will be preserved, and we’ll all be able to read it easier...

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Structures, arrays and files

    Is this a homework assignment that requires you to use a multi dimensional array? If not, don't do it.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Structures, arrays and files

    As for the issue, you need to debug your code first. You need to be able to point out exactly where the actual behaviour differs from the expected and what each of those behaviours is.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5
    PowerPoster ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    3,129

    Re: Structures, arrays and files

    Quote Originally Posted by jmcilhinney View Post
    Is this a homework assignment that requires you to use a multi dimensional array? If not, don't do it.
    sure could be Homework,

    I would use OLEDB with a Datareader to search(with SQL) and then read that foundline to Labels
    or Return that nothing was found
    to hunt a species to extinction is not logical !
    since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.

  6. #6

    Thread Starter
    New Member
    Join Date
    Dec 2020
    Posts
    4

    Re: Structures, arrays and files

    Okay
    Last edited by Mcek; Dec 13th, 2020 at 10:01 AM.

  7. #7

    Thread Starter
    New Member
    Join Date
    Dec 2020
    Posts
    4

    Re: Structures, arrays and files

    Yes, I need to use a multidimensional array

  8. #8
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,102

    Re: Structures, arrays and files

    Well, if it's homework, have you covered breakpoints and stepping through code, yet? Lots of classes seem to leave that till late, or leave it out entirely, but it's the single most valuable skill you can have, and I would say that it should be covered first or second. Still, if you haven't covered that, ask about that, because it's what you want to be using. That's what JMC was talking about in post #4.

    That class is doing one thing right, because you are using Integer.TryParse to check user input. However, you are being a bit inefficient about it:

    Code:
    If Integer.TryParse(txtNumeroProducto.Text, intProducto) Then
                intProducto = CInt(txtNumeroProducto.Text)
    The second line isn't necessary. What TryParse does is attempt the conversion. If it succeeds, then the converted integer is put into the second argument. In other words, if TryParse works, then intProducto already has the correct integer, so repeating the conversion and assignment in the second line is redundant.
    My usual boring signature: Nothing

  9. #9
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Structures, arrays and files

    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 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.
    You've declared multiple arrays... not multi-dimentional arrays...
    You've declared a structure... but then aren't using it.
    You're opened a file, but then don't use it to search...

    Instead you've declare a number of arrays, hard-coded values into them, looked through THAT data, then try to read frmo the file when you find a match in the array... I don't think that was the intent.

    I *think* you were supposed to open the file, use the structure to read from it, put the data into the arrays (or array since it's supposed to be multi-dimentional (yuck)) ... THEN loop through THAT to find the data and display it.

    You're getting strange solutions because the assignment is completely counter to how it would be done in the real world... however... it is what it is, and sometimes we have to deal with the strangest of requirements regardless of their insanity.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  10. #10

    Thread Starter
    New Member
    Join Date
    Dec 2020
    Posts
    4

    Re: Structures, arrays and files

    Quote Originally Posted by techgnome View Post
    You've declared multiple arrays... not multi-dimentional arrays...
    You've declared a structure... but then aren't using it.
    You're opened a file, but then don't use it to search...

    Instead you've declare a number of arrays, hard-coded values into them, looked through THAT data, then try to read frmo the file when you find a match in the array... I don't think that was the intent.

    I *think* you were supposed to open the file, use the structure to read from it, put the data into the arrays (or array since it's supposed to be multi-dimentional (yuck)) ... THEN loop through THAT to find the data and display it.

    You're getting strange solutions because the assignment is completely counter to how it would be done in the real world... however... it is what it is, and sometimes we have to deal with the strangest of requirements regardless of their insanity.

    -tg
    Ok that’s exactly what I need

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width