|
Creating a pattern matching system for even a basic "For" loop is very complex, and would be rather more detailed that your example. For example, consider these cases which are legal, but which fail your existing pattern:
for (int i=0;i<9;i++)
for(int i=0;i<10;i++)
for(int i=0;i<9;i+=2)
for(i=1;i<9;i++)
for(int i=0;i<array.Length;i++)
for(int index=0;index<array.Length;index++)
and the following which passes, but which is not a good idea
for(int i=0;j<10;k++)
I suggest you have a look at Extended Backus-Naur form which is a metalanguage for describing languages!
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
gamer1127 wrote: Is that pattern correct?
No. It's perfectly possible to have a statement that reads
for ( ; ; ) . Using a regular expression is not an effective method to accomplish this - a better method would be to use an Abstract Syntax Tree[^].
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Now that you mentioned the Abstract Syntax Tree, I remember that we are required to use what they call a parse tree. is that also the same with Abstract Syntax Tree?
|
|
|
|
|
for(;; ) is also legal
Actually it's something like (no guarantees)
FOR = 'for' '(' {CSL(INIT)}? ';' {BOOL}? ';' {CSL(EXPR)}? ')'
CSL(x) = x (',' x)*
INIT = EXPR | DECL
BOOL = EXPR where the return type is a bool or can be implicitly converted to one, or has operators "true" and "false" (so for example indexing an array of bools is perfectly legal)
EXPR = any expression
DECL = any declaration possibly with initializer
any whitespace between tokens is ignored
float f;
bool[] b = new bool[] { false, true, true, true};
for(f = 3; b[(int)f]; f/=1.2f; ) ;
Is legal. I wouldn't especially recommend it, but it will compile and will do something that could be useful if b weren't a "constant" array.
|
|
|
|
|
For one thing, don't have the for and int in brackets.
You really need to learn more about Regular Expressions. I try to work them up a little at a time, not all at once.
And, as mentioned, this is not the right way to go for this task.
|
|
|
|
|
Is there such a way to do this?
I have a textbox on the GUI. I'm watching the string value from the other class. Whenever the string value is changed, I would like to update the textbox value.
|
|
|
|
|
Good Day Blubbo
Your Textbox has an event "Textchanged" use it, it does exactly what you want.
Hope it helps.
Vuyiswa Maseko,
Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers."
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.somee.com
http://www.vuyiswamaseko.tiyaneProperties.co.za
vuyiswa@its.co.za
http://www.itsabacus.co.za/itsabacus/
|
|
|
|
|
to clarify this... I know how to handle the event by textbox.texthchanged. However, that in class 'b', "string" object is only being processed. So when the string value in class "b" is changed, the class "a" would see that string value in class 'b' is changed, the value in textbox is updated.
|
|
|
|
|
Now that means you have create the events in a class level. The way we approach the design of our application in our Project initial state can lead to this requirement. I think there is a part of your system that was poorly designed. but the workaround this is to create an event and if the value of class changes and you can change the text property of your textbox.
Hope this Helps
Vuyiswa Maseko,
Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers."
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.somee.com
http://www.vuyiswamaseko.tiyaneProperties.co.za
vuyiswa@its.co.za
http://www.itsabacus.co.za/itsabacus/
|
|
|
|
|
I think he's going the other way... Updating the textbox when the string changes.
There are plenty of ways to do this, and people will vehemently disagree on which is best, but here's one possible method:
1) Have your class implement the System.ComponentModel.INotifyPropertyChanged interface, and add the PropertyChanged event as specified in the interface
2) Add a wrapper for it, just to keep things clean:
private void OnPropertyChanged(string propName)
{
if (PropertyChanged != null)
PropertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propName));
}
3) Instead of having the string just be a variable, change it into a property, like so:
private string _myStringValue;
public string MyProperty
{
get { return _myStringValue; }
set { _myStringValue = value; PropertyChanged("MyProperty"); }
}
Then you just listen to the PropertyChanged event, and update the textbox when "MyProperty" comes through.
|
|
|
|
|
so that "PropertyChanged" idea would be placed in which class? (class 'a' or class 'b') as explained in my recent post.
|
|
|
|
|
Class 'b'... The one that contains the string you're monitoring.
|
|
|
|
|
I think I've got this idea...
in class 'a':
Control: TextBox tbText
global:
BillAudit ba = new BillAudit();
constructor:
ba.DisplayOutput= tbText.Text;
in class 'b':
global variable: ReadWriteMessage (this is the string that class 'a' is watching)
public string DisplayOutput
{
get { return ReadWriteMessage; }
set { ReadWriteMessage = value; }
}
get the idea? might work?
modified on Tuesday, July 28, 2009 10:52 AM
|
|
|
|
|
That will set the DisplayOutput value to the textbox text... I thought you wanted it the other way around.
Like I said, implement INotifyPropertyChanged in class 'b', modify the set{} section for DisplayOutput to trigger a PropertyChanged event... Then in class 'a', you can do something like:
ba.PropertyChanged += new PropertyChangedEventHandler(...)
And in the event handler, you just do: tbText.Text = ba.DisplayOutput
Basically, the control flow goes like this:
1) ba.DisplayOutput changes
2) ba.DisplayOutput updates ReadWriteMessage
3) ba.DisplayOutput triggers PropertyChanged
4) Class 'a' sees the PropertyChanged
5) Class 'a' sets tbText.Text to the new value of DisplayOutput
|
|
|
|
|
|
Doesn't work why?
Do you have an exception? An error message from the database? Does the user you've connected to the database as have insert permissions? Is your query string correctly formatted? Is your getconnection() method returning an object correctly? Is there a specific line where the error occurs?
It definitely isn't definatley
|
|
|
|
|
not exception is caught
insert query is
String query = "insert into mydb values('" + textBox1.Text + "','" + textBox2.Text + "')";
This code was posted by me...
|
|
|
|
|
I notice you're using a try block, but I don't see the catch... Are you sure you're not just throwing away the exception?
And if there's really no exception, try setting a breakpoint and seeing exactly what "query" is being set to after that line runs. Maybe your textboxes are blank.
If the query is right, and you're really getting no exception, then it might be a database issue... Try running the exact query (Copy-paste it, so you know it's the same) in an SQL client to see what happens.
EDIT: Oops, responded to the wrong identical reply...
|
|
|
|
|
SqlConnection con = connection();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = query;
cmd.Connection = con;
try
{
con.Open();
cmd.ExecuteNonQuery();
return 1;
}
catch (Exception e)
{
return 0;
}
finally
{
con.Close();
cmd.Dispose();
}
tis is the code its running fine without exception but no data is inserted into the table at last
This code was posted by me...
|
|
|
|
|
Obviously there is no exception that what a try catch does, it enables you to handle the exception, you catch is returning 0 so your not going to see any problem. You may have a problem with your insert statement too, have your tried specifying the columns you are trying to add data to?
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
yes i tried specifying the columns
but no use
any prob with insert query?????
String query = "insert into mydb(username,password) values('" + textBox1.Text + "','" + textBox2.Text + "')";
This code was posted by me...
|
|
|
|
|
try...
INSERT INTO mydb ([username],[password]) VALUES ('" + textBox1.Text + "','" + textBox2.Text + "')
Also...
- Confirm that 'mydb' is a table name and not the name of your database.
- make sure your database columns have the corrent datatype
- look into using parameters
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
What values does this method return? You're catching the exception but not doing anything with it (apart from changing the return value). Assuming you're using VS, set a breakpoint on the line "return 0;" and check to see that the value of 'e' (the exception) is.
It definitely isn't definatley
|
|
|
|
|
i debuggged the code
but no exception is caught
may be prob with insert statemnt???
any prob with insert query?????
String query = "insert into mydb(username,password) values('" + textBox1.Text + "','" + textBox2.Text + "')";
This code was posted by me...
|
|
|
|
|
Try changing your code to this:
SqlConnection con = connection();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = query;
cmd.Connection = con;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
cmd.Dispose();
and see if you get an exception - if the insert has failed, the database should indicate this.
It definitely isn't definatley
|
|
|
|