I am currently trying to understand the way that classes work and have a simple programme that will read in the contents of a serial text file and split the contents into separate strings. These will form a class, which I hope eventually to write to a SQL database file. Hopefully by simply copying saving the class the to database via the entity framework. I have not however got that far and have a simple query with a simple example.
The above code works well or at least i think so, however i now need to repeat this numerous times. Whilst I would normally put a loop round it, for simplicity whilst i get it working, I have duplicated the code.
As you would expect, this generates an error that P is already defined. As I intend to repeat this code numerous times, with a string being passed to it, within a loop, I am unsure how to get round this problem.
I am sure it must be simple, but any help would be appreciated.
Code:
Module Module1
Sub Main()
Dim p As Pe1 = New Pe1("TestString")
Console.WriteLine(p.Part1)
Console.WriteLine(p.part2)
Console.ReadLine()
End Sub
End Module
Class Pe1
Public Part1 As String
Public Part2 As String
Public Sub New(ByVal name As String)
MyClass.Part1 = name.Substring(0, 1)
MyClass.Part2 = name.Substring(1, 1)
End Sub
End Class
Code:
Module Module1
Sub Main()
Dim p As Pe1 = New Pe1("TestString")
Console.WriteLine(p.Part1)
Console.WriteLine(p.part2)
Dim p As Pe1 = New Pe1("StringTest1")
Console.WriteLine(p.Part1)
Console.WriteLine(p.part2)
Console.ReadLine()
End Sub
End Module
Class Pe1
Public Part1 As String
Public Part2 As String
Public Sub New(ByVal name As String)
MyClass.Part1 = name.Substring(0, 1)
MyClass.Part2 = name.Substring(1, 1)
End Sub
End Class
I am sure it must be simple, but any help would be appreciated.