if (Copy1 != "")
{
Process.Start(Copy1);
}
if (Copy2 != "")
{
Process.Start(Copy2);
}
if (Copy3 != "")
{
Process.Start(Copy3);
}
17 Replies - 562 Views - Last Post: 30 January 2013 - 09:49 AM
#1
Process.Start not working within if statement
Posted 28 January 2013 - 03:17 PM
Replies To: Process.Start not working within if statement
#2
Re: Process.Start not working within if statement
Posted 28 January 2013 - 03:22 PM
#3
Re: Process.Start not working within if statement
Posted 28 January 2013 - 03:33 PM
Skydiver, on 28 January 2013 - 03:22 PM, said:
Basicly its 3 links to web sites so www.google.com,www.bing.com,www.sky.com I tried it without the if statement so just
Process.Start(Copy1) Process.Start(Copy2) Process.Start(Copy3)
and it worked but as I get the value for each from a text box an error may happen if nothing is entered
while stepping through the program each of the copy's had the correct value assigned and were opened in IE.
#4
Re: Process.Start not working within if statement
Posted 28 January 2013 - 03:36 PM
if (!String.IsNullOrWhiteSpace(Copy1)) Process.Start(Copy1); if (!String.IsNullOrWhiteSpace(Copy2)) Process.Start(Copy2); if (!String.IsNullOrWhiteSpace(Copy3)) Process.Start(Copy3);
Next - As Skydiver pointed out what are the runtime values of these variables? IE: Put a breakpoint at the first one and look.
tlhIn`toq's FAQ list
Learning to debug one's own code is an essential skill. Sadly, one that apparently few college courses teach. Silly if you ask me.
Placing breakpoints and walking through the code line by line allows you to actually WATCH it execute.
Visualizing what your code does will let you see why it behaves the way it does.
It would be well worth your time to do the tutorials on FAQ 2. A couple hours learning this skill will save you hundreds of hours of confusion in one project alone.
TOP most asked:
What does this error message mean?
FAQ 2: How do I debug
FAQ 3: How do I make Class1/Form1 talk to Class2/Form2
FAQ (Frequently Asked Questions - Updated Jan 2013
#5
Re: Process.Start not working within if statement
Posted 28 January 2013 - 03:44 PM
I did add break points and when running through the code it went through each if statement as none were = "" or nothing the value of each of the copy's so copy1,copy2,copy3 were as expected they each held the value of the link I had entered in the text boxes and when running through the program debugging it actually worked the problem is when I remove the break points and run the program only copy2 is executed.
This post has been edited by tlhIn`toq: 28 January 2013 - 07:30 PM
Reason for edit:: Don't quote the entire immediately previous message: We all see it
#6
Re: Process.Start not working within if statement
Posted 28 January 2013 - 06:46 PM
As an aside, running "foo.com" via Start.Process() is dangerous. What if instead of "foo.com", it was "format.com" or "command.com"? Remember that on your hard drive are potentially various programs with ".com" extensions and Start.Process() will call the Win32 API ShellExecute() which will prefer to run a local ".com" program over trying to find a matching website.
#7
Re: Process.Start not working within if statement
Posted 28 January 2013 - 07:34 PM
I would strongly suggest you stop looking at textboxblahblahblah.Text and start using properties. Uncouple this tight binding between code and GUI.
#8
Re: Process.Start not working within if statement
Posted 29 January 2013 - 05:19 AM
Skydiver, on 28 January 2013 - 06:46 PM, said:
As an aside, running "foo.com" via Start.Process() is dangerous. What if instead of "foo.com", it was "format.com" or "command.com"? Remember that on your hard drive are potentially various programs with ".com" extensions and Start.Process() will call the Win32 API ShellExecute() which will prefer to run a local ".com" program over trying to find a matching website.
Hi in terms of the 1st and 3rd copy being null it doesnt seem to be the case as when i step throught the program they each have the correct value assigned and even execute only when i dont debugg the program do they not its also weird that when i comment out the 2nd and 3rd copy the first executes.
In terms of using Start.Process() i am going to use this small program to launch multiple hyperlinks i have collected so in all probibility there wont be just a simple .com will be more like http://www.dreaminco...32&qpid=1792540 although i do understand your conserns just thought the Start.Process() would be easyest to use in the this instance
#9
Re: Process.Start not working within if statement
Posted 29 January 2013 - 05:36 AM
tlhIn`toq, on 28 January 2013 - 07:34 PM, said:
I would strongly suggest you stop looking at textboxblahblahblah.Text and start using properties. Uncouple this tight binding between code and GUI.
Hi i have changed it so now i have it saving to a db and reading from it into a list which asigns its values to each of the varibles so Copy1 has the value of Copy1 in the db but again while debgging the values are getting asigined and the start.process is executing each of them but if i simply run the program only one is executed its almost as if start.process is exiting before the other if staements are executed but while debiggin this isnt the case i also thought it might be something to do with how fast each of the start.process is called maby if it was to close together then the second was called before the first finished and that would be the problem but i added a time laps in each if statement but it didnt work just made my program slower lol.
#10
Re: Process.Start not working within if statement
Posted 29 January 2013 - 06:10 AM
Instead of:
Process.Start(url);
Try using this instead:
Process.Start("IExplore.exe", url);
Replace "IExplore.exe", with your browser. Put in a full path if needed.
#11
Re: Process.Start not working within if statement
Posted 29 January 2013 - 06:50 AM
#12
Re: Process.Start not working within if statement
Posted 29 January 2013 - 07:15 AM
I would use IsNullOrEmpty against controls' .Text property and String.Empty against a string variable - which cannot be null unless declared as:
Dim sSome As String? 'nullable VB string? sSome; // C#
Allowing null is really intended for use when retrieving or comparing database-data.
IsNullOrWhiteSpace I would use against a controls' Text if I want to treat just spaces (and other whitespace characters) as though the control didn't contain anything.
This post has been edited by andrewsw: 29 January 2013 - 07:19 AM
#13
Re: Process.Start not working within if statement
Posted 29 January 2013 - 07:50 AM
string? nullString; Nullable<string> nullStringAlso;
On the other hand, this is perfectly legal:
string nullString = null;
So you would still need to check for null, and hence the existence of String.IsNullOrEmpty().
#14
Re: Process.Start not working within if statement
Posted 29 January 2013 - 01:12 PM
Skydiver, on 29 January 2013 - 06:10 AM, said:
Instead of:
Process.Start(url);
Try using this instead:
Process.Start("IExplore.exe", url);
Replace "IExplore.exe", with your browser. Put in a full path if needed.
tried your suggestion and it worked first time thanks for taking the time to help.
#15
Re: Process.Start not working within if statement
Posted 29 January 2013 - 02:31 PM
Skydiver, on 29 January 2013 - 07:50 AM, said:
string? nullString; Nullable<string> nullStringAlso;
On the other hand, this is perfectly legal:
string nullString = null;
So you would still need to check for null, and hence the existence of String.IsNullOrEmpty().
@SkyDiver Thank you; my mistake. String is a reference type and nullable by default. We can do:
int? nullInteger; Nullable<int> nullIntegerAlso;
|
|

New Topic/Question
Reply




MultiQuote






|