|
If it uses a different encoding then create that instance of the Encoding you need. Taking a dependency on another assembly just to use Chr is absurd. Are you now going to bloat your software distribution and force that assembly on your clients?
It all comes down to encodings. If the character is encoded differently than UTF8 or Unicode, then use the right encoding:
Encoding enc = Encoding.GetEncoding(932);
string s = enc.GetString(BitConverter.GetBytes(0x819a));
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hello Heath,
Thanks for the support.
Heath Stewart wrote:
Taking a dependency on another assembly just to use Chr is absurd. Are you now going to bloat your software distribution and force that assembly on your clients?
You really believe I will be doing that? Chr is a static and almost independent.
Heath Stewart wrote:
It all comes down to encodings. If the character is encoded differently than UTF8 or Unicode, then use the right encoding:
If you are using an international version of XP, just set the font of the Form to "MS Mincho" or similar with the character set to Japanese and view the output of your code snip in a paint handler as:
e.Graphics.DrawString(s, this.Font, Brushes.Red, 20, 20);
Best regards,
Paul.
Jesus Christ is LOVE! Please tell somebody.
|
|
|
|
|
Paul Selormey wrote:
Chr is a static and almost independent.
It doesn't matter if it's static. There is no "static linking" like with native code. Or are you saying that you'll just duplicate what it does. I've done this for an old project for a GetDeviceCaps wrapper.
The character encoding is a different issue than the font issue, which I didn't realize you were having problems. Yes, a font file must have defined a glyph for that font, but how the character is encoded is a different matter. When you decode it you have a char . The cast I showed you initially would've worked had the character been ASCII (7-bit) or Unicode (native to .NET) encoded. Characters in .NET are all stored as Unicode, so you just need to make sure you decode it from the proper encoding. Whatever font you use should be based on what characters you expect.
In Windows XP several of them have a wide range of Unicode characters. Font files, BTW, are typically encoded for a particular encoding. For the Unicode font files, they are coded for Unicode encoded characters, of course.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Heath Stewart wrote:
Or are you saying that you'll just duplicate what it does. I've done this for an old project for a GetDeviceCaps wrapper.
That is the simply story.
public static char Chr(int CharCode)
{
if ((CharCode < -32768) || (CharCode > 0xffff))
{
throw new ArgumentException();
}
if ((CharCode >= 0) && (CharCode <= 0x7f))
{
return Convert.ToChar(CharCode);
}
int nTemp;
Encoding enc = Encoding.GetEncoding(932);
if ((enc.GetMaxByteCount(1) == 1) && ((CharCode < 0) || (CharCode > 0xff)))
{
throw new InvalidOperationException();
}
char[] chTemp = new char[2];
byte[] buffer = new byte[2];
Decoder decoder = enc.GetDecoder();
if ((CharCode >= 0) && (CharCode <= 0xff))
{
buffer[0] = (byte) (CharCode & 0xff);
nTemp = decoder.GetChars(buffer, 0, 1, chTemp, 0);
}
else
{
buffer[0] = (byte) ((CharCode & 65280) / 0x100);
buffer[1] = (byte) (CharCode & 0xff);
nTemp = decoder.GetChars(buffer, 0, 2, chTemp, 0);
}
return chTemp[0];
}
Best regards,
Paul.
Jesus Christ is LOVE! Please tell somebody.
|
|
|
|
|
Hello,
I would like to do the following thing: Suppose I have a .Net program running. From another program I want to be able to get access to the first program's instantiated objects. My utlimate goal is to have something like a real time debugger where I can see the actual object's properties and fields values, without having to pause the program and use the VS debugger. Right now I have done something that can do exactly what I describe here, however from the program I want to debug I need to give reference to the objects I want to analyse to my real time debugger.
I realy want to achieve the same thing with my real time debugger but without having to have a link between the debugge and and the debugger.
I have investigated the following:
- Use Process.GetProcesses() then get a module from the process with: ProcessModuleCollection modules = process.Modules.
From there I don't know where to go....
Any Ideas ?
- Dany McCarthy -
|
|
|
|
|
A process is not the same as an AppDomain , in which the managed objects are actually hosted. For this you need to implement .NET Remoting, which you can read about at http://msdn.microsoft.com/library/en-us/cpguide/html/cpconaccessingobjectsinotherapplicationdomainsusingnetremoting.asp[^]. Just having a Process instance (in the native world, this is a process handle, or HANDLE ) won't help you acheive that end.
If it's a debugger or debugger-like application your after, then write one. It's actually not too difficult if all you want to do is examine objects. View the search results for managed debugger[^] for a large list of examples about how to implement a debugger, as well as some blog entries from developers on the CLR team.
This will require native code and can tell a lot more about an object than what you can get through managed code, even with .NET Remoting - which would require that you establish a remoting infrastructure for both applications.
You can use other IPC (inter-process communications) mechanisms to communicate between applications, but .NET Remoting is the recommend way, and is the best way to marshal managed objects across application boundaries, rather than marshaling memory through global locks and other ways that you'd have to do in managed code. Keep in mind that what managed applications see is much different than what's actually on the heap or in the stack for managed objects. That managed code is JIT'd to native code, which works much differently under the covers.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Thanks Heath, for sure I do not want to go through the unmanage solution. I think I will keep going with what I've done so far. I already planned to implement remoting to do real time remote debugging. I will send an article about my results if they are concluant.
Best regards,
Dany McCarthy
|
|
|
|
|
I have to do a stock market demstration for class, and I am fairly new to C#(have made one little guessing game) and i need some help. I would like for the user to start with some money, purchase stocks of a few possible companies, be able to sell them, and then give a total score at the end of 30 days in the game. It would be random, so you never know what could happen. Anyway to do this simply?
Doesn't have to be pretty.
(Im only 13 so i dont know that much)
|
|
|
|
|
Well, the easiest way is to take the problem and break it into smaller problems, then work on the smaller problems. If you still can't work it out then perhaps the problem is still too big and needs to be broken down further.
So your user has:
money
choice of stocks
ownership of stock
The program runs for 30 cycles (days). In each cycle the user has the option to buy or sell stock. (I suggest allowing the user to sell first, before buying). At the end of each cycle the each stock price changes by a random amount (to simulate market movements)
At the start of your program you need to set up the variables (money, stocks, and owenership).
You may wish to look at NameObjectCollection[^] so you can create a look up based on the stock name. So you have a lookup of stocks (the key is the stock name) with the object being the current stock price. The same goes for ownership (the key is the stock name, with the object being the current quantity of stock owned) [Is this making any sense? If I'm talking at the wrong level let me know]
Each cycle you get the user input for the stocks they wish to sell. You adjust the ownership list for these stocks by the amount of stock they sell and credit the money they have with the sale price.
You then allow the user to buy stock. Add the stock to ownership list, and deduct the amout of money it cost from their account.
At the end of the program you can list how much money the user has, and how much of each stock (and the value of each, if you want).
I hope this has helped. It may help if you write out some pseudo code (a kind of English-like code that reads like bullet points on paper) that can help to organise thoughts better. Like this:
--Initial setup
* Set money to $1000
* Set stock_price item "MSFT" to $25
* Set stock_price item "RYA" to $36
* Set stock_price item "HBOS" to $12
* Set ownership item "MSFT" to $0
* Set ownership item "RYA" to $0
* Set ownership item "HBOS" to $0
-- Main loop
* Loop 30 times
-- Sell Stock
** Ask for stock to sell
** Get stock_name as input
** Get quantity as input
** Subtract quantity from ownership item [stock_name]
** Add quantity * stock_price [stock_name] to money
-- Buy Stock
** Ask for stock to buy
** Get stock_name as input
** Get quantity as input
** Add quantity from ownership item [stock_name]
** Subtract quantity * stock_price [stock_name] from money
-- Update stock prices
** Change stock_price "MSFT" by random amount
** Change stock_price "RYA" by random amount
** Change stock_price "HBOS" by random amount
* End loop
* Display results
You can use what ever notation works for you. What ever way helps you organise your thoughts...
Does this help?
Do you want to know more?
WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and Forums Upcoming talk:
SELECT UserName, Password FROM Users
-- Getting unauthorised access to a SQL Server, and how to prevent it.
|
|
|
|
|
I kind of get it, but how would i stop the loop to allow selling/buying?
I am a little confused.
|
|
|
|
|
Code Project lost my original post so I'll try again.
To loop a set number of times use a for loop like this:
for(int i=0; i<30; i++)
{
} I'll break each section down so you can see what it does.
int i=0; This sets up a variable i which we use to count the iterations (i.e. the number of times the loop will repeat itself) and we set that variable to zero to start with (you can set it to any number you like depending on your circumstances, but because our problem is simple zero will do just fine.
i<30; This is the condition that is used to determine whether the loop is to keep repeating. This says that while i is less than 30 then repeat.
i++ This is what happens to i at the end of each iteration. In this case we add one (++ is the increment operator). You can specify anything you like depending on your situation, however since this is a simple repeat 30 times we'll just add one.
Does this help?
Do you want to know more?
WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and Forums Upcoming talk:
SELECT UserName, Password FROM Users
-- Getting unauthorised access to a SQL Server, and how to prevent it.
|
|
|
|
|
Hi folks:
I have simple question for you: how can I find the position to a newly created record in a DataSet in the corresponding DataGrid?
My DataGrid is binded to a SQL DataSource. Another application creates a new record into the database. I need to refresh the DataSet and, after this, I need to obtain the position of the new record in the DataGrid in order to show to the user the new record.
I assumed it was as easy as to search the new record in the dataset, but the position of the record in the dataset doesn't correspond (necessarily) to the position in the DataGrid because it may have another sort order.
Hope somebody can help with this simple question,
Regards,
Enrique .
|
|
|
|
|
This has been covered many, many times in this forum. Click "Search comments" above this forum and search for "DataGrid DataSet".
Also see the .NET Framework SDK for the SqlDataAdapter.Update and Fill methods. The documentation for the DataGrid.DataSource and DataMember properties also contain examples and other information about binding a DataSet to a DataGrid .
To find the record of the new row is possible in many ways. The DataSet keeps track of changes (so never call DataSet.AcceptChanges before SqlDataAdapter.Update , otherwise no changed information is found and the database is not updated), so you can enumerate the rows and find the newest row. A more efficient way is to handle the DataTable.RowChanged event for the DataTable within the DataSet that you've bound to. In your event handler, you check the DataRowChangedEventArgs.Action for DataRowAction.Added . If that is the case, the DataRowChangedEventArgs.Row is the DataRow that was just added to the DataTable .
You should also keep in mind that if you allow sorting in your DataGrid , the select row visually may not actually be the nth row in the DataTable . For that, you use a CurrencyManager . This is because what the view in the DataGrid is is only a view; the data is unchanged in the DataTable . If you click "Search comments" and search for "CurrencyManager" you can find many topics covering this problem as well.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
hi,
i have installed VS.net 2003 on a windows server 2003 machine. i am not able to open any new
or old web application c# project. i have tried most common method of registering IIS using "aspnet_regiis.exe -i". But, still i am not able to open the web application project. can anybody tell what else i need to do?
thanks in advance,
Pankaj
|
|
|
|
|
It says "Visual studio.NET cannot create or open the application. The likeliest problem is that required components are not installed on the local Web server. Run Visual Studio.NET setup and add the Web Development component". I have IIS installed and localhost is working fine.
please help
|
|
|
|
|
Your question belongs in the ASP.NET forum.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
from MSDN:
A ListItem control represents an individual data item within a data-bound list control, such as a ListBox or a RadioButtonList control.
There are several ways to specify the text displayed for an item in the list control.
The most common method is by placing text in the inner HTML content. The inner HTML content is the text between the opening and closing tags of the ListItem control.
You can also use the Text property to specify the text displayed in the list control for the item.
The Value property allows you to associate a value with the item in the list control, in addition to the text displayed in the control.
For example, you can display text for an item in the list control,
such as "Item 1", and use the Value property to specify a value for that item,
such as "$1.99".
Which applies to the webforms control.
For the windows forms listbox, you can add any object to its 'Items' collection. The text in the listbox is by default the result of the ToString() method for the added object (which could also have any other public properties such as your index). You can also specify the source of the test in the DisplayMember propery of the ListBox itself (the name of the public string property of your list objects that should be displayed as the text). The ComboBox control works similarly, since it also derives from ListControl.
Why would anyone waste time arguing with an accountant about anything? Their sole function is to record what happenned, and any higher aspirations are mere delusions of grandeur. On the ladder of productive contributions they are the little rubber pads at the bottom that keep the thing from sliding out from under you. - Roger Wright
|
|
|
|
|
Here is what I am trying to do. I have a DataSet that is displayed in a DataGrid. I would like the user to be able to highlight a row and then press the delete button above it, and have the highlighted row be deleted.
I have somewhat accomplished this. My current method is to search the DataGrid for the selected rows and store their index number. Then delete the rows with the corresponding index in the DataSet. This works great as long as the DataSet was not sorted at all while in the DataGrid. If the data was sorted then the index's of the DataGrid are still in ascending order (i.e. 0 for the top row, 1, ...), but the index's of the DataSet are in the order that the row was added. Thus, I delete the wrong row.
The code that I have is below, any help is appreciated.
ArrayList rowsToRemove = new ArrayList();<br />
for(int i = 0; i < myDataSet.Tables[myTableName].Rows.Count; i++)<br />
{<br />
if(myDataGrid.IsSelected(i))<br />
{<br />
rowsToRemove.Add(i);<br />
}<br />
}<br />
int count = 0;<br />
foreach (object j in rowsToRemove)<br />
{<br />
myDataSet.Tables[myTableName].rowsToRemove[(int)j - count].Delete();<br />
count ++;<br />
}
|
|
|
|
|
Why can't you just use the dataAdapter's update method?
|
|
|
|
|
You should use the DataGrid.BindingContext to get a CurrencyManager , which is always the view of the bound DataTable . That means if you sort it, the CurrencyManager will enumerate the rows in the sorted order.
This has been discussed before and I've posted an example several times. Please click "Search comments" above this message board and search for "CurrencyManager". You can also view the documentation for the CurrencyManager example in the .NET Framework SDK, which is installed by default with VS.NET, available as a separate download from http://msdn.microsoft.com/netframework[^], and available to read online at http://msdn.microsoft.com/library[^].
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Thanks! Your response was most helpful, and your right, that did the trick!
|
|
|
|
|
We have Access 2003, and we secured a database using "User Level Security
Wizard". Now we have 2 ".mdw" files,
the original one which we used to secure the database, and another one that
is created when we open the database.
Through connection string we open the database using the original one. My
question is.. is there a way to open the
database using the other ".mdw" (the one that is created by access when the
databse opens) as this is the one that
really enforce the security on the file. Bare in mind that this is a windows
application class so everyone will have a copy
of the original ".mdw" to be able to connect to the database...
|
|
|
|
|
In the connection string you can specify the path to the correct MDW file using the "System Database" property, like:
OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4; "
+ "User ID=anon;Password=;Data Source=C:\Data\Database.mdb; "
+ "System Database=C:\Data\Users.mdw"); Any further questions specific to ADO.NET please post in the ADO.NET forum.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hi!
My goal is to create a typed dataset from an XML file at run-time, meaning that I don't want all columns to be strings, but also integers, floats and so on. The thing is that at run-time, I know about the types of the fields to be created, but I don't have this information in a .xsd or .dtd file and don't want to use schemas in other files.
So here is a sample example XML file:
<?xml version="1.0" encoding="utf-8" ?>
<config xmlns="http://tempuri.org/simple.xsd">
<params>
<SomeFloat>0.25</SomeFloat>
<SomeInt>25</SomeInt>
<SomeString>A string</SomeString>
</params>
</config>
which would gives me something like this:
Name: value: type:
SomeFloat 0.25 string
SomeInt 25 string
SomeString A string string
with the following code:
----------
m_Dataset = new DataSet();
m_Dataset.ReadXml("simple.xml");
//Linking dataset to datasource
DataGrid datagrid = new DataGrid();
dataGrid1.DataSource = m_Dataset;
//Selecting the node that is of interest
dataGrid1.DataMember = "params";
dataGrid1.CaptionText = dataGrid1.DataMember;
---------
I know at run-time that SomeFloat is a float, SomeInt an int and son on. So before I load the XML, I would like to specify programmatically the table so it would look like this:
Name: value: type:
SomeFloat 0.25 float
SomeInt 25 int
SomeString A string string
How can I make sure that the type of the columns won't be only strings? How can I specify these types? Should I create the table in the dataset first?
Thanks!
Huck
|
|
|
|
|
how is this done? (its a byte array, if it matters..)
|
|
|
|
|