|
what isnt working? what does not happen that you expect it too? is your application crashing? are you getting any error messages? or any error messages that you have caught?
please explain your problem more, rather than posting alot of code and saying it does not do what you want it to.
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
I dont have any error message.
I want to run the code by showing file path d:\\a.txt insted of input each of values from screen.
|
|
|
|
|
wwwxyz wrote: I dont[sic] have any error message.
You would if you actually caught your exceptions properly.
This code is wrong on so, so many levels. Firstly, try posting code that actually BUILDS before asking why it doesn't WORK! It does not work because it is SH!T.
Secondly, when you OPEN a stream it is considered good practice maybe even mandatory, to CLOSE THE FIN STREAM YOU MINDLESS TW@T!
Next let us look at variable names. Have you been programming in ZxSpectrum BASIC for the last 30 years? You can use descriptive cariable names you Muppet!
Structure? Heard that word before? Who puts an entire program into a constructor? Retarded MF's, that's who!
It took me about 30 sec to get this to work and output (as expected?) but then I have not been in a coma for the last eight years.
Now go away or I shall flame you!!!
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
good use of insults
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
I suffer from insomnia. Some nights I can't sleep at all and so lay awake all night.
As I lay there I listen to the soft elephantine breathing of my beloved, the hushed night time police sirens and I think to myself. I think about life, love, work, knowledge. All sorts of thing.
But most of all, I think "Why-oh-why can't someone, anyone, post a question in the codeproject programming forums about programming, rather then questions that show their ignorance."
This is normally followed by 'What would be a good flame for...'
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
I think im missing alot of fun when im asleep
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
You've been attending the John Simmons School of Charm, haven't you?
Dude, I know John can be a bit harsh, but ... DAMN! Put down the flame thrower and step away slowly.
|
|
|
|
|
Dave Kreskowiak wrote: Put down the flame thrower and step away slowly
Ain't gonna happen. Not while no bubba's callin me dude it ain't...
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
wwwxyz wrote: I dont have any error message.
Then how do you know it's not working?
"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 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
I am not to be able to make oneself understood.
Original code is works that is first my sended the code.
But I want to convert it as secondly my sended the code then it isnt works
|
|
|
|
|
JFC! I gave you the answer already; or at least told you how to advance.
1) Issolate the problem.
Find where it is going wrong and try to bebug it.
2) Your method input, which is crap, does not update the return value. Change the signature to:
private bool input(ref double fx,
ref double ft,
ref double alpha,
ref int n,
ref int m)
And call it somit like:
ok = input(ref fx,
ref ft,
ref alpha,
ref n,
ref m);
Don't change anything and compile. What do you see? Come on, you can do it! A few debug statements in the code and you'll soon see that the whole is method is a steaming puile of doo doo.
Personally, I would remove all the try/catch code and see what happens. then I would add try/catches where needed. This means you have to actually test your code for invalid input and/or data but it won't take long.
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
firstly thanks for your helps
Error:'hard.Program.input(ref double, ref double, ref double, ref int, ref int)': not all code paths return a value
using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.IO;
namespace hard
{
class Program
{
static void Main(string[] args)
{
Program app = new Program();
}
Program()
{
bool ok = false;
double[] w = new double[25];
double[] l = new double[25];
double[] u = new double[25];
double[] z = new double[25];
double ft = 0.0, fx = 0.0, alpha = 0.0, h = 0.0, k = 0.0, vv = 0.0, t = 0.0, x = 0.0;
int n = 0, m = 0, m1 = 0, m2 = 0, n1 = 0, flag = 0, i1 = 0, i = 0, j = 0 ;
ok=input(ref fx,ref ft,ref alpha,ref n,ref m);
if (ok)
{
m1 = m - 1;
m2 = m - 2;
h = fx / m;
k = ft / n;
vv = alpha * k / (h * h);
for (i = 1; i <= m1; i++) w[i - 1] = F(i * h);
l[0] = 1.0 - 2.0 * vv;
u[0] = vv / l[0];
for (i = 2; i <= m2; i++)
{
l[i - 1] = 1.0 - 2.0 * vv - vv * u[i - 2];
u[i - 1] = vv / l[i - 1];
}
l[m1 - 1] = 1.0 - 2.0 * vv - vv * u[m2 - 1];
for (j = 1; j <= n; j++)
{
z[0] = w[0] / l[0];
for (i = 2; i <= m1; i++)
z[i - 1] = (w[i - 1] - vv * z[i - 2]) / l[i - 1];
w[m1 - 1] = z[m1 - 1];
for (i1 = 1; i1 <= m2; i1++)
{
i = m2 - i1 + 1;
w[i - 1] = z[i - 1] - u[i - 1] * w[i];
}
}
output(ft, x, m1,ref w, h);
}
}
private double F(double X)
{
double f;
f = 0.3061 * X * X -2.1286*X+38.11;
return f;
}
private bool input(ref double fx, ref double ft, ref double alpha, ref int n, ref int m )
{
try
{
FileStream fs = new FileStream("d:\\a.txt", FileMode.Open);
StreamReader sr = new StreamReader(fs);
List<string> lines = new List<string>();
String line;
while ((line = sr.ReadLine()) != null)
{
lines.Add(line);
}
try
{
fx = double.Parse(lines[0]);
ft = double.Parse(lines[1]);
alpha = double.Parse(lines[2]);
m = Int32.Parse(lines[3]);
n = Int32.Parse(lines[4]);
}
catch { }
}
catch (Exception e)
{
Console.WriteLine("Exception in ShowFile: {0}", e);
}
}
public void output(double ft, double x, int m1, ref double[] w, double h)
{
System.IO.StreamWriter oup;
System.IO.TextWriter tmp = Console.Out;
Console.WriteLine("Choice of output method.");
Console.WriteLine("1. Output to screen");
Console.WriteLine("2. Output to text file");
int flag = Convert.ToInt32(Console.ReadLine());
if (flag == 2)
{
Console.WriteLine("Sample: D:\\1.txt");
string name = Console.ReadLine();
try
{
oup = new System.IO.StreamWriter(name);
Console.SetOut(oup);
write(ft, x, m1, ref w, h);
oup.Close();
}
catch (System.IO.IOException expc)
{
Console.WriteLine(expc.Message + " file dont extract.");
}
}
else
{
write(ft, x, m1, ref w, h);
}
}
private void write(double ft, double x, int m1, ref double[] w, double h)
{
Console.WriteLine("I\tX(I)\tW(X(I),{0:#.#})", ft);
for (int i = 1; i <= m1; i++)
{
x = i * h;
Console.WriteLine("{0:#.##}\t{1:#.###}\t\t{2:#.###}", i, x, w[i - 1]);
}
}
}
}
</string></string>
|
|
|
|
|
Correct, now WHY?
The return value is not being set. You were supposed to work that one out.
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
Dude, yer spittin' into the wind. All that's gonna happen is you'll end up with spit all over yourself. Nothing else will change.
We are CodeProject of Borg. Assistance is futile.
"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 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
I know. I like to help, I really do. The problem is, well you know EXACTLY what the problem is.
So I've resolved to trying to prod them in the right direction. Using an electrified cattle stick. As the average intelligence comes out around duckweed, one has to derive what little pleasure is available.
In other news, it is now afternoon here and the Gin should be kickiing in around about now.
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
Dumbest mistake I've seen all day.
What happens when you use a function which is not a void?
The function has to return something eg:
private bool rawr()
{
bool returnObject = false;
...
return returnObject;
}
It's not rocket science it just common sense!
hmmm pie
modified on Saturday, March 14, 2009 6:56 AM
|
|
|
|
|
Thanks everyone!
finally code:
using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.IO;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Program app = new Program();
Console.ReadLine();
}
Program()
{
bool ok = false;
double[] w = new double[25];
double[] l = new double[25];
double[] u = new double[25];
double[] z = new double[25];
double ft = 0.0, fx = 0.0, alpha = 0.0, h = 0.0, k = 0.0, vv = 0.0, t = 0.0, x = 0.0;
int n = 0, m = 0, m1 = 0, m2 = 0, n1 = 0, flag = 0, i1 = 0, i = 0, j = 0;
input(ref ok, ref fx, ref ft, ref alpha, ref n, ref m);
if (ok)
{
m1 = m - 1;
m2 = m - 2;
h = fx / m;
k = ft / n;
vv = alpha * k / (h * h);
for (i = 1; i <= m1; i++) w[i - 1] = F(i * h);
l[0] = 1.0 - 2.0 * vv;
u[0] = vv / l[0];
for (i = 2; i <= m2; i++)
{
l[i - 1] = 1.0 - 2.0 * vv - vv * u[i - 2];
u[i - 1] = vv / l[i - 1];
}
l[m1 - 1] = 1.0 - 2.0 * vv - vv * u[m2 - 1];
for (j = 1; j <= n; j++)
{
z[0] = w[0] / l[0];
for (i = 2; i <= m1; i++)
z[i - 1] = (w[i - 1] - vv * z[i - 2]) / l[i - 1];
w[m1 - 1] = z[m1 - 1];
for (i1 = 1; i1 <= m2; i1++)
{
i = m2 - i1 + 1;
w[i - 1] = z[i - 1] - u[i - 1] * w[i];
}
}
output(ft, x, m1, ref w, h);
}
}
private double F(double X)
{
double f;
f = 0.3061 * X * X - 2.1286 * X + 38.11;
return f;
}
private void input(ref bool ok, ref double fx, ref double ft, ref double alpha, ref int n, ref int m)
{
try
{
FileStream fs = new FileStream("D:\\1.txt", FileMode.Open);
StreamReader sr = new StreamReader(fs);
string[] lines = new string[10];
string line;
int i = 0;
while ((line = sr.ReadLine()) != null)
{
lines[i++] = (line);
}
fx = double.Parse(lines[0]);
ft = double.Parse(lines[1]);
alpha = double.Parse(lines[2]);
m = Int32.Parse(lines[3]);
n = Int32.Parse(lines[4]);
}
catch (Exception e)
{
Console.WriteLine("Exception in ShowFile: {0}", e);
}
ok = true;
}
public void output(double ft, double x, int m1, ref double[] w, double h)
{
System.IO.StreamWriter oup;
System.IO.TextWriter tmp = Console.Out;
Console.WriteLine("Choice of output method.");
Console.WriteLine("1. Output to screen");
Console.WriteLine("2. Output to text file");
int flag = Convert.ToInt32(Console.ReadLine());
if (flag == 2)
{
Console.WriteLine("Sample: C:\\Data\\1.txt");
string name = Console.ReadLine();
try
{
name = name.Replace(@"\", @"\\");
oup = new System.IO.StreamWriter(name);
Console.SetOut(oup);
write(ft, x, m1, ref w, h);
oup.Close();
}
catch (System.IO.IOException expc)
{
Console.WriteLine(expc.Message + " file dont extract.");
}
}
else
{
write(ft, x, m1, ref w, h);
}
}
private void write(double ft, double x, int m1, ref double[] w, double h)
{
Console.WriteLine("I\tX(I)\tW(X(I),{0:#.#})", ft);
for (int i = 1; i <= m1; i++)
{
x = i * h;
Console.WriteLine("{0:#.##}\t{1:#.###}\t\t{2:#.###}", i, x, w[i - 1]);
}
}
}
}
|
|
|
|
|
You really don't need to post the code every frakking time you put up a message.
"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 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
Calm down, Chris has just ordered a couple of extra 250 TB dirve racks for when the next term starts.
And now sport, Gin 3 Tonic 2. Gin goes onto to meet Liver in the next round.
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
Hi,
I'm trying to write a service that runs only in safe mode,
for that i need to figure out if I'm in safe mode or not,
how do i do that in c# ? (i cant use System.Windows.Forms.SystemInformation.BootMode since i'm in a service and no forms)
Thanks
Aviad.
|
|
|
|
|
aviadqwerty wrote: i cant use System.Windows.Forms.SystemInformation.BootMode since i'm in a service
I doubt that. Why would it be impossible to add a reference to ths System.Windows.Forms DLL and use the SystemInformation.BootMode enum? you don't need a GUI to do that. Have you tried it, what happened?
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
Hello! I am following this guide about switching background wallpaper via a windows service http://www.codeproject.com/KB/cs/C__Wallpaper_Switcher.aspx[^] but cant get it right.
My service is up and running (it do other things så of that I am certain) but the background wont just change. If I try exactly the same code in a win form app it works (and SystemParametersInfo returns 1) but not in my service (SystemParametersInfo returns 0). Has Vista something to do with it, security limitations? Is it posible to get better error messages from SystemParametersInfo?
|
|
|
|
|
Don't ask here, it's not our code. Any qiestion regarding an article should be posted on the article. It's really quite a clever idea - you ask the person who wrote it why you're having a problem.
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
Well then maybe I can change my question a bit? Regardless of the article, how do I change the background image within a windows service? I have search the web for hours now and all code are variations of the code as shown in the article (pretty much c# to me and this is a c# forum, right?)...
[DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern Int32 SystemParametersInfo(UInt32 uiAction, UInt32 uiParam, String pvParam, UInt32 fWinIni);
private static UInt32 SPI_SETDESKWALLPAPER = 20;
private static UInt32 SPIF_UPDATEINIFILE = 0x1;
/.../
SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, @"C:\...\test.bmp", SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE);
Works perfectly in win forms in vista but not in my service of some reason.
|
|
|
|
|
It's a service. You shouldn't be able to access the UI from a service.
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|