|
Hey i have two function fun1 and fun2...
fun1()
{
Console.WriteLine("Before Call of fun2");
fun2(9);
Console.WriteLine("After Call of fun2");
}
fun2(int a)
{
if(a<10)
return;
Console.WriteLine(a);
}
Now the question is that.when a<10 it returns, i want when a<10 it returns from fun2 as well as from fun1.
when a<10 Output should be
[Before Call of fun2]
Note that. there should not be any new variable in fun1.
is there any solutin for that..
thanks
|
|
|
|
|
hotthoughtguy wrote: is there any solutin for that..
No.
The only way to do this would be to move the "After call of fun2" message into the end of fun 2. Or duplicate the a<10 check in fun1 as well.
Simon
|
|
|
|
|
The best way that comes to mind to do this would be to make fun2 return a boolean. You could then check the return value in fun1 and continue or exit depending on the return value from fun2.
|
|
|
|
|
Hi,
instead of return, throw an exception and make sure you catch it where you want it to land.
|
|
|
|
|
Great Idea Luc Pattyn
thanks a lot. Your have solved my no of problems thanks again
|
|
|
|
|
you're welcome.
|
|
|
|
|
Go with Gideon not Luc.
Exceptions are for exceptional situations ie. events that you cannot control and would probably lead to the program halting. The one you describe is not exceptional i.e. it's one that depends on the logic of your code rather than something outside of it.
But then again I'm just an old fuddy-duddy who thinks that way.
|
|
|
|
|
Hi All,
Iam using FTPWebRequest for downloading the files...
Here, the function is working good. but while downloading the file, if the internet connection goes down, then this program going to throws the exception and end the process. So, in this scenario i want to pause/resume downloading...
How to acheive this...
If anybody knows help me...
thanks
Here my sample code
-------------------
public void Download(string fileName)
{
//Desc: To download the file from the ftp server
FtpWebRequest reqFTP;
try
{
//fileName = <<Name of the file to be createdNeed not name on FTP server. name name()>>
FileStream outputStream = new FileStream(downloadPath + "\\" + fileName, FileMode.Create);
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + ftpServerIP + ftpPath + "/" + fileName));
reqFTP.Method = WebRequestMethods.Ftp.DownloadFile;
reqFTP.UseBinary = true;
reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword);
FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
Stream ftpStream = response.GetResponseStream();
long cl = response.ContentLength;
int bufferSize = 2048;
int readCount;
byte[] buffer = new byte[bufferSize];
readCount = ftpStream.Read(buffer, 0, bufferSize);
while (readCount > 0)
{
outputStream.Write(buffer, 0, readCount);
readCount = ftpStream.Read(buffer, 0, bufferSize);
}
reqFTP.Abort();
ftpStream.Close();
outputStream.Close();
response.Close();
}
catch (Exception ex)
{
Utils.Write(ex.Message);
}
}
Thanks & Regards
Kumaran
|
|
|
|
|
You can't pause and resume the download, but you can start a new download and start it from a certain point. Have a look at the ContentOffset property of the FtpWebRequest object. Also you can find examples of this just by Googling for "ftpwebrequest resume download".
|
|
|
|
|
I cant get it right... why this doesnt work :S:S
string b = "3.12312123";
if ((b[0] == '2' || b[0] == '3' || b[0] == '4' || b[0] == '5') && ((textBox2.Text != "703") || (textBox2.Text != "733")))
{
this.Text = "OK";
}
else
{
this.Text = "NOT OK!";
}
Any ideas?
Regards,
Matjaž
|
|
|
|
|
I can't be sure what you mean by not working, but that condition will always be true because of this:
((textBox2.Text != "703") || (textBox2.Text != "733"))
The textBox2 text will never be equal to both 703 and 733.
As an aside, you seem to be doing number comparisons, so I would recommend using number variables instead of strings. You could then test (b >= 2 && b < 6)
|
|
|
|
|
Okeeei...
So, i want to check... if its enetered only 703 or 733... BESIDES that the b starts with 2,3,4 or 5.
I really dont know how to make this thing to work... maybe i jsut have a bad day and am a bit confused... but yet again... i dont understand it
Please help? :/
Regards,
Matjaž
|
|
|
|
|
Matjaž Grahek wrote: i want to check... if its enetered only 703 or 733
I have no idea what the condition is.
a) Do you want this.text = "OK" if text = 703 or 733?
b) or do you want this.text = "Not Ok!" if text = 703 or 733?
int textVal = 0;
int.tryparse(textbox2.text, out textVal);
if(textVal == 703 || textVal==733)
{
this.Text = "ok";
this.Text = "Not Ok";
}
Matjaž Grahek wrote: b starts with 2,3,4 or 5
here is a simple solution to that:
int val = 0;
int.tryparse(b[0].ToString(), out val)
this should help,
Prateek
|
|
|
|
|
This code
((textBox2.Text != "703") || (textBox2.Text != "733"))
will always be true
Regards,
Lev
|
|
|
|
|
well,
((textBox2.Text != "703") || (textBox2.Text != "733"))
will always evaluate to true for starters.
Regards,
Rob Philpott.
|
|
|
|
|
|
Hi,
if you don't understand why a statement behaves the way it does, then the only good advice is to write simpler statements. Why do you insist on putting everything in a single line? Chop it into smaller pieces and look at the intermediate values, that will help you understand if and how it works.
As for the 703/733 thing, as all the others already told you, that cannot possibly be what you intended. For what value do you think it will evaluate to false?
|
|
|
|
|
Well, my intention was ...
If the first character of the string was 2,3,4 or 5 the it should also check the textbox if there is entered any of the two mentioned values (703 or 733).
Ok, looking at it this way... maybe it could work with two ifs...
Regards,
Matjaž
|
|
|
|
|
if (b[0] == '2' || b[0] == '3' || b[0] == '4' || b[0] == '5')
if((textBox2.Text != "703") || (textBox2.Text != "733"))
{
this.Text = "OK";
}
else
{
this.Text = "NI OK!";
}
ok... this doesnt work either:S
Regards,
Matjaž
|
|
|
|
|
Matjaž Grahek wrote: ((textBox2.Text != "703") || (textBox2.Text != "733"))
Guy, for the last time, this will ALWAYS evaluate to True. How about change that "or" to an "and"??
if ((textbox2.Text != "703") && (textbox2.Text != "733"))
|
|
|
|
|
It doesn't work because you haven't changed the logic.
Scott P.
"Simplicity carried to the extreme becomes elegance."
-Jon Franklin
|
|
|
|
|
class Program {
static void Main(string[] args) {
string b = "3.12312123";
if ((b[0] == '2' || b[0] == '3' || b[0] == '4' || b[0] == '5') && ((args[0] == "703") || (args[0]== "733"))) {
Console.WriteLine("OK");
} else {
Console.WriteLine("NOT OK!");
}
}
}
Merry Christmas.
"Simplicity carried to the extreme becomes elegance."
-Jon Franklin
|
|
|
|
|
Your problem displays the most common failure of beginning programmers -- mixing their 'AND' and their 'OR' logic.
You also need to think of how to address your other requirement that the text begin with 2,3,4, or 5.
A possible solution is first to write what you want out in text
if b starts with a valid number and textbox contains valid numbers then it's ok.
That leads to code such as this:
string b = "3.12321212";
List<char> validValues = new List<char> { '2', '3', '4', '5' };
List<string> validInput = new List<string> { "703", "733" };
textbox1.Text = "Not OK";
if ( validValues.Contains( b[0] ) && validInput.Contains( texbox.Text ) )
{
textbox1.Text = "OK";
}
Another way you can also address this problem is with RegEx but I don't have the time to figure out the pattern.
|
|
|
|
|
Ok... thank you all for your answers. Will try this tommorow. Again, thanks for your patience and the will to help.
Good night
Regards,
Matjaž
|
|
|
|
|
Hello
I have just updated a control in my project and cannot access the Design panel because of teh following error:
ResX file Could not load file or assembly 'Xceed.Chart.Core, Version=4.2.100.0, Culture=neutral, PublicKeyToken=ba83ff368b7563c6' or one of its dependencies. The system cannot find the file specified. Line 7585, position 5. cannot be parsed. ---> System.Xml.XmlException: Could not load file or assembly 'Xceed.Chart.Core, Version=4.2.100.0, Culture=neutral, PublicKeyToken=ba83ff368b7563c6' or one of its dependencies. The system cannot find the file specified. Line 7585, position 5. ---> System.IO.FileNotFoundException: Could not load file or assembly 'Xceed.Chart.Core, Version=4.2.100.0, Culture=neutral, PublicKeyToken=ba83ff368b7563c6' or one of its dependencies. The system cannot find the file specified.
File name: 'Xceed.Chart.Core, Version=4.2.100.0, Culture=neutral, PublicKeyToken=ba83ff368b7563c6'
Where do i delete the bad reference?
The program works but i cannot edit the GUI because of the error.
I am using VS2008 SP1
is there a workaround?
Thanks
Have a nice Day
|
|
|
|