|
Try the following. I put your two expressions into my Regex editor (http://www.radsoftware.com.au/regexdesigner/) and started playing around till I found the following to work.
\s*{\s*__(?<name>[^ ]+)__(\s*(?<parameters>#[^}]*)})?
It works because the second part of the expression (\s*(?<parameters>#[^}]*)})? is now in an un-named optional group. Your first example, // {__NAME1__} didn't match the second part of your expression, so it failed. The other two examples matched, so they came back. This will result in an extra group being returned, but you can ignore it when you go through your matches by using the group names.
Hope this helps.
Hogan
|
|
|
|
|
Hi,
I would like to know if there is any method in .NET that can gurantee that when I use it the data will be saved to disk.
e.g.
for(int i = 0; i < 5000; i++)
{
StreamWriter myStream = new StreamWriter("test.txt");
myStream.WriteLine(i);
myStream.Close();
}
This does not provide that guarantee, if power is cut during the saving of no. 2500, so many numbers will be missing and only blank lines are inserted in the file.
Even using the .Flush() method does not provide this feature.
I found one method that calls a function from Kernel32.dll using [DllImport], but that makes the i/o operation too slow, and that too without a perfect guarantee.
Please help.
|
|
|
|
|
There is no method at all that will guarantee that all of your data will get saved to the disk if the power is pulled halfway through the save operation. How could it? If you haven't finished writing it out, there's nothing that you can do.
BTW - your example will cause you problems. You open and close the stream through each iteration of the loop.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Hi,
I have a number of SQL Server Express editions those are running on the same network. I want to synchronize the data on each instance with other instances on the network. The problem is that Full/Enterprise version of SQL Server is not allowed. Does anybody have any idea on how to do it? Any suggestion, component etc.
Regards,
Wasif Ehsan.
|
|
|
|
|
Hi there. I am experiencing timeout:
System.Data.SqlClient.SqlException: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, TdsParserState state)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()
at System.Data.SqlClient.TdsParser.ReadNetlib(Int32 bytesExpected)
at System.Data.SqlClient.TdsParser.ReadBuffer()
at System.Data.SqlClient.TdsParser.ReadByteArray(Byte[] buff, Int32 offset, Int32 len)
at System.Data.SqlClient.TdsParser.ReadEncodingChar(Int32 length, Encoding encoding)
at System.Data.SqlClient.TdsParser.ReadSqlValue(_SqlMetaData md, Int32 length)
at System.Data.SqlClient.TdsParser.ProcessRow(_SqlMetaData[] columns, Object[] buffer, Int32[] map, Boolean useSQLTypes)
at System.Data.SqlClient.SqlDataReader.PrepareSQLRecord(Int32 i)
at System.Data.SqlClient.SqlDataReader.GetSqlInt32(Int32 i)
at System.Data.SqlClient.SqlDataReader.GetInt32(Int32 i)
The problem is that the exception is thrown when trying to get a field from the 8th row, 1st column. The command was executed successfully, and the reader read 7 rows. I tried it several times, and the problem appears when I reach the 8th row, always.
Any ideas?
Thanks in advance.
|
|
|
|
|
then check timeout[^] of connectionstring
I Love SQL
|
|
|
|
|
In the SqlCommand object there is a property called CommandTimeout. There is a good chance you need to increase this number. The default is 30 seconds. So if you need more time then that increase this property so you don't timeout as soon.
Ben
|
|
|
|
|
10x Ben, but it's nothing to do with that. As I have pointed out this occurs always on the same row, after Executing the command. Which is odd. To my knowledge timeout has nothing to do with reading the dataset, but it throws Timeout exception.
My only guess is that maybe the exception message is wrong or the wrong exception s thrown.
10x anyway for your help.
|
|
|
|
|
|
When your application starts first time, create a file and store the started date inside that. For more security you can store that as encrypted. Read this file when ever your application starts. if it reaches more than 60 day's show expired message. Alternatively you can keep this in Windows registry also.
|
|
|
|
|
The program needs a way to tell that it's the first time it runs, though... Otherwise, the user could just delete the file or registry key, and the program would create a new one, practically giving you 60 more days of testing.
|
|
|
|
|
Hello
How do I create a project for .net 1.0, what I am using now is VS 2005. Can I convert and existing project to .net framework 1.0??
samuel
|
|
|
|
|
Not inside VS2005.
Well, you could create the code in VS2005 (i.e. just using it as a text editor) and as long as you only used .NET 1 methods, you could compile it using the cs command line compiler.
I do have a question though, why would you want to do this? .NET 2 provides a much better framework so it's hard to see why you would want to use a lesser version.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
well the WinCE 4.2 is stable only with .net 1.0 and with 2.0 there seems to be some issues, thanks I will try your method and see how it works
|
|
|
|
|
I am creating a menu control. It is having property called Items similar to ListItem . MenuItem class contains MenuName , MenuText , Image properties. User can add any number of menu items. So I created MenuItemCollection class which extends CollectionBase . It's having add method which accepts MenuItem class objects. Everything worked fine when adding from code behind. It looks like
MenuItemCollection MnuCollection = New MenuItemCollection();
MnuCollection.Add(MenuItemObject)
But problem started when I given collection class to the Items property to let user add menu items at design time, like what listbox do.VS Editor is showing collection at the Items Property. But when I click on Items, it opens collection editor also. But after clicking new it's simply showing System.Object . It's not showing any properties written in the MenuItem class. Can any one throw some light into this problem ? How I can create a collection class in user control and set that to the property, where user can add items at design time ?
|
|
|
|
|
If you are using .net >= 2.0 then I suggest you use a generic collection for your MenuItems:
public List<MenuItem> MenuItems
{
get { ... }
set { ... }
}
-^-^-^-^-^-
no risk no funk
|
|
|
|
|
Urs Enzler wrote: public List <MenuItem> MenuItems
Thanks, But I am not clear with this line, what do you mean by this ? By specifying <MenuItem> will this show properties in MenuItem class on CollectionEditor ?
|
|
|
|
|
I receive a format exception message when i run this program.
the code is as follow:
string latitude1, latitude2;
string longitude1, longitude2;
latitude1 = label9.Text;
longitude1 = label10.Text;
label9.Text = textBox1.Text.ToString();
label10.Text = textBox2.Text.ToString();
latitude2 = label9.Text;
longitude2 = label10.Text;
if ((latitude1 != latitude2) || (longitude1 != longitude2))
{
double lat1 = Convert.ToDouble(latitude1);
double long1 = Convert.ToDouble(longitude1);
//double lat1 = 1.346094;
//double long1 = 103.932421266667;
double lat2 = Convert.ToDouble(latitude2);
double long2 = Convert.ToDouble(longitude2);
double lat1r = lat1 * (Math.PI / 180);
double long1r = long1 * (Math.PI / 180);
double lat2r = lat2 * (Math.PI / 180);
double long2r = long2 * (Math.PI / 180);
double latitude = lat2r - lat1r;
double longitude = long2r - long1r;
double a = Math.Pow(Math.Sin(latitude / 2.0), 2.0) + Math.Cos(lat1r) * Math.Cos(lat2r) * Math.Pow(Math.Sin(longitude / 2.0), 2.0);
double c = 2.0 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1.0 - a));
const Double earthRadius = 6376.5;
distance = earthRadius * c;
}
totalDistance = totalDistance + distance;
label4.Text += totalDistance.ToString();
the exception came in at double lat1 = Convert.ToDouble(latitude1);
so i edited the code to:
string latitude1, latitude2;
string longitude1, longitude2;
latitude1 = label9.Text;
longitude1 = label10.Text;
label9.Text = textBox1.Text.ToString();
label10.Text = textBox2.Text.ToString();
latitude2 = label9.Text;
longitude2 = label10.Text;
if ((latitude1 != latitude2) || (longitude1 != longitude2))
{
if (latitude1!="" || longitude1!="")
{
double lat1 = Convert.ToDouble(latitude1);
double long1 = Convert.ToDouble(longitude1);
//double lat1 = 1.346094;
//double long1 = 103.932421266667;
double lat2 = Convert.ToDouble(latitude2);
double long2 = Convert.ToDouble(longitude2);
double lat1r = lat1 * (Math.PI / 180);
double long1r = long1 * (Math.PI / 180);
double lat2r = lat2 * (Math.PI / 180);
double long2r = long2 * (Math.PI / 180);
double latitude = lat2r - lat1r;
double longitude = long2r - long1r;
double a = Math.Pow(Math.Sin(latitude / 2.0), 2.0) + Math.Cos(lat1r) * Math.Cos(lat2r) * Math.Pow(Math.Sin(longitude / 2.0), 2.0);
double c = 2.0 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1.0 - a));
const Double earthRadius = 6376.5;
distance = earthRadius * c;
}
}
totalDistance = totalDistance + distance;
label4.Text += totalDistance.ToString();
adding another if condition to solve the exception, although the format exception was handled. the end result of what was expected is not there. the totalDistance calculated show me an answer that display infinity.
any idea how i can solve this problem
|
|
|
|
|
Hello,
And you had no time to make a little debugging, to tell us the point where the exception occures?
Sorry just saw, that you gave some infos.
But it is very difficult to see, as you are not using the pre tags to mark the code!
I would think, this is very dangerous!
Convert.ToDouble(latitude1); Use "double.TryParse" instead!
And that's the reason of the exception:
latitude1 = label9.Text;
longitude1 = label10.Text;
label9.Text = textBox1.Text.ToString();
label10.Text = textBox2.Text.ToString();
Looks like label Text is empty when you pathit to the string field.
label9.Text = textBox1.Text.ToString();
label10.Text = textBox2.Text.ToString();
latitude1 = label9.Text;
longitude1 = label10.Text;
-- modified at 5:06 Thursday 26th July, 2007
All the best,
Martin
|
|
|
|
|
How would this be dangerous?
Convert.ToDouble(latitude1);
i did try using double.TryParse() but it doesn't work. The end result is still infinity.
latitude1 = label9.Text;<br />
longitude1 = label10.Text;<br />
<br />
label9.Text = textBox1.Text.ToString();<br />
label10.Text = textBox2.Text.ToString();<br />
<br />
latitude2 = label9.Text;<br />
longitude2 = label10.Text;
i did it in this way because whenever a new coordinate(latitude, longitude) is received, it will replace the variable that is either of old value being stored or empty value currently.
|
|
|
|
|
Let's suppose for a moment your program contains more than one mistake.
You will have to fix them all.
It is unlikely that fixing the first one will solve all problems, since by
assumption there are multiple problems.
But still, the first mistake needs fixing.
So why do you ask for advice, then choose to ignore perfectly good advice
Anyhow if some system does not behave the way you intended, there are two ground rules:
1. observe, observe closely, observe even more closely; so dont look at the end result,
it is wrong and it will be wrong for a long time.
2. if you dont understand the overall thing, reduce the size; make sure that part works
perfectly under all circumstances; then investigate another part, etc; when all parts
SEEM OK, now look at the whole thing again.
Such is called debugging, whatever the tools you use.
|
|
|
|
|
|
I want to read data from a hardware device like time access punching machine.
What is the complete process to read data and storing into a databse from any hardware device.
If any one have some idea, please guide me.
Thanks,
Pathak
|
|
|
|
|
I am using FolderBrowserDialog to Browse for folder
I want to show the address in textbox also which I select in FolderBrowserDialog
or can directly type the address of folder in textbox instead of selecting it from tree view control
FolderBrowserDialog obj=new FolderBrowserDialog();
obj.ShowNewFolderButton=true;
Ankit Aneja
"Nothing is impossible. The word itself says - I M possible"
|
|
|
|
|
Hi sweety , it's very easy . enjoy it :
// Initialize FolderBrowserDialog
FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog();
// If dialogResult result is OK then set txtAddress by folderBrowserDialog
// SelectedPath's property .
if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
{
string selectedPath = folderBrowserDialog.SelectedPath;
txtAddress.Text = selectedPath;
}
have a good time.
DMASTER
|
|
|
|