Advertisement
conception

Glovers Solution

Apr 15th, 2015
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. Public Class frmMain
  2. 'Declare array of structure variables:
  3. Private itemList(4) As Product
  4.  
  5. Structure Product
  6. Public strItem As String
  7. Public dblPrice As Double
  8. End Structure
  9.  
  10. Private Sub frmMain_Load(sender As Object, e As EventArgs) Handles Me.Load
  11. 'fill arrays with Item numbers and Prices
  12. Dim inFile As IO.StreamReader
  13. Dim intArray As Integer
  14. Dim intLength As Integer
  15. Dim strNum As String
  16.  
  17. 'check to see if file exists
  18. If IO.File.Exists("ItemInfo.txt") Then
  19. 'open file for input
  20. inFile = IO.File.OpenText("ItemInfo.txt")
  21. 'process loop instructions until end of file
  22.  
  23. Do Until inFile.Peek = -1
  24. 'read an item number
  25. strNum = inFile.ReadLine
  26. Integer.TryParse(strNum, intLength)
  27. If intLength = 5 Then
  28. itemList(intArray).strItem = strNum
  29. Else
  30. Double.TryParse(strNum, itemList(intArray).dblPrice)
  31. End If
  32.  
  33. 'add item number to list box
  34. lstItems.Items.Add(itemList(intArray).strItem)
  35. intArray = intArray + 1
  36. Loop
  37. 'close the file
  38. inFile.Close()
  39.  
  40. End If
  41. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement