Click here to Skip to main content
15,905,414 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hi there, I would like to find out how I can make this work... I have a Text file containing two classes, but the compiler keeps on failing... A bit frustrated now... Been battling for about a week... Please help.

IN TEXT FILE... If you would like to see the code I can send it via email
1. Public Class Form1
2. Public Class Settings

This is how far I got

Private Function Compile(ByVal output As String) As Boolean
Dim result As Boolean

Dim vbcode As VBCodeProvider = New VBCodeProvider
Dim compiler As ICodeCompiler = vbcode.CreateCompiler()
Dim compargs As New CompilerParameters()
compargs.GenerateInMemory = False
Dim references() As String = {"System.Windows.Forms.dll", "System.Drawing.dll", "Microsoft.VisualBasic.dll", "System.dll"}
compargs.CompilerOptions = "/target:winexe /m:Form1 /win32icon:" & "C:\install.ico"
compargs.GenerateExecutable = True
compargs.IncludeDebugInformation = False
compargs.OutputAssembly = output
compargs.TreatWarningsAsErrors = False

compargs.ReferencedAssemblies.AddRange(references)

Dim res As CompilerResults
res = compiler.CompileAssemblyFromFile(compargs, "C:\TDIR\prg.txt")

If res.Errors.Count > 0 Then
result = False
Else
result = True
End If
Return result
End Function
Posted
Comments
Sergey Alexandrovich Kryukov 8-Nov-13 2:24am    
Could I see the simplest possible failing sample of input code (the one you try to compile)? Doesn't it try to use any assemblies which you did not reference? Have you been able to compile anything at all, even the rudimentary sample? What is the compilation error information? Normally, it should give you all the detail.
—SA
AJ_Smit 8-Nov-13 5:25am    
Hi Sergey

This is the source in the "C:\prg.txt" file ...

Imports System
Imports System.Xml
Imports System.Drawing
Imports System.Windows.Forms

Public Class Form1
Inherits Form
Dim WithEvents myButton As Button

Public Sub New()

myButton = New Button()
myButton.Text = "Auto Generated"
myButton.Top = 70
myButton.Left = 70

Me.controls.add(myButton)

End Sub

Private Sub myButtonClick(ByVal sender As Object, ByVal e As EventArgs) _
Handles myButton.Click
MessageBox.Show("Hello World!")
End Sub

End Class

Public Class Settings
Dim m_MyButtonText As String = ""

Public Property MyButtonText() As String
Get
Return m_MyButtonText()
Set (Byval value As String)
m_MyButtonText = value
End Get
End Property
End Class

If I compile the file containing the source without the Settings Class it compiles correctly.

And these are the errors I get...

Line 2, Col 0: Error BC40056 - Namespace or type specified in the Imports 'Settings' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases.
Line 4, Col 0: Error BC40056 - Namespace or type specified in the Imports 'System.Xml' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases.
Line 54, Col 0: Error BC42025 - Access of shared member, constant member, enum member or nested type through an instance; qualifying expression will not be evaluated.
AJ_Smit 8-Nov-13 5:39am    
I have played around with the original files and did this...

Imports Settings
Imports System.Drawing
Imports System.Windows.Forms

Public Class Form1
Inherits Form
Dim WithEvents myButton As Button

Public Sub New()

myButton = New Button()
myButton.Text = "Auto Generated"
myButton.Top = 70
myButton.Left = 70

Me.controls.add(myButton)

End Sub

Private Sub myButtonClick(ByVal sender As Object, ByVal e As EventArgs) _
Handles myButton.Click
MessageBox.Show("Hello World!")
End Sub

End Class

<serializable> _
Public Class Settings

Dim m_MyButtonText As String

Public Sub New()
End Sub

Public Readonly Property MyButtonText() As String
Get
Return m_MyButtonText()
End Get
End Property
End Class

I managed to get rid of all the errors but seem to be getting this now...

Line 36, Col 0: Error BC30455 - Argument not specified for parameter 'index' of 'Public ReadOnly Default Property Chars(index As Integer) As Char'.
Sergey Alexandrovich Kryukov 8-Nov-13 10:28am    
Actually I was about to advise you to take a deep breath, calm down and get to thinking, all that stuff; yes, really, because it was apparent that you basically know the topic and might have missed some little detail. I'm glad you are done now.

Just one thing: next time, just put your code in proper place: the body of your question, using "Improve question". It does not read well in a comment, and cannot be formatted. You need to format code by sandwiching <pre lang="vb"> ...your code... </pre> (there is a menu item for that under the text area)...

—SA
AJ_Smit 10-Nov-13 9:00am    
Thank you Sergey I will do so next time.... However I am stuck again... I am trying to add a folder with all sub-folders as embedded resources to the compiler or is it not possible?.... And believe it or not I am again scratching my head LOL... Well the app has come a long way and I am thinking of posting it in an article for other people that needs a little boost.

 
Share this answer
 
Comments
AJ_Smit 8-Nov-13 5:30am    
Thanks Mehdi, but that was where I started initially... I found useful tips regarding a C# program but as I converted the app to vb.net it gave me several errors one being as soon as I try serializing my settings.xml file, The app lets me know that it cannot locate the file or assembly "MyNamespace.XMLSerializer... Hence I had to go a different route, that is working fine now by the way, but as I replied to Sergey, The issue is I am not able to compile two classes that are typed in the same text file.
After breathing heavily I decided to calm down... Watched a bit of cricket and then got to thinking
I changed the whole text file check the code below... Behold...IT WORKS! I am soooo stoked!


Imports Settings
Imports System
Imports System.IO
Imports System.Text
Imports System.Drawing
Imports System.Windows.Forms
Imports System.ComponentModel
Imports System.CodeDom.Compiler
Imports System.Collections.Generic
Imports System.Runtime.Serialization.Formatters.Binary

Public Class Form1
Inherits Form
Dim WithEvents myButton As Button

Public Sub New()

myButton = New Button()
dim [set] as New Settings()
myButton.Text = [set].MText
myButton.Top = 70
myButton.Left = 70

Me.controls.add(myButton)

End Sub

Private Sub myButtonClick(ByVal sender As Object, ByVal e As EventArgs) _
Handles myButton.Click
MessageBox.Show("Hello World!")
End Sub

End Class

<serializable> _
Public Class Settings

Public Sub New()
End Sub

Public m_text as String = "BOOOOO"

Public Property MText() As String
Get
return m_text
End Get
Set(value As String)
m_text = value
End Set
End Property

End Class
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900