Copy Items From An Array Into A ListBox?
I'm trying to write a simple program that has a textbox, a button, and a listbox. Basically, the user enters a file path into the textbox to access a file that has names and phone numbers. Then the user clicks the button to copy those items from the file into an array.
Eventually I want to take those items from the array and copy them into a Listbox.
My program is only made to the point where it wants to make an array but it gets stuck at the line marked " **** " - it's like an object error or something.
Can someone take a minute to take a glance at it and maybe give me a pointer? Thanks :)
---
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents ListBox1 As System.Windows.Forms.ListBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.ListBox1 = New System.Windows.Forms.ListBox()
Me.TextBox1 = New System.Windows.Forms.TextBox()
Me.Button1 = New System.Windows.Forms.Button()
Me.SuspendLayout()
'
'ListBox1
'
Me.ListBox1.Location = New System.Drawing.Point(168, 72)
Me.ListBox1.Name = "ListBox1"
Me.ListBox1.Size = New System.Drawing.Size(96, 95)
Me.ListBox1.TabIndex = 0
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(16, 56)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(120, 20)
Me.TextBox1.TabIndex = 1
Me.TextBox1.Text = "Enter Path"
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(16, 128)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(120, 40)
Me.Button1.TabIndex = 2
Me.Button1.Text = "Engage!"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 273)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Button1, Me.TextBox1, Me.ListBox1})
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
Public Class phoneB
Public Structure namePhone
Public name As String
Public phone As String
End Structure
' class variables
Private phoneBook(100) As namePhone
Private count As Integer
Public Function ReadFile(ByVal filename As String)
'inside routine to read a file
'local variables
Dim s As String
Dim i, linecount As Integer
FileOpen(1, filename, OpenMode.Input) ' filename is a string variable
s = LineInput(1)
count = Val(s)
linecount = count
If (count > phoneBook.Length) Then
ReDim phoneBook(count)
End If
For i = 0 To (linecount - 1) Step 1
s = LineInput(1)
phoneBook(i).name = s
' put the name from string s in the phonebook at i
s = LineInput(1)
phoneBook(i).phone = s
' put the phone number from string s in the phonebook at i
Next i
FileClose(1)
End Function
End Class
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim p As phoneB
Dim filename As String
Dim lineCount As Integer
filename = TextBox1.Text
**** p.ReadFile(filename)
End Sub
End Class
|