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
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...
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.
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.
Re: Structures, arrays and files
Quote:
Originally Posted by
jmcilhinney
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
Re: Structures, arrays and files
Re: Structures, arrays and files
Yes, I need to use a multidimensional array
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.
Re: Structures, arrays and files
Quote:
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
Re: Structures, arrays and files
Quote:
Originally Posted by
techgnome
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