|
You could use the Process.Start("http://www........") to fire off a default browser session external to the application.
|
|
|
|
|
|
Hi,
I am using Visual studio 2008.I build my application in ‘Release’ mode.It gave error while executing during some check ,But same things works fine when I execute in debugging as well if Exe is built in Debug version.
Is there any setting required in visual studio.
Regards,
Sachin
|
|
|
|
|
What error did it give you?
|
|
|
|
|
|
I would like to convert a string representing a MAC-address in one format to an other format. I thought I could use the String.Format() method to do this, but I don't get what I want.
I'm looking for this sequence flow:
Soruce: 00204A846187
Result: 00-20-4A-84-61-87
My code:
string mac1 = "00204A846187";
string mac2 = String.Format("{0:##-##-##-##-##-##}", mac1);
Console.WriteLine(mac1 + " converted to: " + mac2);
When I run that I don't get what I want. mac2 is the same as mac1 variable...
I hope I missed something because I don't want to loop through every other charecter and append "-" manually.
Any suggestions?
|
|
|
|
|
Mc_Topaz wrote: I don't want to loop through every other charecter and append "-" manually
the code to do that would be shorter than your above message is.
strings aren't the primary choice for representing data, and string.Format is pretty good at turning non-strings into a string.
having two different string representations for anyhting is to be avoided, so rather than convert I suggest you avoid the dash-less format entirely.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
You could do this with Regex.Replace[^].
The following regex will match your input (note the capture groups, will be used in the replacement):
^([0-9A-F]{2})([0-9A-F]{2})([0-9A-F]{2})([0-9A-F]{2})([0-9A-F]{2})([0-9A-F]{2})$
Next use a replacement string to put a hyphen between each of the 6 capture groups:
$1-$2-$3-$4-$5-$6
Final code which should work:
string mac1 = "00204A846187";
string pattern = "^([0-9A-F]{2})([0-9A-F]{2})([0-9A-F]{2})([0-9A-F]{2})([0-9A-F]{2})([0-9A-F]{2})$";
string replacemant = "$1-$2-$3-$4-$5-$6";
string mac2 = Regex.Replace(mac1,pattern,replacement);
|
|
|
|
|
You are taking a string and passing it to a String.Format() method where a number is expected (look at your format specifiers); no wonder you do not get the results you want. It would be simpler to use a small loop extracting successive two character substrings.
I must get a clever new signature for 2011.
|
|
|
|
|
Without a loop? how about...
string mac1 = "00204A846187";
string mac2 = mac1.Insert(10, "-").Insert(8, "-").Insert(6, "-").Insert(4, "-").Insert(2, "-");
Console.WriteLine(mac1 + " converted to: " + mac2);
...oh, and you will want to validate the length before the insert line
I may or may not be responsible for my own actions
|
|
|
|
|
Store the Mac Address as a Int64 and then use the format specifiers on the mac address.
|
|
|
|
|
mac2 = string.Format("{0:x2}-{1:x2}-{2:x2}-{3:x2}-{4:x2}-{5:x2}",
mac1.Substring(0,2),
mac1.Substring(2,2),
mac1.Substring(4,2),
mac1.Substring(6,2),
mac1.Substring(8,2),
mac1.Substring(10,2));
or
StringBuilder mac2 = new StringBuilder();
mac2.AppendFormat("{0:x2}", mac1.Substring(0,2));
mac2.AppendFormat("{0:x2}", mac1.Substring(2,2));
mac2.AppendFormat("{0:x2}", mac1.Substring(4,2));
mac2.AppendFormat("{0:x2}", mac1.Substring(6,2));
mac2.AppendFormat("{0:x2}", mac1.Substring(8,2));
mac2.AppendFormat("{0:x2}", mac1.Substring(10,2));
or
string mac2 = "";
for (int i = 0; i < mac1.Length; i++)
{
mac2 += mac1[i];
if ((i + 1) % 2 == 0 && i < mac1.Length-1)
{
mac2 += "-";
}
}
I'm sure there are other ways, and pretty much anything you come up with can be turned into an extension method.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997
|
|
|
|
|
OH WAIT! How about a MACAddress class? (The following is untested code)
public class MACAddress
{
const string separator = "-";
public int[] Octets = new int[6];
public string Mac
{
get
{
StringBuilder str = new StringBuilder();
for(int i = 0; i < Octets.Length; i++)
{
str.AppendFormat("{0:x2}", Octets[i]);
if (i < Octets.Length - 1)
{
str.Append(separator);
}
}
}
public MACAddress(string address)
{
if (ValidateAddress(ref address))
{
Parse(address)
}
}
private bool Validate(ref string address)
{
address = address.Replace("-", "").Replace(":", "").Replace(" ", "").ToUpper().Trim();
if (address.Length != 12)
{
throw new Exception("Invalid mac address specified. Must be exactly 12 valid alphanumeric characters");
}
string validCharacters = "0123456789ABCDEF";
var count = (from c in address
where !validCharacters.Contains(c)
select c).Count;
if (count > 0)
{
throw new Exception("Invalid MAC address specified. One or more invalid characters detected.");
}
}
private void Parse(string address)
{
for (int i = 10; i > 0; i-2)
{
address = address.Insert(i,":");
}
string[] parts = address.Split(":");
for (int i = 0; i < parts.Length; i++)
{
Int32.TryParse(parts[i], out Octets[i]);
}
}
}
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997
|
|
|
|
|
Way too much time on your hands; Nice answer.
|
|
|
|
|
Nice. I always implement classes or structs for custom types like this when the framework doesn't already have them.
I wasn't, now I am, then I won't be anymore.
|
|
|
|
|
I have a main form for entry purposes shown in the taskbar.
After I click on the OK button it starts a class method routine opening a status form. This should not be shown in taskbar. After doing some operation this window should automatically close.
Question:
If I switch back to my application in taskbar, I would like to get shown the status form and not the main form.
What I've tried:
1. Opening status form with ShowDialog method.
+ Switching to the application shows the status form
- All following operations are halted until status form is closed
2. Set TopMost attribute
+ switching to the application shows the status form
- Status form's always on top
3. Opening status form with Show method
+ All following operations are running afterwards
- Switching to the application shows the main window
|
|
|
|
|
Try handling the main form's Activated event and activating the status form instead.
Alternatively, adjust your design so if the user's supposed to be able to keep editing on the main form, a summary of the status is available on that form (status line? a panel that appears like Visual Studio's error pane?).
|
|
|
|
|
Hi,
From your posting I think that you want to show the main form in taskbar and not the status form when it displayed. To solve this issue try setting parent property of the status form.
Hope this helps.
Nitheesh George
http://www.simpletools.co.in
|
|
|
|
|
How can I do that?
That's how I currently control my forms.
frmMain- Form:
- Clicked event on a button creates object of an action class
clsUsage _clsUsage = new clsUsage();<br />
_clsUsage.CalcUsage();<br />
CalcUsage calls and closes the status form
frmStatus _frmStatus = new frmStatus();<br />
_frmStatus.Show();<br />
_frmStatus.Close();
|
|
|
|
|
Hi
try the following.
frmStatus _frmStatus = new frmStatus();
frmStatus.parent = this;
frmStatus.showInTaskbar = false;
_frmStatus.Show();
//doing some operations and modifying attributes to controls of frmStatus form
_frmStatus.Close();
hope this helps
Nitheesh George
http://www.simpletools.co.in
|
|
|
|
|
Not so easy because the call of the form is in my action class.
Tried the following.
private Form parentForm;<br />
<br />
public Form ParentForm<br />
{<br />
get { return parentForm; }<br />
set { parentForm = value; }<br />
}<br />
<br />
_clsUsage.ParentForm = this;<br />
<br />
_frmStatus.Parent = ParentForm;
But this creates an ArgumentException.
|
|
|
|
|
I am using following code:
dgTrans.EditingControlShowing += new DataGridViewEditingControlShowingEventHandler(dgTrans_EditingControlShowing);
private void dgTrans_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
ComboBox combo = e.Control as ComboBox;
System.Diagnostics.Debug.WriteLine(dgTrans.CurrentCell.ColumnIndex + "EditControlShowing");
if (combo != null)
{
combo.SelectedIndexChanged -= new EventHandler(dgcboDocNo_SelectedIndexChanged);
combo.SelectedIndexChanged += new EventHandler(dgcboDocNo_SelectedIndexChanged);
}
}
private void dgcboDocNo_SelectedIndexChanged(object sender, EventArgs e)
{
System.Diagnostics.Debug.WriteLine(dgTrans.CurrentCell.ColumnIndex + "SelectedIndexChanged");
string docno = ((ComboBox)sender).Text.ToString();
DataRow[] dr = myDs.Tables["DetailDocRegister"].Select("DocNo = '" + docno + "'");
int y = dgTrans.CurrentCellAddress.Y;
dgTrans.Rows[y].Cells[1].Value = dr[0]["DocTitle"];
}
But it not work properly. the first column is combobox. second is textbox, which will show the value according to what selected in combobox column. the first time select one item in combobox, it is ok. when you continue select items in second row. one error comes out.But if you select combobox column, then click another column, then select items in another row, it works.
how to solve this problem? thanks for your help.
|
|
|
|
|
In your SelectedIndexchanged event handler you appear to be trying to get the value for the text column from the underlying DataSet. When the SelectedIndexChanged event fires the new value has not yet been propagated to the DataSet. This doesn't happen until later. Definitely after the EndEdit for the combo column fires but exactly when depends on how your dgv is set up.
This may be the cause of your problems. It is difficult to be precise as you do not state clearly what 'one error comes out' means.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
I wouldn't let CG touch my Abacus!
When you're wrestling a gorilla, you don't stop when you're tired, you stop when the gorilla is.
|
|
|
|
|
thanks for your reply, henry.
The error happens here: dgTrans.Rows[y].Cells[1].Value = dr[0]["DocTitle"]; with description "Index was outside the bounds of the array". It means no result in datarow array dr[]. how to do nothing if no result in dr[]?
|
|
|
|
|
OK.
Simply test for a valid dr before trying to do anything with it.
private void dgcboDocNo_SelectedIndexChanged(object sender, EventArgs e)
{
System.Diagnostics.Debug.WriteLine(dataGridView1.CurrentCell.ColumnIndex + "SelectedIndexChanged");
string docno = ((DataGridViewComboBoxEditingControl)sender).Text.ToString();
DataRow[] dr = myDs.Tables["DetailDocRegister"].Select("DocNo = '" + docno + "'");
if (dr.Length > 0)
{
int y = dataGridView1.CurrentCellAddress.Y;
dataGridView1.Rows[y].Cells[1].Value = dr[0]["DocTitle"];
}
}
Note that I have also changed your reference to string docno = ((ComboBox)sender).Text.ToString(); this is because the DataGridViewComboBoxEditingControl has properties and methods that a plain old ComboBox doesn't. One day you might need to use them so it's a good idea to get into the habit of using the proper control now. You should also do this in your EditingControlShowing handler:
private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
DataGridViewComboBoxEditingControl combo = e.Control as DataGridViewComboBoxEditingControl;
System.Diagnostics.Debug.WriteLine(dataGridView1.CurrentCell.ColumnIndex + "EditControlShowing");
if (combo != null)
{
combo.SelectedIndexChanged -= new EventHandler(dgcboDocNo_SelectedIndexChanged);
combo.SelectedIndexChanged += new EventHandler(dgcboDocNo_SelectedIndexChanged);
}
}
Hope this helps.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
I wouldn't let CG touch my Abacus!
When you're wrestling a gorilla, you don't stop when you're tired, you stop when the gorilla is.
|
|
|
|