|
string Price = double.Parse(((Label)DataList1.Controls[0].FindControl("PriceLabel")).Text).ToString("0.00");
I Love T-SQL
Don't torture yourself,let the life to do it for you.
|
|
|
|
|
Saba02 wrote: why this error occured?
because
1) double.Parse(...) returns a double
2) string Price = expects a string
Saba02 wrote: what do i do now?
get your act together.
|
|
|
|
|
Saba02,
Two things. You are assigning a string with a double. And you should also use TryParse();
Label priceLabel = DataList1.Controls[0].FindControl("PriceLabel") as Label;
double price = double.TryParse(priceLabel.Text);
Regards,
Gareth.
|
|
|
|
|
gareth111 wrote: double price = double.TryParse(priceLabel.Text);
your intentions are good, your syntax isn't.
The documentation tells differently.
|
|
|
|
|
|
Hi Gareth,
no problem!
|
|
|
|
|
Hi!
I am using MS Visio control in an application developed in C# (for .Net 1.1). I have a class MyAppContext that extends ApplicationContext . The application is started by calling Application.Run(myAppContext) where myAppContext is an instance of class MyAppContext .
The problem I face, is this, only under Vista, if a form containing Visio control is initialized, a NullRefrenceException is thrown. However, if I load the same form before initializing myAppContext, it works fine.
The same code works under XP and Windows 2003. I have also used 'Run as Administrator' option in Vista but the result is same.
Does anyone have a clue, what should I do to fix this problem?
|
|
|
|
|
Kashif Iqbal Khan wrote: a NullRefrenceException is thrown
by whom? at what line? catch the exception, look at its ToString() output, tell
Visual Studio to always show line numbers, and identify the faulty line.
A wild guess: you did something that is not thread-safe, your XP machine is single core
so it runs fine nevertheless, and your Vista machine is dual core, so it is bound to fail.
As I said, this is just a guess.
|
|
|
|
|
Thanks for your prompt reply.
The exception stack trace shows that it is thrown somewhere in AxHost class. Unfortunately, I am not at my work place right now, so cannot attach the exact StackTrace. But will update as soon as I get it.
To explain further, I am writing the code flow that is something like as follows
<br />
<br />
VisioForm f = new VisioForm();<br />
f.Show();<br />
f.Close();<br />
<br />
MyApplicationContext c = new MyApplicationContext; <br />
Application.Run( c );<br />
<br />
<br />
There is a button on MainForm that has the same code as mentioned in Line 1-3 above in its click event. Now If I comment the code as in Line 1-3, the application will crash if the button on main form is clicked. But works fine, if I leave it there.
More interestingly, If the lines 1-3 are moved between line 4 and 5, the application will still crash with the same message.
This makes me believe that there is something wrong when using ActiveX controls inside a custom application context on Vista.
|
|
|
|
|
Hi,
I have some remarks, not sure how relevant they are:
1. are you sure about your f.Show f.Close sequence? it shows then hides the form, without
waiting for anything? or did you mean ShowDialog()?
2. I would put everything in one big try-catch as in:
try {
... all about VisioForm
... all about MyApplicationContext
} catch(Exception exc) {
Console.WriteLine(exc.ToString());
}
that will catch everything in the main thread that you may have forgotten to catch
elsewhere. Note the ToString, it is important to see the entire exception.
3.
Are you manipulating apartment models? is everything STAThread? MTAThread?
Maybe the Visio stuff needs it to be STAThread. I don't know the details, I do know
it often is an issue when using COM.
4.
Are you using the same version of Visio on both machines?
|
|
|
|
|
Thanks for all your effort.
1. Yes, it is form.Show() and form.Close(). This is actually a work around to make the application work on Vista. After placing these lines, VisioForm opens fine whenever the button on MainForm is clicked.
2. The code does has try-catch. Problem is I cannot get my form open. I will put the exception log here.
3. Main module has STA Attribute.
4. Yes.
Actually if I open and close the form containing Visio control (Line 1-3 in my previous post), before application context initialization, my application works fine on Vista. but If I remove these lines, it starts crashing whenever the VisioForm is initialized.
|
|
|
|
|
Hi Guys. I have an opendiledialoge. If I click Cancel then the whole project closses. Any idea how I can set it to return to the main form if the user clicks on cancel instead of having the whole app closing??
Here is the code.
if (openFileDialog1.ShowDialog() != DialogResult.OK)
{
this.Close();
}
Excellence is doing ordinary things extraordinarily well.
|
|
|
|
|
I have solved it.
I set it as follows:
if (openFileDialog1.ShowDialog() != DialogResult.OK)
{
return;
}
Excellence is doing ordinary things extraordinarily well.
|
|
|
|
|
|
Ah, that was a good laugh.
"I told my app to close, and it closes; but I don't want it to close, how do I get it not to close? (Help urgent please)" 
|
|
|
|
|
He figured it out and fixed it. Obviously not a Hlp Urgnt Pls at all, just a beginner. Just like you and I were
Jon
Smith & Wesson: The original point and click interface
|
|
|
|
|
Oh I wasn't laughing at him in particular. 
|
|
|
|
|
Hi,
You can use the below also.
if (openFileDialog1.ShowDialog() == DialogResult.Cancel)
return;
Regards,
Charith
Charith Jayasundara
|
|
|
|
|
Hi,
IMO the best way is by testing for a positive, as in:
if (openFileDialog1.ShowDialog() == DialogResult.OK) {
} }
That way, if for whatever reason something other than OK and Cancel gets returned,
nothing will happen.
I tend to avoid negative tests, they tend to confuse people sometimes.
|
|
|
|
|
Hi Luc. I used to have it that way but then for some reason the openfiledialog would show again if you selected the file and clicked on OK. When I changed it to a negative test then it worked fine.
Thanks for taking the time to help and reply. It is greatly appreciated. Someday I will be able to help the guys out as well and be a great programmer like most of the guys here.
Excellence is doing ordinary things extraordinarily well.
|
|
|
|
|
Hi,
Kwagga wrote: for some reason the openfiledialog would show again
Seeing the dialog more than once cannot depend on how you formulate the condition;
it would need either a loop (for, while, ...) or the method being called more than once.
|
|
|
|
|
This is code from another project I am working on. This is where the openfiledialoge is opened twice instean of once.
private void btnOpenFix_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
txtboxFixed.Text = openFileDialog1.FileName;
}
if (openFileDialog1.ShowDialog() == DialogResult.Cancel)
this.Close();
Now that I know how to resolve this in one code statement I can fix it.
So, I would rather have it like this:
private void btnOpenFix_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() != DialogResult.OK)
{
return;
}
else
txtboxFixed.Text = openFileDialog1.FileName;
}
Excellence is doing ordinary things extraordinarily well.
|
|
|
|
|
Ah, see? You're calling ShowDialog twice.
You could store the result in a local variable:
DialogResult res = openFileDialog1.ShowDialog() ;
if ( res == DialogResult.OK ) ... ;
if ( res == DialogResult.Cancel ) ... ;
or use a switch:
switch ( openFileDialog1.ShowDialog() )
{
case DialogResult.OK : ... ; break ;
case DialogResult.Cancel : ... ; break ;
}
|
|
|
|
|
Hi,
adding to what PIEBALD told you, I find it rather strange that your program would
do something when CANCEL is clicked; normally cancel means "don't do anything, since I have
changed my mind". This also means you should NOT close the form itself.
I trust the above is part of the Microsoft recommendations for a Graphical User Interface.
|
|
|
|
|
Hi all,
I used this code for computing total price<b></b> of all item that customer ordered them:
public Double total <br />
{<br />
get<br />
{<br />
double t;<br />
if (items == null)<br />
{<br />
return 0;<br />
}<br />
foreach (cartitem Item in items)<br />
{<br />
t += Item.Totalline;<br />
}<br />
return t;<br />
}<br />
} but this error occured when i run above code:
Use unassigned local variable 't'
Now where i should define 't'?
Hoda
|
|
|
|