|
I am a new programmer in C#, so I hope there is an easy answer for this problem.
I need to declare an array of class objects, and the code compiles fine, but I always get the runtime exception "Object reference not set to an instance of an object." When I single step through the code, the exception is thrown when the array declaration statement is executed. I have tried the same declaration, but for a single instance rather than an array, and it works fine. I can step through the constructor and see that all the variable are created properly.
Below are the two statements that I have used. I try the array declaration, and it bombs. The single instance works great. Any suggestions on what I am doing wrong? I can provide more details if needed.
Parameter[] yearsArray = new Parameter[yearsOfData];
Parameter yearArray = new Parameter();
Steve
|
|
|
|
|
Steve Searcy wrote:
Parameter[] yearsArray = new Parameter[yearsOfData];
This declares an array. All items on the array are null (yearsArray[0], yearsArray[1]... yearsArray[yearsOfData]).
You need to assign new instances to them in a loop.
Yes, even I am blogging now!
|
|
|
|
|
hi
how to control in a datagrid header .....
i mean want to add aheader to group of columns
suppose u have "First Name","Last Name" headers and u want to group them under a toal header "Personal Information" for example..
does any one kow how to do that !!??
|
|
|
|
|
Hi All,
With my datagrid I want different Column Headers to have different Colors?
There are global settings e.g
tableStyle.HeaderFont = Color.Green;
but I'm after soming like :
tableStyle.Columns[1].HeaderFont = Color.Green;
tableStyle.Columns[2].HeaderFont = Color.Blue;
I'm using C#. I'm aware of 3rd Party tools that can do this, but want to avoid them if possible.
Any help would be very much appreciated,
Thanks, Jonny
|
|
|
|
|
Hi,
Is anyone know how to write automatic updates like windows automatic updates ?
Thank
|
|
|
|
|
|
Hi all,
i made a two combobox i fill the first one from database and i take the selected value from the first combobox to select another recorde from table but it got me an exception
"The column prefix 'System.Data' does not match with a table name or alias name used in the quer"
and this my code:
<br />
SqlDB DB = new SqlDB();<br />
DB.ConStr = DB.ConnectionSTR(DB.Current_DB());<br />
DataSet ds = DB.Select("Select * From MSA Where Client_ID = "+cboClient_Name.SelectedValue.ToString()+"");<br />
cboMSA_ID.DataSource = ds;<br />
cboMSA_ID.DisplayMember = "Table.MSA_Effective_Date";<br />
cboMSA_ID.ValueMember = "Table.MSA_ID";<br />
SqlDB contain the database handling (command , connection...)
please help
|
|
|
|
|
Does anybody know of any way to perform a string contains string check without using regex.
For example
string s1 = "abcdefg";
string s2 = "def";
string s3 = "xyz";
bool b1 = StringContains(s1, s2);
bool b2 = StringContains(s1, s3);
bool StringContains(string baseString, string searchString)
{
?????
}
post.mode = postmodes.signature;
SELECT everything FROM everywhere WHERE something = something_else;
> 1 Row Returned
> 42
|
|
|
|
|
Forget it, I just found the IndexOf() function
post.mode = postmodes.signature;
SELECT everything FROM everywhere WHERE something = something_else;
> 1 Row Returned
> 42
|
|
|
|
|
Hi gurus,
I have a simple question about formatting strings.
I would like to know how I can convert an hex value to the character itself?
we give the string "3a" and the formatting says ";".
how to do that in C#? the %x format is unknown to C#
thanks.
best regards.
There is no spoon.
|
|
|
|
|
Use int.ToString()
If you have : int a = 0x3a;
The result of a.ToString("X") is "3A"
Ami
|
|
|
|
|
thanks for the trick.
I use the Convert class
Convert.ToString(Convert.ToChar(int.Parse(txtCharacter.Text, System.Globalization.NumberStyles.HexNumber)));
It's heavy but it does what I want. If things can be simpler, let me know.
There is no spoon.
|
|
|
|
|
A little heavy? That's an understatement...
Like Ami said...
myInt.ToString("X")
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
what do you mean by "understatement"? you mean I've done the same in an other way?
There is no spoon.
|
|
|
|
|
The code you came up with is needlessly complex, doing multiple conversions that are both redundent and useless. Your code converted a text property to an int, back to a string, then broke that into an array of chars, then converted that back to a string again.
All you had to do is dive into the documentation on .ToString() and it would have made your life so much easier. It probably would have taken you the same amount of time to read that and come up with the correct answer to your problem as it did to try everything under the sun and come up with the bastardized statement you posted.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Dave Kreskowiak wrote:
It probably would have taken you the same amount of time to read that and come up with the correct answer to your problem as it did to try everything under the sun and come up with the bastardized statement you posted.
When there are 8,000+ classes (or whatever it's up to now) that probably happens more often than not to some degree.
- Nick Parker My Blog | My Articles
|
|
|
|
|
I developed a SMS application, I use a timer to pool the modem every now and then for new responses if a response is found I launch an ResponseReceived event, then that event looks for the type of response, then when a new message is detected I launch the NewMessageReceived event from the ResponseReceived event. The main application receives this event and opens a new dialog window, but the problem is that it does not show the window. I can see the window in the taskbar but not on the screen. I tried forcing the window to show, go topmost, maximize, every thing, but no window. I suspect that this could be due to threading of the timer or something, can anyone help?
Leon v Wyk
|
|
|
|
|
Leon v Wyk wrote:
I suspect that this could be due to threading of the timer or something, can anyone help?
You're right: see the docs for the InvokeRequired property, and you'll understand more. Simply put, you can only do UI tasks on the main thread. There's an "Invoke" method and an "InvokeRequired" property on all controls and forms that ease things for you.
Yes, even I am blogging now!
|
|
|
|
|
Thank you so much! How do I send variables to the method that I invoke?
<br />
private delegate void NewSMSReceived();<br />
protected void OnNewSMSReceived()<br />
{<br />
int Position = 1;<br />
Solutions.Gsm.Modem.SMSMessageReceive SMS = Gsm.ReadSms(Position,true);<br />
SMSReceivedForm NewSMS = new SMSReceivedForm(SMS);<br />
NewSMS.ShowDialog();<br />
}<br />
private void Gsm_NewSMSReceived(object sender, Being.IT.Solutions.Gsm.Modem.NewSMSEventArgs e)<br />
{<br />
lbInfo.Text = "New SMS received @ "+ DateTime.Now.ToString();<br />
Solutions.Multimedia.SoundPlayer.Play(Application.StartupPath+@"\NewSMSNotify.wav");<br />
<br />
this.BeginInvoke( new NewSMSReceived( this.OnNewSMSReceived) );<br />
<br />
<br />
}<br />
Leon v Wyk
|
|
|
|
|
Leon v Wyk wrote:
//e.StoragePosistion
this.BeginInvoke( new NewSMSReceived( this.OnNewSMSReceived) );
This becomes (I removed all the 'this.', I find it weird):
Invoke(new MethodInvoker(OnNewSMSReceived), new object[] { your variables go here });
Other alternative would be using properties, since you're on different threads, but will be invoking methods on the same object ('this.').
Yes, even I am blogging now!
|
|
|
|
|
I just want to know if its possible to do the following, but first, some background. I have a com dll which I connect to through C#. The dll has a connect property which is the first method you call. This method attempts to locate an electricity server. I want to find out if I can stop this method from executing after a certain period of time if no server is found within that time limit. The dll has no settings to set a timeout, and the people who make the dll are to "busy" to do anything about it. It does throw an Exception when it does not connect, but this is after about 20 seconds, and I would prefer this to be around 5. Please let me know how to do this if this can be done.
|
|
|
|
|
I've tried stopping COM objects before (in C++, not in C#), and all I can say is that it's simply not reliable if you do it in-process (e.g., loading a DLL). I tried creating the object in another apartment, asynchronous COM calls, aborting the threads, etc, and nothing was reliable enough. After a while instability started to happen.
The only reliable way I found was using out of process COM servers (.exe), so as I killed the process, the OS done all the cleanup needed. I suggest you to load this dll in a surrogate process and kill it when you need to cancel the call.
I know that starting and stopping processes in Windows is not a fast task, but in some cases, it can be fast enough for what you need.
Yes, even I am blogging now!
|
|
|
|
|
Got an web application where users can select applications they would like to use. They can choose several applications. The choices i want to store in a database. A table with fields like userid, appname. The combination of the two can occur only once.
I can of course use an insert statement and loop for the number of applications but i was wondering if .net has a better way. Something like filling up a dataset and passing the dataset to a insert method.
Glad to hear some suggestions.
|
|
|
|
|
I am implementing a UI for debugger, and trying to do a step mechanism where the current source code line is highlighted (its background is colored).
So basicly I am trying to set a background for the selected text (only).
Any ideas?
Thanks,
Orly
|
|
|
|
|
I believe that the RichTextBox is fast enough for a debugger, so I would suggest you to use it, as it's easy to change colors, fonts, etc, of the text.
Yes, even I am blogging now!
|
|
|
|