Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > .NET Framework > Forum > C# WinApp อยากทราบว่า ถ้าจะนำ string หรือ ข้อความ มาใช้เป็นโค้ดแล้ว รัน ต้องเขียนโค้ดยังไงครับ



 

C# WinApp อยากทราบว่า ถ้าจะนำ string หรือ ข้อความ มาใช้เป็นโค้ดแล้ว รัน ต้องเขียนโค้ดยังไงครับ

 



Topic : 120042



โพสกระทู้ ( 4,436 )
บทความ ( 23 )



สถานะออฟไลน์
Facebook



อย่างผมมีข้อความใน text file ว่า MessageBox.Show("TOR@Chemistry 5555")

แล้วผมอยากจะ รัน ผมต้องเขียนยังไงครับ

ขอโทษนะครับที่อาจจะตั้งคำถามแบบงงๆๆ



Tag : .NET, Win (Windows App), C#, Windows







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2015-11-19 14:58:20 By : lamaka.tor View : 811 Reply : 7
 

 

No. 1



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

Code (C#)
Type thisType = this.GetType();
MethodInfo theMethod = thisType.GetMethod(TheCommandString);
theMethod.Invoke(this, userParameters);


ใช่ตัวนี้หรือเปล่าครับ






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-11-19 15:03:22 By : mr.win
 


 

No. 2

Guest


คิดว่าไม่สามารถจะสั่งรันได้จากการอ่านนะครับ
แต่สามารถเขียนโปรแกรม อ่าน Text File แล้วค่อยรัน อันนี้ได้ครับ

ประมาณว่า Text File มีคำว่า
TOR@Chemistry 5555

string[] lines = System.IO.File.ReadAllLines(@"D:\TOR.txt");
string str;
str = lines[0];

MessageBox.Show(str);

ประมาณนี้ครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-11-19 15:06:41 By : บัญดิษฐ
 

 

No. 3



โพสกระทู้ ( 4,436 )
บทความ ( 23 )



สถานะออฟไลน์
Facebook

คือผมเขียนโค้ดสำหรับ รันโค้ดแบบนี้ครับ

Code (C#)
void SetVoid()
        {
            string str = "str = ";
            string s = " ";
            
            int num = 3;
            s += "void SetData" + num + "()\n { \n count += (int)Math.Pow(Program.symbol.Length," + num + ");  \n";
            s += "progressBar1.Invoke(new Action(() => { progressBar1.Maximum = count; })); \n string str" + num + " = string.Empty; \n";

            str = "str" + num + " = ";
            for (int i = 1; i < num + 1; i++)
            {
                s += "foreach (string s" + i + " in Program.symbol){\n";
                str += ((str == "str" + num + " = ") ? " s" + i : "+ s" + i);
            }

            s += "\n  try {  \n" + str + "; \n  Program.Insert(" + Convert.ToChar(34) + num + Convert.ToChar(34) + ", str" + num + "); \n num++; ";
            s += "\n  this.Invoke(new Action(() => { this.Text = str" + num + "; })); \n  double t = DateTime.Now.TimeOfDay.TotalSeconds - startCounter; \n  double strt = (double)((count - num) * t / num);";

            s += "\n  str = str" + num + ";  new System.Threading.Thread(SetDisplay).Start();";

            s += "\n   if (num <= progressBar1.Maximum){ \n this.progressBar1.Invoke(new Action(() => { this.progressBar1.Value = num; }));\n} \n } \n catch { };\n";

            for (int i = 1; i < num + 1; i++)
            {
                s += "}";
            }
            s += "\n  this.Invoke(new Action(() => { this.Text = " + Convert.ToChar(34) + "Complete...." + Convert.ToChar(34) + "; })); \n}";
            richTextBox1.Text +="\n  \n"  + s;
        }


จากโค้ดด้านบนพอรันแล้ว จะได้

Code (C#)
void SetData3()
        {
            count += (int)Math.Pow(Program.symbol.Length, 3);
            progressBar1.Invoke(new Action(() => { progressBar1.Maximum = count; }));
            string str3 = string.Empty;
            foreach (string s1 in Program.symbol)
            {
                foreach (string s2 in Program.symbol)
                {
                    foreach (string s3 in Program.symbol)
                    {

                        try
                        {
                            str3 = s1 + s2 + s3;
                            Program.Insert("3", str3);
                            num++;
                            this.Invoke(new Action(() => { this.Text = str3; }));
                            double t = DateTime.Now.TimeOfDay.TotalSeconds - startCounter;
                            double strt = (double)((count - num) * t / num);
                            str = str3; new System.Threading.Thread(SetDisplay).Start();
                            if (num <= progressBar1.Maximum)
                            {
                                this.progressBar1.Invoke(new Action(() => { this.progressBar1.Value = num; }));
                            }
                        }
                        catch { };
                    }
                }
            }
            this.Invoke(new Action(() => { this.Text = "Complete...."; }));
        }


แต่ผมคิดว่ามันน่าจะมีทางที่ สร้างเสร็จก็รัน SetData3() ได้เลย แบบนี้ครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-11-19 15:13:48 By : lamaka.tor
 


 

No. 4

Guest


555+++ ผมนี้หลงประเด็นไปเลย งั้นลองค้นหาดูเรื่อง Compiling C# Code at Runtime ดูนะครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-11-19 15:28:27 By : บัญดิษฐ
 


 

No. 5

Guest


ผมยังไม่เคยลองนะ ลองดูตามเว็บนี้ดูนะครับ
แค่ลากว่างและเขียนโด้ดเพิ่มนี่ก็เอาการอยู่แล้ว จะให้มาเขียนโค้ดสดแล้ว Compiling Runtime
ผมว่าหนักเอาการอยู่ 555+++ ผมว่าถ้าแยกเป็น module น่าจะดีกว่านะครับผม
https://west-wind.com/presentations/DynamicCode/DynamicCode.htm
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-11-19 16:03:11 By : บัญดิษฐ
 


 

No. 6



โพสกระทู้ ( 4,436 )
บทความ ( 23 )



สถานะออฟไลน์
Facebook

ผมลองหัดใช้ตาม

http://www.codeproject.com/Tips/715891/Compiling-Csharp-Code-at-Runtime

อยู่ครับ
ที่เหลือก็ต้องลองเอามาปรับใช้ดู

ขอถามอีกอย่างครับ

Code (C#)
public static string[] symbol = new string[]{"!","%","&","-",".","/",@"\","_","0","1","2","3","4","5","6","7","8","9","@","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};
void SetData10()
        {
            count += (int)Math.Pow(Program.symbol.Length, 10);
            progressBar1.Invoke(new Action(() => { progressBar1.Maximum = count; }));
            string str10 = string.Empty;
            foreach (string s1 in Program.symbol)
            {
                foreach (string s2 in Program.symbol)
                {
                    foreach (string s3 in Program.symbol)
                    {
                        foreach (string s4 in Program.symbol)
                        {
                            foreach (string s5 in Program.symbol)
                            {
                                foreach (string s6 in Program.symbol)
                                {
                                    foreach (string s7 in Program.symbol)
                                    {
                                        foreach (string s8 in Program.symbol)
                                        {
                                            foreach (string s9 in Program.symbol)
                                            {
                                                foreach (string s10 in Program.symbol)
                                                {

                                                    try
                                                    {
                                                        str10 = s1 + s2 + s3 + s4 + s5 + s6 + s7 + s8 + s9 + s10;
                                                        Program.Insert("10", str10);
                                                        num++;
                                                        this.Invoke(new Action(() => { this.Text = str10; }));
                                                        double t = DateTime.Now.TimeOfDay.TotalSeconds - startCounter;
                                                        double strt = (double)((count - num) * t / num);
                                                        str = str10; new System.Threading.Thread(SetDisplay).Start();
                                                        if (num <= progressBar1.Maximum)
                                                        {
                                                            this.progressBar1.Invoke(new Action(() => { this.progressBar1.Value = num; }));
                                                        }
                                                    }
                                                    catch { }; System.Threading.Thread.Sleep(100);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            this.Invoke(new Action(() => { this.Text = "Complete...."; }));
        }


จากโค๊ดนี้ถ้าใช้ Thread เดียวทำงานมันช้ามากครับ

ถ้าจะแบ่งออกมาซัก 50 Thread จะแบ่ง for ยังไงครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-11-19 16:43:51 By : lamaka.tor
 


 

No. 7



โพสกระทู้ ( 4,436 )
บทความ ( 23 )



สถานะออฟไลน์
Facebook

ดัน ๆๆๆ
ถ้าจะแบ่งออกมาซัก 50 Thread จะแบ่ง for ยังไงครับ

Code (C#)
public static string[] symbol = new string[]{"!","%","&","-",".","/",@"\","_","0","1","2","3","4","5","6","7","8","9","@","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};
void SetData10()
        {
            count += (int)Math.Pow(Program.symbol.Length, 10);
            progressBar1.Invoke(new Action(() => { progressBar1.Maximum = count; }));
            string str10 = string.Empty;
            foreach (string s1 in Program.symbol)
            {
                foreach (string s2 in Program.symbol)
                {
                    foreach (string s3 in Program.symbol)
                    {
                        foreach (string s4 in Program.symbol)
                        {
                            foreach (string s5 in Program.symbol)
                            {
                                foreach (string s6 in Program.symbol)
                                {
                                    foreach (string s7 in Program.symbol)
                                    {
                                        foreach (string s8 in Program.symbol)
                                        {
                                            foreach (string s9 in Program.symbol)
                                            {
                                                foreach (string s10 in Program.symbol)
                                                {

                                                    try
                                                    {
                                                        str10 = s1 + s2 + s3 + s4 + s5 + s6 + s7 + s8 + s9 + s10;
                                                        Program.Insert("10", str10);
                                                        num++;
                                                        this.Invoke(new Action(() => { this.Text = str10; }));
                                                        double t = DateTime.Now.TimeOfDay.TotalSeconds - startCounter;
                                                        double strt = (double)((count - num) * t / num);
                                                        str = str10; new System.Threading.Thread(SetDisplay).Start();
                                                        if (num <= progressBar1.Maximum)
                                                        {
                                                            this.progressBar1.Invoke(new Action(() => { this.progressBar1.Value = num; }));
                                                        }
                                                    }
                                                    catch { }; System.Threading.Thread.Sleep(100);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            this.Invoke(new Action(() => { this.Text = "Complete...."; }));
        }


แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-11-23 10:33:37 By : lamaka.tor
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : C# WinApp อยากทราบว่า ถ้าจะนำ string หรือ ข้อความ มาใช้เป็นโค้ดแล้ว รัน ต้องเขียนโค้ดยังไงครับ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 05
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่