|
All integer expressions are computed using ints or larger, even if all the terms in it are bytes or shorts; that has been true in all C-like languages. The difference with C# is it complains when trying to store such expression result in anything smaller than int; C and C++ silently truncated the result, with a possible value error for free. In C# you need a cast, so you know you are responsible for a possible truncation.
try this (or its equivalent) in different languages:
ushort a=1;
ushort b=0xFFFF;
a++;
a=(ushort)(a+1);
b++;
b=(ushort)(b+1);
You may not like it, but this is how it has been defined.
The details can be found in section 7.2.6.2 of the C# language specification.
If you were to study the programming language you choose from a book, you would probably know such things.
|
|
|
|
|
Luc,
Thanks for your explanation. Not sure if the last line is meant condescendingly, but I value your input too much to complain . And your right. Its been a while since I really dug through my c# books. This is a PT thing for me. When it was FT, I did spend a lot more time in the books.
Thanks again.
*****************
"We need to apply 21st-century information technology to the health care field. We need to have our medical records put on the I.T." —GW
|
|
|
|
|
Dwayner79 wrote: Not sure if the last line is meant condescendingly
Not at all.
Too many people try and learn a language by experimenting, or reading a few things on the web, instead of really studying a book. A book tends to teach such stuff in a logic order, explaining how and why things are the way they are, and IMO there isn't really any alternative. And that's what I wanted to suggest.
|
|
|
|
|
I have some code that I'm trying to use to create a service on a remote machine. I am doing this:
static bool CreateService() {
try {
ManagementClass classInstance = new ManagementClass("root\\CIMV2", "Win32_Service", null);
ManagementBaseObject inParams = classInstance.GetMethodParameters("Create");
inParams["DesktopInteract"] = true;
inParams["DisplayName"] = "WallRotate";
inParams["ErrorControl"] = 0;
inParams["Name"] = "WallRotate";
inParams["PathName"] = "c:\\program files\\nts\\wallrotate\\wallclient.exe";
inParams["ServiceType"] = 16;
inParams["StartMode"] = "Automatic";
ManagementBaseObject outParams = classInstance.InvokeMethod("Create", inParams, null);
Write(outParams["returnvalue"].ToString());
} catch (Exception e) {
Write(e.Message.ToString());
return false;
}
return true;
}
...and it always fails. The outParams["returnvalue"] is 23. What other options can you get from the return on InvokeMethod? I was hoping to find something a little more, I dunno.. message-like? Hehe. "23" doesn't tell me much.
Thanks!
|
|
|
|
|
Apparently, you're trying to create a service that already exists on the machine. All you had to do was read the documentation on the Win32_Service class, Create method, here[^].
|
|
|
|
|
I have a listview and two bits fields (is_active) and (in_use) but it's showing on the ListView as True or False..
I am using this code to show in the ListView:
item.SubItems.Add(sql_reader["is_active"].ToString());
item.SubItems.Add(sql_reader["in_use"].ToString());
how can I change it to show as checkbox?
|
|
|
|
|
Checkbox is only available in Detail view of a listview.
You can add a listviewitem and use its checked property.
ListViewItem sitem = new ListViewItem();
sitem.checked = sql_reader["is_active"] as bool;
item.subitems.add(sitem);
This will do the trick I think...
|
|
|
|
|
A listview only allows 1 checkbox AFAIK and only in the first column, use a datagridview if this does not meet you needs.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
how to make sure there is always an item selected in the listview even if the user clicked in the outside area?
|
|
|
|
|
This is the common behavior to most of the .NET UI controls. The selection remains when you click on another control. Only thing that you have to do, is to select for the first time..
If your intention is to show the selection to the user, you may change the background color of the item on selection.
|
|
|
|
|
Set the 'Hide Selection' property to false on the listview.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I want to know how can hide and again show a column in the listview control just like visible=true or =false?
|
|
|
|
|
AFAIK you need to remove the item when you want it invisible, and again you can add when needed.
|
|
|
|
|
Like was mentioned, you have to remove the column from the ListView to hide it, then re-add it when you want it to be visible.
|
|
|
|
|
is there any way to give a domain name then .NET will search for all created emails under that domain name?
|
|
|
|
|
jrahma wrote: is there any way to give a domain name then .NET will search for all created emails under that domain name?
Why would you need that?
I can not think of any other thing other than a SPAMMER needing this.
Manas Bhardwaj
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
First, the question is why would yo want this?
The second question is search in WHAT for these emails? Search an Outlook archive?, an SMTP server?, your own database?, ... what is storing these emails??
|
|
|
|
|
Hello,
VS 2008
I am filling the buffer with the read method in the code below, using SlimDX to capture the audio input from the microphone.
The problem I have is that the buffer will overrun. It there anyway to create a circuler buffer that once it gets to the the end it will start over again?
Many thanks for any suggestions,
private void bgwAudioInput_DoWork(object sender, DoWorkEventArgs e)
{
Int16[] samples = new Int16[8192 / sizeof(Int16)];
Int16 audioValue = 0;
int i = 0;
captureBuff.Start(true);
while (captureAudio)
{
if (!this.bgwAudioInput.CancellationPending)
{
captureBuff.Read(samples, 0, true);
audioValue = Math.Abs(samples[i++]);
this.bgwAudioInput.ReportProgress(audioValue);
}
}
}
|
|
|
|
|
Hi,
Steve1_rm wrote: The problem I have is that the buffer will overrun
Are you sure about that? It looks to me as if you are attempting to read beyond the end of the array.
Every iteration of the while loop reads data into the samples array. That's ok but eventually the indexer i has the value 4096 and the array access in the line audioValue = Math.Abs(samples[i++]); will fail.
I can't understand the meaning of audioValue and how it would relate to progress. Did you mean to report total amount of data read perhaps?
Alan.
|
|
|
|
|
Steve1_rm wrote: It there anyway to create a circuler buffer that once it gets to the the end it will start over again?
Sure, just index with i%length or i&(length-1) for powers of 2 (which you have here)
|
|
|
|
|
So i've slowly been learning c# over few months but going slow and is my first language.
One thing i would like to know, is how it would get a c# program to take data from a website then display inside the application. (Not taking data from a database)
Could anyone possible point be at examples or tell me roughly what i would have to do.
Thanks in advance,
Malcom
|
|
|
|
|
Hi,
there are a couple of ways to do that:
1.
add a WebBrowser to your form, make it navigate to your URL, then grab its DocumentText.
You could do that with a hidden WebBrowser as well.
2.
use HttpRequest and HttpResponse classes to access the web yourself.
This is faster, but a bit more complex.
FWIW: make sure to study a good book[^] on C#
|
|
|
|
|
Yeah i have heard of HttpRequest and Response. I didn't want to use a browser.
So on return of the data it is possible to display it differently. For example come up in a textbox or different controls im not really thinking of just now.
Thanks for the book recommendation, i'm looking for the best one at Amazon
|
|
|
|
|
the response is always a string, it is a text following HTML conventions.
|
|
|
|
|
Thanks for the help
|
|
|
|