|
If you're stopping another timer, why not just change its interval to the interval you had in mind for the third timer and hook up the right event listener to it?
|
|
|
|
|
I have a console application, that shows messages using Console.WriteLine. I have a WinForms application, that runs the console application, and redirects the console output to a TextBox (using ProcessInfo.StartInfo.RedirectStandardOutput ).
When the console output contains the character 'ë' (or '\x00EB'), the TextBox shows it as '‰' (the per mille sign). In the debugger's Locals window, I see the '‰' instead of the 'ë' in the string that has to be displayed, so the error is not in the TextBox.
Why is the 'ë' changed into a '‰'? How can I get it to display correctly? I want to get rid of my current workaround, doing a Replace('‰', 'ë') , because there are other characters (like ï or é) that could cause the same kind of problem.
|
|
|
|
|
Using CharacterMap, take a look at the font that your TextBox is using and the font that the Output window is using. You'll probably see a difference right away.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
I don't think so, because I already set the console and the textbox to the same font (Lucida Console). The 'ë' is character '\x00EB', the '‰' is '\x2030', and both show up correctly in the Lucida Console font (as they do in Courier New).
When I searched the string for a character '\x00EB' it just wasn't there. So it is most likely not a matter of font difference, but more a character encoding problem.
|
|
|
|
|
Correct. it has to be an encoding problem.I have never really played a lot with encodings to the console and when I did it was years back. But you might get some hints from "Console.InputEncoding" and "Console.OutputEncoding".
|
|
|
|
|
I created the following function, to try to convert console output to a string that can be displayed in a textbox.
private string ConsoleOutputToUnicode(string consoleOutput)<br />
{<br />
byte[] bConsole = Console.OutputEncoding.GetBytes(consoleOutput);<br />
byte[] bUnicode = UnicodeEncoding.Convert(Console.OutputEncoding, UnicodeEncoding.Unicode, bConsole);<br />
return UnicodeEncoding.Unicode.GetString(bUnicode);<br />
}
I tried other encodings (Default, UTF7, UTF8, UTF32) with the same result, and ASCII resulting in a '?'. Same results with ASCIIEncoding instead of UnicodeEncoding .
The byte[] bConsole is filled with the proper ASCII values ('ë' translates into a byte with the value 137). In a console (or in a message reply box in this thread) type alt-137, and you will see an 'ë'.
In bUnicode I would expect two corresponding bytes with the values 235 and zero (for \x00EB), but I get the values 48 and 32 (so \x2030, which is the per mille sign). Why is that?
One thing I discovered is that typing alt-0137 in a console also gives a '‰'. It is almost like somewhere in the conversion process the leading zero is added.
|
|
|
|
|
It was a thought. I've seen a couple noobie dev's change the font's in the IDE to some really weird ones (Star Trek types) and they wondered why something similar happened to them.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Hi all,
I was wondering if there is anyway that you could use Math.Round or some other method/class to round numbers off.
Basically if I have the number 19 or 256 etc I would like to round it off to the nearest ten,
ie
19 rounded to 20
256 rounded to 260
I've tried using Math.Round but that only works for decimals.
Any idea's?
TIA
Gav
|
|
|
|
|
The following should work:
double x = 256;
x = Math.Round(x / 10.0) * 10.0;
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
i dont know if there already is a function. if not try this:
<br />
function roundup(int myval)<br />
{<br />
while (myval % 10 != 0)<br />
myval++;<br />
return myval;<br />
}<br />
<br />
usage:<br />
roundup(15);<br />
<br />
output:<br />
20<br />
if you want it to use the "real" rules, you will have to do it like this:
<br />
function round(int myval)<br />
{<br />
int runs = 0;<br />
while ((myval + runs) % 10 != 0)<br />
{<br />
runs++;<br />
}<br />
if (runs < 5)<br />
return (myval - 10);<br />
return myval;<br />
}<br />
EDIT: the post before this one shows another solution which is much simpler and also looks better (since it's using inbuilt technology it probable will be faster too )
|
|
|
|
|
Thanks for replying,Actually i am trying yo convert matlab code into C#,if u can help me then i will send u the code in matlab and also that work that i have done C#, but plz help me
and give me ur mailing id so that i could send u code in attachments
|
|
|
|
|
Hi all,
I have a variable: string TelNo = "(000)000-0000"
How can i trim away the first and second bracket and also the "-" between the zeros. I just want the following value to be in the TelNo Variable...
"0000000000"
Thank you in advance.
"Many of life's failures are people who did not realize how close they were to success when they gave up." Thomas A. Edison
|
|
|
|
|
TelNo.Replace("-", "");
TelNo.Replace("(", "");
TelNo.Replace(")", "");
this will remove ALL "(", ")" and "-" from the string.
|
|
|
|
|
Thank you.
I would never have thought about using replace. I thought i would be something to do with the "Trim().IndexOf"....
Thank you for your time.
"Many of life's failures are people who did not realize how close they were to success when they gave up." Thomas A. Edison
|
|
|
|
|
Another way to do it would be to go through the entered string, character-by-character, and add only the numbers to a StringBuilder. When your done searching the string, just call the StringBuilder's .ToString method to return the entered number, sans all the seperation characters and formatting. With this method you get the flexibility of using any seperation characters you want and support for freeform entry of the number.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Hi:
I am trying to serialize/deserialize a datatable in chunks (say every 10,000 records of a 250,000 record table) using the filemode.append functionality of the binary formatter stream object as follows:
dt.RemotingFormat = SerializationFormat.Binary;
BinaryFormatter formatter = new BinaryFormatter();
Stream output = new FileStream(path, FileMode.Append, FileAccess.Write, FileShare.Write))
formatter.Serialize(output, dt);
This serializes the file to disk just fine. I can watch the size of the resulting disk file increase with each chunk added.
When I attempt to deserialize the file, I only get the first chunk (1st 10,000 records) of data from the datatable and the rest is apparently ignored. Looking at the file in a hex editor, I can see header records for each appended set of records. I believe that the multiple headers are the problem.
I know I have to be overlooking something simple. If you have seen this or solved this, please tell me what I need to do.
Thanks for your time.
John
|
|
|
|
|
Hi,
I have also experienced this. The problem lies in the deserialization of the DataTable. Somehow when deserializing a DataTable it somehow reads some more bytes from the next object in the stream thus destroying the next deserialization step. This not only occurs when using several DataTables but also when you just append some other information after a DataTable. One workaround would be to save your tables in different files. The other possibility would be to add some more custom information to the stream:
Saving:
1. Serialize the table into a MemoryStream.
2. Append the length of the MemoryStream (a simple integer should be alright) to your FileStream.
3. Append the contents of the MemoryStream to the FileStream.
Repeat 1-3 for every DataTable.
The resulting file should logically look somehow likes this:
<Length from Table1><Data from Table1><Length from Table2><Data from Table2><Length from Table3><Data from Table3>...
Loading:
1. Open the FileStream.
2. Deserialize an integer giving you the length of the next DataTable.
3. Deserialize the DataTable.
4. Adjust the Position property of the FileStream to match the length you read at point 2.
Repeat 2-4 for every DataTable (or just until the FileStream is empty).
Robert
|
|
|
|
|
Thanks for the help.
Your suggestion did the trick. Didn't need to mess with the position as it was where it needed to be for the next deserialization.
Thanks again.
|
|
|
|
|
i want to make report that will open DataBase and read two colum
as (select tblUsrs.grad from tblUsrs)
i want to display label with (exlent, very good,good) by use the tblUsrs.grad from tblUsrs
plz how can make this ........
Palestine
|
|
|
|
|
Hi,
I made a event handler for a serialport. This event handler is meant for response from the device which is attached to the serialport.
This is how the event hander looks like:
public static void ReplyOnDataReceived(object sender, SerialDataReceivedEventArgs e)
{
buffer += serialPort.ReadExisting();
}
Im using thread.sleep() at the moment. But this is not very trustworth.
So now i wanna use an event handler, for instance if it receives response from the device attached on the serialport, than go on with the program.
Hope you guys can help me.
Thanks in advance!
|
|
|
|
|
I have DataGridColumnStyle-s assigned to my datagrid. The columns are filled with data. How can I insert the data of a single column to a SQL Server database? I have inserted the data of a column into a SortedList, so I want to insert these values using the Insert statement to a CommandText property of the SqlCommand class???
|
|
|
|
|
you could do it like this or by using a sql/odbc/oledb datadapter (e.g. system.data.oledb.oledbdataadapter) and set it up. this is a bit more complicated and i used it only once so you should go and google for it. the msdn has some nice explaination about how to use this thing. if you want to do it by yourself, you will have to have an array (or list or anything else) containg the values and the fieldname (a 2-dimensional array would do the job
if you got a table consisting of 3 columns (e.g. id, name, postdate) you would need an array like this:
data[0,0] = "id";<br />
data[0,1] = 0;<br />
data[1,0] = "name";<br />
data[1,1] = "myname";<br />
data[2,0] = "postdate";<br />
data[2,1] = "2006-05-02";<br /> (alternatively you could use 2 single array, one holding the column names and the other one holding the column values)
it would be easy to generate the statement then - it could look like
string sqlquery = "INSERT INTO tablename (";<br />
string comma = "";<br />
<br />
for (int i = 0; i < data.GetLength(0)-1; i++)<br />
{<br />
if (i > 0)<br />
comma = ","<br />
sqlquery = sqlquery + comma + data[i,0];<br />
}<br />
<br />
sqlquery = sqlquery + ") VALUES (";<br />
<br />
for (int i = 0; i < data.GetLength(0)-1; i++)<br />
{<br />
if (i > 0)<br />
comma = ","<br />
sqlquery = sqlquery + comma + "'" + data[i,1] + "'";<br />
}<br />
<br />
sqlquery = sqlquery + ");";<br />
this code would produce a query like
<br />
INSERT INTO tablename (id,name,postdate) VALUES ('0','myname','2006-05-02');<br />
since this can be a lot of work you should make yourself familiar with the dataadapters
|
|
|
|
|
Thanks many!
|
|
|
|
|
yeah and maybe take a look at concurrencymanager.
Tom Wright
tawright915@gmail.com
|
|
|
|
|
Hello everybody,
i've been searching the forums for a similar question but wasn't successfull yet.
So i decided to ask the question by myself.
Is there ANY possibility to create a pointer in a generic class, which points to a variable of one of the specified typeparameters.
A little example
<br />
class myclass <T><br />
{<br />
unsafe T * myptr = null;<br />
}<br />
The compiler tells me he isn't able to declare a pointer of a "managed type" (I hope this is the correct translation so let me know if that doesn't make any sense)
Is there a workaround to make this pointer point to the specified address AND act like a "native" pointer (please don't tell me about a void pointer - it just doesnt work for my purposes)
____________________________________
If this should not be possible (yeah, i almost gave up ) is there a solution for my problem anyways? It's about associating some variable with another one.
<br />
public class dbTable<br />
{<br />
ulong myvar = 0;<br />
dbColumn<ulong> mycol = null;<br />
<br />
public dbTable()<br />
{<br />
mycol = new dbColumn<ulong>();<br />
mycol.MapVariable(ref myvar);<br />
}<br />
}<br />
<br />
public class dbColumn<T><br />
{<br />
public T mysecondvar;<br />
public MapVariable(ref T VarToMap)<br />
{<br />
mysecondvar = VarToMap;<br />
}<br />
}<br />
That example doesn't work of course because it will try to assign the value of "VarToMap" to "mysecondvar". When trying to retrieve "VarToMap"-address and assign it to "mysecondvar" the compiler throws out some errors too (the address wasn't meant to be the value of a ulong variable).
I want to be able to get the following output when performing this code:
<br />
dbTable mytable = new dbTable();<br />
mytable.myvar = 5;<br />
<br />
Console.WriteLine(mytable.myvar.ToString());<br />
Console.WriteLine(mytable.mycol.mysecondvar.ToString());<br />
<br />
mytable.mycol.mysecondvar = 3;<br />
<br />
Console.WriteLine(mytable.myvar.ToString());<br />
Console.WriteLine(mytable.mycol.mysecondvar.ToString());<br />
This should produce:
<br />
5<br />
5<br />
3<br />
3<br />
So i want one Variable to keep the Value and another one to point at it BUT i need to be able to specify the type of both variables (void pointer would do the job but i'm not able to retrieve or assing values to the variable its pointing to because the "=" operator wasn't defined for!)
I hope that someone has a solution for this problem (as already mentioned, i don't care about how it is realized as long as the requirements above are met)
I would like to hear any kind of comment because i'm really desperated.
If this i a bas idea at all it would be nice if you could tell me why i shouldn't do it like this...
Thanks in advance
mik
-- modified at 9:42 Wednesday 30th August, 2006
|
|
|
|