473,624 Members | 2,165 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Code Run Dynamically From Textbox in Vb.Net

1 New Member
Hello Friends

I run dynamically code from text-box in vb.net
only one text-box txtoutput can be access in dynamically run code

while get input from another text-box compiler show error
"txtbox1 is not declared .it may be inaccessible due to its protection level"


Please help me how to resolve this error

Thanks in Advance
Attached Images
File Type: jpg Run Test Ok.jpg (82.8 KB, 394 views)
File Type: jpg error textbox.jpg (90.0 KB, 281 views)
Attached Files
File Type: txt Dynamic Code.txt (2.5 KB, 298 views)
Nov 27 '19 #1
1 3981
SioSio
272 Contributor
Add textBox1 and txtBox2 to the array of objects representing the arguments passed to the method (UpdateText).
And add textBox1 and txtBox2 to the argument of subroutine UpdateText.

Expand|Select|Wrap|Line Numbers
  1. Public Sub runCode()
  2.         ' Read code from file  
  3.         '  Dim input = My.Computer.FileSystem.ReadAllText("Code1.txt")
  4.         Dim input = TextBox3.Text
  5.         ' Create "code" literal to pass to the compiler.  
  6.         '  
  7.         ' Notice the <% = input % > where the code read from the text file (Code.txt)   
  8.         ' is inserted into the code fragment.  
  9.         Dim code = <code>  
  10.                        Imports System  
  11.                        Imports System.Windows.Forms  
  12.                        Public Class TempClass  
  13.                            Public Sub UpdateText(ByVal txtOutput As TextBox, ByVal txtbox1 As TextBox, ByVal txtbox2 As TextBox)  
  14.                                <%= input %>  
  15.                            End Sub
  16.                        End Class 
  17.                    </code>
  18.         ' Create the VB.NET compiler.  
  19.         Dim vbProv = New VBCodeProvider()
  20.             ' Create parameters to pass to the compiler.  
  21.             Dim vbParams = New CompilerParameters()
  22.             ' Add referenced assemblies.  
  23.             vbParams.ReferencedAssemblies.Add("mscorlib.dll")
  24.             vbParams.ReferencedAssemblies.Add("System.dll")
  25.             vbParams.ReferencedAssemblies.Add("System.Windows.Forms.dll")
  26.             vbParams.GenerateExecutable = False
  27.             ' Ensure we generate an assembly in memory and not as a physical file.  
  28.             vbParams.GenerateInMemory = True
  29.             ' Compile the code and get the compiler results (contains errors, etc.)  
  30.             Dim compResults = vbProv.CompileAssemblyFromSource(vbParams, code.Value)
  31.             ' Check for compile errors  
  32.             If compResults.Errors.Count > 0 Then
  33.                 ' Show each error.  
  34.                 For Each er In compResults.Errors
  35.                     MessageBox.Show(er.ToString())
  36.                 Next
  37.             Else
  38.                 ' Create instance of the temporary compiled class.  
  39.                 Dim obj As Object = compResults.CompiledAssembly.CreateInstance("TempClass")
  40.             ' An array of object that represent the arguments to be passed to our method (UpdateText).  
  41.             Dim args() As Object = {Me.txtoutput,Me.txtbox1,Me.txtbox2}
  42.             ' Execute the method by passing the method name and arguments.  
  43.             Dim t As Type = obj.GetType().InvokeMember("UpdateText", BindingFlags.InvokeMethod, Nothing, obj, args)
  44.         End If
  45.     End Sub
Dec 18 '19 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
1616
by: Senthil Kumar via .NET 247 | last post by:
Hi Frends, I have a "a.aspx.cs" and "b.aspx.cs", can i compile b.aspx.cs from a.aspx.cs? Thanks in advance Best Regards, Senthil kumar Ramachandran -----------------------
0
320
by: Andreas Klemt | last post by:
Hello, I have an ASPX Page with 8 Web User Controls on it. Some are Visible = False and some are Visible = True Now I wrote in each Web User Control code: Sub Page_Load() If Me.Visible Then Me.lblName = "Hello World"
4
2605
by: Andy G | last post by:
I am tring to loop through a dataset to find records that exist. If the record exists then make the corresponding image visible. So I try to take the row value and concatenate it onto a string ("imgSession"), so the resulting control ID name will be imgSessionX. Where X could be a number corresponding to the ID of the image. I need help with the logic. Dim row As DataRow Dim myImage As Image
4
2235
by: Jaime Stuardo | last post by:
Hi all... I need to add some JavaScript code that is dynamically generated to some point of the page. Currently I'm using ClientScript.RegisterStartupScript(GetType(), "menu", "<script type=\"text/javascript\">" + oMenu.BuildMenu(true, true, true) + "</script>"); But the script is added to the end of the page, but I need it to be added at
2
1309
by: gn | last post by:
I have a simple app that asks a user to enter text in a multiline textbox, (runat server) then submit, after submitting this text is then assigned to a variable as a string. This works fine with regular text like: This is a test However if I try to enter HTML code in the textbox, the submit onclick event doesn't even fire. It doesn't have to be complex HTML code, even: <div align="left"> will cause it to fail, changing it to: div...
6
4413
by: salo | last post by:
Can anybody say me for writing javascript code for textbox key press event such a way that it should allow only alphabets,dot and spaces
3
1472
by: kj | last post by:
I've tried a bazillion ways to code dynamically generated methods, to no avail. The following snippet is a very simplified (and artificial) demo of the problem I'm running into, featuring my latest attempt at this. The idea here is to use __getattr__ to trap any attempt to invoke a nonexistent method, have it return a generic handler called _auto which creates the new method dynamically, invokes it, and "installs" it in the class, so...
15
8190
by: =?Utf-8?B?VG9tIENvcmNvcmFu?= | last post by:
I've been led to believe by several articles, particularly Eric Gunnerson's C# Calling Code Dynamically, that calling a method dynamically through Reflection was much slower than through a Delegate. My testing showed that actually it was six times faster: 0.5 seconds for 100,000 iterations versus 3.1 seconds. Can anyone explain why? Something in the way I coded it? I'd appreciate any insights. Here's the code (in a Windows Form...
0
1377
by: =?Utf-8?B?amVmZmVyeQ==?= | last post by:
i need help compiling code dynamically it may involve some reflection so if any one is any good in that field or compiling code this would be a great time to show me what you know. by the way my last weird but serious combo box error i solved my self it was just a simple recompile and some simple code changes and it worked. i will put a link to the code for compiling dynamially here: <a href =...
0
8234
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
8335
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8474
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7158
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6110
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4079
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4174
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2605
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1784
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.