|
Henry Minute wrote: and then implementing the IRaiseItemChangedEvents interface, but it's one heck of a lot of work, and BindingSource does it all already.
That's why I opted for the ready solution of the list box, before I encountered that snag.
Henry Minute wrote: The problem is that the DataSource property of the ListBox is probably implemented like this:
I don't think so, the reason being I actually tried setting the DataSource to null and then resetting it the List<t> I had, and it still wouldn't work.
If the post was helpful, please vote, eh!
Current activities:
Book: Devils by Fyodor Dostoyevsky
Project: Hospital Automation, final stage
Learning: Image analysis, LINQ
Now and forever, defiant to the end.
What is Multiple Sclerosis[ ^]?
|
|
|
|
|
Mustafa Ismail Mustafa wrote: I don't think so, the reason being I actually tried setting the DataSource to null and then resetting it the List I had, and it still wouldn't work.
Interesting!!
I'm wrong again. In that case I have no clue. Computers, hey.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Henry Minute wrote: I'm wrong again.
Don't sweat it, I'm wrong more often than not
Henry Minute wrote: Computers, hey. Laugh
Yep.
Sometimes, I wonder why I didn't listen to my mom and turned out a surgeon or carried on to study Organic Chemistry as a major!
If the post was helpful, please vote, eh!
Current activities:
Book: Devils by Fyodor Dostoyevsky
Project: Hospital Automation, final stage
Learning: Image analysis, LINQ
Now and forever, defiant to the end.
What is Multiple Sclerosis[ ^]?
|
|
|
|
|
Works like clock-work
Mucho thank you!
But WHY DID that strange occurrence happen?
If the post was helpful, please vote, eh!
Current activities:
Book: Devils by Fyodor Dostoyevsky
Project: Hospital Automation, final stage
Learning: Image analysis, LINQ
Now and forever, defiant to the end.
What is Multiple Sclerosis[ ^]?
|
|
|
|
|
See my reply to your previous message, sorry about the formatting, I bollixed up the HTML Tags Checkboxes.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Can someone help me on how to match an entered string to a regex pattern?
I'm creating a program that would parse a for loop statement and check if the entered for loop statement is correct or not. So far I've been able to split that statement and pass it into an array. I then pass it again to a string variable after i put the splitted statement into that array. My only problem is how to check if the entered for loop statement is correct? I've been trying lots of pattern matching codes from the web but none of them have worked so far. The deadline will be next week but until now there hasn't been any progress.
My pattern isn't done yet too because i can't make a pattern that would match the >=, <= relational operators and the '--', '++' unary operators.
To make things easier, this is my code:
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections;
namespace MachineProblem
{
class Program
{
static void Main(string[] args)
{
string passedStatement = " ";
string[] stringHolder = null;
GetStatement(stringHolder, ref passedStatement);
SyntaxVerifier(stringHolder, ref passedStatement);
Console.Read();
}
public static void GetStatement(string[] arrayBox, ref string statement)
{
Console.WriteLine("Write an example of a for loop statement: ");
statement = Console.ReadLine();
foreach (string token in Tokenizer(arrayBox, statement))
{
}
}
public static string[] Tokenizer(string[] strBox, string tokenizeStatement)
{
strBox = null;
Regex strTokenizer = new Regex(@"([\;\(\)\ \\])");
for (int i = 0; i < strTokenizer.Split(tokenizeStatement).Length; i++)
{
strBox = strTokenizer.Split(tokenizeStatement);
}
return strBox;
}
public static void SyntaxVerifier(string[] arrayString, ref string passedsyntax)
{
string pattern = @"(for\s*[\(]\s*int\s*[a-zA-Z\d]*\s*=\s*[\d]*\s*;\s*[a-zA-Z\d]*\s*[\<\>]\s*[\d]\s*;\s*[a-zA-z\d]*\s*[\-(1)])";
string stringStatement = "for(int x=0; x<5; x++) Console.WriteLine(\"Hello\")";
foreach (string words in arrayString)
{
stringStatement = words;
stringStatement.Trim();
}
}
}
}
Thanks in Advance for those who could help
|
|
|
|
|
I have not tried to parse a for loop before but if I was to do it I would start by extracting the data between the for loops brackets (ensure you get the matching close bracket).
Then I would split it into three parts (using string.Split method with a semi-colon)
Then attempt to parse each part individually...
There also seems to be a number of things you may have overlooked such as; int is not the only valid datatype, the variable may be declared elsewhere thus meaning no datatype should be present, variable names can contain more than leters, there are more evaluation options than > and < etc...
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
I forgot to include that my parser program is created to parse just a simple for loop statement. it doesn't have to cover all of the possible examples of a for loop statement. We were instructed to only have one line statement after the for loop syntax meaning we don't have to include the open and close curly brackets.
example:
for(int abc989 = 10; abc989 >= 0; abc989--) Console.WriteLine("*");
or
for(int abc989 = 0; abc989 < 50; abc989++) Console.WriteLine("HelloWorld\n");
Those example are the only ones we can do at the moment since we're not in compiler design yet. We were given this kind of machine problem to apply one data structure which is a parse tree.
|
|
|
|
|
gamer1127 wrote: We were given this kind of machine problem to apply one data structure which is a parse tree.
Then why don't you use a parse tree, rather than try to force a regex to do the work?
forLoop
|--------------|--------------------------------------------------|
"for" LoopConstruct Statement
|-------|------|-----|--------|------|------|
"(" Init ";" EndCond ";" Step ")"
etc.
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
|
|
|
|
|
I agree - RE's are really the wrong tool for this job, unless your lecturer/tutor is insisting you use them (although I'd be wondering why).
You say you're "not into compiler design yet" on your course, but I presume it's coming up eventually, and when it does you don't want to start off down the wrong road.
There are three kinds of people in the world - those who can count and those who can't...
|
|
|
|
|
Do you know any good source that i can read about parse tree?
|
|
|
|
|
Google
Regards
David R
---------------------------------------------------------------
"Every program eventually becomes rococo, and then rubble." - Alan Perlis
|
|
|
|
|
hehehe....i'm doing it right now...but i can't determine if that source is good or not...
|
|
|
|
|
http://en.wikipedia.org/wiki/Parsing[^]
THis looks useful - got by googling 'parse tree compiler'
Regards
David R
---------------------------------------------------------------
"Every program eventually becomes rococo, and then rubble." - Alan Perlis
|
|
|
|
|
I am implementing a SerializationBinder.
In public override Type BindToType(string assemblyName, string typeName) I am passed type name such as:
<code>System.Collections.Generic.Dictionary`2[[System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]</code>
Which I like to decompose in:
typename: System.Collections.Generic.Dictionary
2 generic type argument
assembly: mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
typename: System.Int32
assembly: mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
typename: System.String
Is there some utility class which will do that for me?
Or an article with some parser?
Any link?
A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station....
_________________________________________________________
My programs never have bugs, they just develop random features.
|
|
|
|
|
Well, I'm a complete beginer with Irony ( Irony[^] ),
so I don't know if I would manage to do something with it.
Nonetheless it is so easy to use that I was able to guess / write this following type name parser in 90 minutes...
[Language("Type FullName", "1.0", "serialization type name")]
public class TypeNameGrammar : Grammar
{
public TypeNameGrammar()
: base(true)
{
var typeName = new NonTerminal("TypeName");
this.Root = typeName;
var ident = new IdentifierTerminal("identifier");
var number = new NumberLiteral("number", NumberFlags.IntOnly);
var token = new IdentifierTerminal("token", "0123456789", "");
var optionalGenericType = new NonTerminal("GenericPart");
var optionalAssembly = new NonTerminal("Assembly");
var typeParameters = new NonTerminal("TypeParameters");
var fullName = new NonTerminal("fullname");
var aversion = new NonTerminal("aversion");
var acult = new NonTerminal("acult");
var atok = new NonTerminal("atok");
typeName.Rule = fullName + optionalGenericType + optionalAssembly;
optionalGenericType.Rule =
Empty
| Symbol("`") + number + "[" + typeParameters + "]";
optionalAssembly.Rule =
Empty
| Symbol(",") + fullName + "," + aversion + "," + acult + "," + atok;
typeParameters.Rule =
typeParameters + "," + "[" + typeName + "]"
| Symbol("[") + typeName + "]";
fullName.Rule =
fullName + "." + ident
| ident;
aversion.Rule = Symbol("Version=") + number + "." + number + "." + number + "." + number;
acult.Rule = Symbol("Culture=") + ident;
atok.Rule = Symbol("PublicKeyToken=") + token;
}
}
A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station....
_________________________________________________________
My programs never have bugs, they just develop random features.
|
|
|
|
|
A better Irony grammar yet
[Language("Type FullName", "1.0", "Generic type name")]
class TypeNameGrammar : Grammar
{
public TypeNameGrammar()
: base(true)
{
var typeName = new NonTerminal("TypeName");
this.Root = typeName;
var ident = new FreeTextToChars("identifier", ",[]` ");
var aname = new FreeTextToChars("AssemblyName", "]");
var number = new NumberLiteral("number", NumberFlags.IntOnly);
var optionalGenericType = new NonTerminal("GenericPart");
var optionalAssembly = new NonTerminal("Assembly");
var typeParameters = new NonTerminal("TypeParameters");
typeName.Rule = ident + optionalGenericType + optionalAssembly;
optionalGenericType.Rule =
Empty
| Symbol("`") + number + "[" + typeParameters + "]";
optionalAssembly.Rule =
Empty
| Symbol(",") + aname;
typeParameters.Rule =
typeParameters + "," + "[" + typeName + "]"
| Symbol("[") + typeName + "]";
this.RegisterPunctuation("[", "]", "`", ",");
}
class FreeTextToChars : Terminal
{
private char[] stopChars;
public FreeTextToChars(string name, string chars)
: base(name, TokenCategory.Literal)
{
stopChars = chars.ToCharArray();
}
public override Token TryMatch(CompilerContext context, ISourceStream source)
{
var next = source.Text.IndexOfAny(stopChars, source.PreviewPosition);
if (next == -1)
{
string token = source.Text.Substring(source.PreviewPosition);
source.PreviewPosition = source.Text.Length;
return source.CreateToken(this, token);
}
else
{
string token = source.Text.Substring(source.PreviewPosition, next - source.PreviewPosition);
source.PreviewPosition = next;
return source.CreateToken(this, token);
}
}
}
}
A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station....
_________________________________________________________
My programs never have bugs, they just develop random features.
|
|
|
|
|
Hi all,
In my solution I already have lots of business object unit tests. However I also want to test the web service layer. So to do this I've added another project to the solution and added a project reference to the web service layer. So now I can see all the web methods.
The problem I have is that when I want to go to the database my method GetDAOFactory() always returns null. I think this is because the global file inherits the HttpApplication class. E.G.
Try and get the customer or create a new one
1)
private Customer GetCustomerInSession()
{
Customer customer = Session[PropertyCustomer] as Customer;
if (customer == null)
{
Session[PropertyCustomer] = customer = new Customer(GetDAOFactory());
}
return customer;
}
Get the DAO Factory this returns null
2)
private IDAOFactory GetDAOFactory()
{
return Application[Global.DAOFactorySetting] as IDAOFactory;
}
I think the reason is because global inherits HttpApplication
3)
public class Global : HttpApplication
{
protected void Application_Start(object sender, EventArgs e)
{
// create data access implementation
string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["DevBox"].ConnectionString;
Application[DAOFactorySetting] = new ADODAOFactory(ProviderType.SqlServer, connectionString);
}
protected void Application_End(object sender, EventArgs e)
{
}
public static readonly string DAOFactorySetting = "DAOFactory";
}
Any ideas why its returning null?
I've thought of one solution and that would be to change the reference to a web reference. The only problem then is that I would either have to add a localhost web reference which wouldn't work with the CI build. Or to reference the published development app layer, but that would mean that when I change my code I wouldn't be able to test it until it was committed!!
Any help would be greatly appreciated. I'm using C#.Net 2.0 with NUnit 2.4.7
Phil
P.S. I've copied the connectionString DevBox to the App.config in the WebServiceTests project so that it can see it.
|
|
|
|
|
An odd question but i have an interface which recieves a byte array of 1024 bytes from another device.
Byte Number Page Column
0 to 127 0 0 to 127 // bottom right
128 to 255 1 0 to 127
256 to 383 2 0 to 127
384 to 511 3 0 to 127
512 to 639 4 0 to 127
640 to 767 5 0 to 127
768 to 895 6 0 to 127
896 to 1023 7 0 to 127 // top left
Does anyone know if i can somehow convert these bytes to be represented in the text box on the GUI.
1023 896
895 768
767 640 // screen layout
639 512
511 384
383 256
255 128
127 0
Thanx in advance
|
|
|
|
|
maybe something like...
TextBox1.Clear();
for(int i = 1023; i >= 0; i--)
{
TextBox1.Text += ByteArray[i] + " ";
if(i % 128 == 0)
TextBox1.Text += System.Environment.NewLine;
}
...make sure you textbox supports multiline and that should work. Also you would be better using a StringBuilder[^].
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
well i have a string which contains a unix timestamp.
when i try to convert the string to either a double or a int, it gives me an error.
im out of ideas, i dont know how to get the string into a int or double, so i can convert it from unix to datetime.
here is my code:
string validstrStart = "validuntil=";
string validstrEnd = "username=";
int validstartIndex = result.IndexOf(validstrStart);
int validendIndex = result.IndexOf(validstrEnd);
string valid = result.Substring(validstartIndex, validendIndex - validstartIndex);
double timestampv = Convert.ToDouble(valid);
System.DateTime dateTime = new System.DateTime(1970, 1, 1, 0, 0, 0, 0);
dateTime = dateTime.AddSeconds(timestampv);
string validpro = dateTime.ToShortDateString() + " " + dateTime.ToShortTimeString();
it gives me an error in this line:
double timestampv = Convert.ToDouble(valid);
same thing when i try with an int.
any help please
|
|
|
|
|
I guess a unix timestamp is neither in the form of an int or a double. What does it look like ?
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
an example is:
1241771674
this is the unix timestamp of the date right now.
all of them are integers, and i think doubles as well.
so yeh :S
i dont know why its not working
|
|
|
|
|
I suspect you will find that's bigger than the maximum value for an int. So, try using long and see how that goes. I'm not sure what the max value for a long is.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
but you cant convert a string to a long.
remember, i need to convert the string into a int/long/double whatever, but i keep getting errors
|
|
|
|
|