2 Replies - 463 Views - Last Post: 21 March 2011 - 08:35 PM Rate Topic: -----

#1 fallenreaper  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 240
  • Joined: 19-June 10

error when assigning elements to an array of structures..

Posted 21 March 2011 - 06:26 PM

I am getting an error when helping someone with their code. They are trying to create an array of Items, but gets an error at ItemStruc(counter).ItemName = Contents(0)

I am not sure why. >_>

Structure is as follows:
public structure Item 
     dim itemName as String
     dim itemCost as double
end structure

 Dim counter As Integer
        counter = 0
        Dim ItemStruc As Item()
        Do While (counter < fileLength)
            txtRandom.Text = txtRandom.Text + Line.ToString
            'Dim Line As String = s(counter)
            Try
                Dim Contents As String() = Line.Split("-")
                'Splitting items in Inventory List into an array 
                ItemStruc(counter).ItemName = Contents(0)
                ItemStruc(counter).ItemCost = Contents(1)
                Dim strNewItem As String
                strNewItem = FormatCurrency(ItemStruc(counter).ItemCost) & " - [" & ItemStruc(counter).ItemName & "]"
                lstInventory.Items.Add(strNewItem)
                counter = counter + 1
            Catch ex As Exception
                MessageBox.Show(ex.Message)
            End Try



Is This A Good Question/Topic? 0
  • +

Replies To: error when assigning elements to an array of structures..

#2 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 574
  • View blog
  • Posts: 2,989
  • Joined: 19-May 09

Re: error when assigning elements to an array of structures..

Posted 21 March 2011 - 07:51 PM

what's the error?
Was This Post Helpful? 0
  • +
  • -

#3 fallenreaper  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 240
  • Joined: 19-June 10

Re: error when assigning elements to an array of structures..

Posted 21 March 2011 - 08:35 PM

We found a solution! Thanks ^_^!
 Private Sub frmCheckout_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim Array As Inventory()
        Dim ItemsInventory() As String = IO.File.ReadAllLines("inventory.txt")
        For counter As Integer = 0 To ItemsInventory.Length
            Dim s As String = ItemsInventory(counter)
            Dim temp As String() = s.Split("-")
            Dim x As String = "[" + temp(0) + "] - " + (FormatCurrency(temp(1)))
            lstInventory.Items.Add(x)

        Next

    End Sub



We stepped through it and rewrote it from scratch. :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1