我正在编写一个类的程序,我必须从文件中使用getline拉出字符串,然后将其打印到具有一种格式的新文件。我编译得很好,但由于某种原因我的程序崩溃,即使我相信所有的substr调用应该在字符串的范围内。这是我的代码:
Public Shared ReadOnly WinFormsTemplate As String =
<a>
Imports System
Imports System.Windows.Forms
Namespace MyNamespace
Public NotInheritable Class Form1 : Inherits Form
Public Sub New()
Me.StartPosition = FormStartPosition.CenterScreen
End Sub
Private Sub Form1_Shown(ByVal sender As Object, ByVal e As EventArgs) _
Handles MyBase.Shown
MessageBox.Show("VisualBasic.NET WinForms Template.")
End Sub
End Class
End Namespace
</a>.Value
Private Sub CompileSourceCode()
Dim cProvider As CodeDomProvider = New VBCodeProvider
Dim cParams As New CompilerParameters
Dim cResult As CompilerResults
Dim sourceCode As String = WinFormsTemplate
With cParams
.GenerateInMemory = False
.GenerateExecutable = True
.OutputAssembly = Path.Combine(My.Application.Info.DirectoryPath, ".\test.exe")
.CompilerOptions = "/target:winexe"
.ReferencedAssemblies.AddRange({"System.dll", "System.Windows.Forms.dll", "Microsoft.VisualBasic.dll"})
.MainClass = "MyNamespace.Form1"
End With
cResult = cProvider.CompileAssemblyFromSource(cParams, sourceCode)
cProvider.Dispose()
End Sub
我的输入文档是一个带有输入行的文本文档,如
玛丽约翰逊史密斯1953年$ 329,475
史密斯,玛丽约翰逊1953年329,475我必须让我的代码适应类型并将其读入。
感谢您的帮助。