I have been creating this program for a while now.. its a program that scans my works network IP's to see there hostnames.. and remove ip addr that does not have any host names.. but the program keeps crashing... The program crashes when I enter an IP address that does not have a hostname.. Can someone point me on the right direction Also.. Please forgive the way I coded it... I'm still learning.. and I'm still reading tutorials on a daily basis. Anyways.. I added the codes in a pastebin.. also any recommendations on the program would be helpfull.
here is the link to the codes... http://pastebin.com/823524
P.S: Unless you want me to post it here.. I will.

Program Crashes.
netleon
Ahoapap
Hmm... on a quick look the code seems correct. What error are you getting and where
Conde_tkd
raaj_001
BigWinston
string[] strings = list.ToArray();
CheckBox[] chk = new CheckBox[strings.Length];
for( int x = 0; x < strings.Length; x++ )
{
if( Regex.IsMatch( strings[x], @"^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$" ) == false )
{
MessageBox.Show( "There is an error in your Input" );
}else{
if( strings[x] != null )
{
try {
this.Cursor = Cursors.WaitCursor;
IPHostEntry ipHostEntry = Dns.GetHostEntry( strings[x].ToString());
chk[x] = new CheckBox();
chk[x].Location = new Point( 10, 30 * x );
chk[x].Size = new Size( 350, 40 );
chk[x].Text = ipHostEntry.HostName;
pnl2.Controls.Add( chk[x] );
}catch( Exception exc ) {
MessageBox.Show( exc.Message, "TestDNS", MessageBoxButtons.OK, MessageBoxIcon.Exclamation );
}finally {
this.Cursor = Cursor;
}
}
}
I keep getting the same debugging box as before... just with a different message. but shouldnt the try/catch work
Joeku
Mike Sage
string[] strings = list.ToArray();
for( int x = 0; x < strings.Length; x++ )
{
if( strings[x] != "" && strings[x] != null )
{
try {
IPHostEntry ipHostEntry = Dns.GetHostEntry( strings[x].ToString());
chk[x] = new CheckBox();
chk[x].Location = new Point( 10, 30 * x );
chk[x].Size = new Size( 350, 40 );
foreach(IPAddress ipAddress in ipHostEntry.AddressList)
{
chk[x].Text = ipHostEntry.HostName;
}
}catch( Exception e ) {
chk[x].Text = strings[x];
}
pnl2.Controls.Add( chk[x] );
}
}
------- edit --------
Oh I see.. ok Will try it out.
Kev Wu
Tonnie
This is probably in line 165, not 164. Your CheckBox array (chk) is only 10 elements in size. If you specify more than 10 addresses as input you get this error. You need to recreate the chk array to have the same size as the strings array:
Ed209
Alvin Kuiper
Same here as Mike Said,
I also ran it and provided some IP Addressses and did not have any crash!!!
Secondly I wonder you are using a text editor to write the code and C# Compiler to compile and run..... Its really weird for me to wirte some small application in 10x time all with hand. Why dont you download free C# Express Editon it supprts almost everything a hobbiest developer needs!
Please dont wait to get it from here for free:
http://msdn.microsoft.com/vstudio/express/visualcsharp/
Best Regards,