|
And can also include the little-known , (COMMA) operator.
|
|
|
|
|
I thought that was only in C++? I don't know for sure though... I am at home now.
Cheers,
Vikram. (Proud to have finally cracked a CCC!) Recent activities:
TV series: Friends, season 10
Books: Fooled by Randomness, by Nassim Nicholas Taleb. Carpe Diem.
|
|
|
|
|
It seems C# limits it somehow, and I'm reading the spec now to see why.
"
8.8.3 The for statement
The for statement evaluates a sequence of initialization expressions and then, while a condition is true, repeatedly executes an embedded statement and evaluates a sequence of iteration expressions.
for-statement:
for ( for-initializer ; for-condition ; for-iterator ) embedded-statement
"
for ( int i = 0 ; i < 10 ; i++ , i++ )
{
System.Console.WriteLine ( i ) ;
}
or
int i ;
for ( i = 0 , i++ ; i < 10 ; i++ , i++ )
{
System.Console.WriteLine ( i ) ;
}
The comma operator is valid in the for-iterator, but not in the for-initializer and for-condition (they are allowed there in C), this may be an oversight.
I may ask on an MSDN forum later.
|
|
|
|
|
Yeah, you're right. Turns out you can even do multiple declarations:
for ( int i = 0, j = 4 ; i < 10; i++ , i++, j++ )
{
System.Console.WriteLine ( i + " " + j) ;
}
Another arcane fact about C# that I'll probably never use in my life
Cheers,
Vikram. (Proud to have finally cracked a CCC!) Recent activities:
TV series: Friends, season 10
Books: Fooled by Randomness, by Nassim Nicholas Taleb. Carpe Diem.
|
|
|
|
|
Yeah, obfuscation.
I checked and it's been like that since v1.1
|
|
|
|
|
Maybe you're right. I see no mention of the comma operator in either C# spec.
C-74 (Dennis Ritchey)
"
7.15 expression , expression
A pair of expressions separated by a comma is evaluated lefttoright
and the value of the left expression is discarded.
The type and value of the result are the type and value of the right operand. This operator groups lefttoright.
It should be avoided in situations where comma is given a special meaning, for example in actual arguments
to function calls (§7.1.6) and lists of initializers (§10.2).
"
C-99 (ANSI)
"
The left operand of a comma operator is evaluated as a void expression; there is a
sequence point after its evaluation. Then the right operand is evaluated; the result has its
type and value.95) If an attempt is made to modify the result of a comma operator or to
access it after the next sequence point, the behavior is undefined.
"
But C# has no comma operator, the effect is provided by:
C# (ECMA)
"
statement-expression:
invocation-expression
object-creation-expression
assignment
post-increment-expression
post-decrement-expression
pre-increment-expression
pre-decrement-expression
statement-expression-list:
statement-expression
statement-expression-list , statement-expression
"
And that's not allowed in the for-condition.
|
|
|
|
|
Ah...ok...thanks about that....
Now, my other problem is how to use the symbols '^', '?', '*', \s, \t, \n to include in the pattern. i already read how they work. its just that i don't know where to put them to make the pattern correct.
for example:
@"([for]\s*)";
is the location of the \s* correct? if not, where should i put it? Can anyone give me suggestions on where to put those things in the pattern...
|
|
|
|
|
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...
|
|
|
|