I m trying to load a txt file into an MsAccess table
At the same time i want a progreess bar in the main form to appear showing the progress of loading. I ve made the following steps
I created a main form named "form1" where the hole procedure will appear
I created a class named "TextFromFile"
This class uses a method named "com_traffic02" from an other class that cuts the lines of the text file into fields and loads them into the Table.
I want to set the values of Minimum, Maximum and step of my progress bar in Form1, different each time from within the class TextFromFile but this could not be done, because each time i m trying to refer to Form1 or other controls of Form1 from within the class TextFromFile i get the message
"object reference not set to an instance of an object"
Any suggestions, please?
Bellow is the code (class TextFromFile)
Public Class TextFromFile
Inherits Form1
Protected txtfile As String
Public Shared Sub Main(ByVal txtfile As String)
If Not File.Exists(txtfile) Then
Console.WriteLine("{0} does not exist.", txtfile)
Return
End If
' Try
Dim sr As StreamReader = File.OpenText(txtfile)
Dim files As Long
Dim f1 As Form1
Dim bar1size As Integer
files = sr.BaseStream.Length
bar1size = CInt(files / 230)
'''' HERE COMES THE ERROR '''
f1.PBar1.Maximum = bar1size
f1.PBar1.Minimum = 1
f1.PBar1.Value = 1
f1.PBar1.Step = 5
Dim input As String
input = sr.ReadLine()
While Not input Is Nothing
' Dim readheader As header
line.com_traffic02(input)
f1.PBar1.PerformStep()
'Console.WriteLine(input)
input = sr.ReadLine()
End While
Console.WriteLine("The end of the stream has been reached.")
sr.Close()
' Catch er As Exception
' MsgBox(er.Message, MsgBoxStyle.Critical, "General Error")
'End Try
End Sub
End Class
At the same time i want a progreess bar in the main form to appear showing the progress of loading. I ve made the following steps
I created a main form named "form1" where the hole procedure will appear
I created a class named "TextFromFile"
This class uses a method named "com_traffic02" from an other class that cuts the lines of the text file into fields and loads them into the Table.
I want to set the values of Minimum, Maximum and step of my progress bar in Form1, different each time from within the class TextFromFile but this could not be done, because each time i m trying to refer to Form1 or other controls of Form1 from within the class TextFromFile i get the message
"object reference not set to an instance of an object"
Any suggestions, please?
Bellow is the code (class TextFromFile)
Public Class TextFromFile
Inherits Form1
Protected txtfile As String
Public Shared Sub Main(ByVal txtfile As String)
If Not File.Exists(txtfile) Then
Console.WriteLine("{0} does not exist.", txtfile)
Return
End If
' Try
Dim sr As StreamReader = File.OpenText(txtfile)
Dim files As Long
Dim f1 As Form1
Dim bar1size As Integer
files = sr.BaseStream.Length
bar1size = CInt(files / 230)
'''' HERE COMES THE ERROR '''
f1.PBar1.Maximum = bar1size
f1.PBar1.Minimum = 1
f1.PBar1.Value = 1
f1.PBar1.Step = 5
Dim input As String
input = sr.ReadLine()
While Not input Is Nothing
' Dim readheader As header
line.com_traffic02(input)
f1.PBar1.PerformStep()
'Console.WriteLine(input)
input = sr.ReadLine()
End While
Console.WriteLine("The end of the stream has been reached.")
sr.Close()
' Catch er As Exception
' MsgBox(er.Message, MsgBoxStyle.Critical, "General Error")
'End Try
End Sub
End Class