Write script trouble

Hi,

I'm having a little trouble with a few things on my write to file script, firstly despite me having

out.write( "\n" );

I don't seem to be getting a new line in my .txt file, just a space equivalent to a tab.

Also I'm trying to implement an if-else loop like:

if(dataRecord.get( "LAYO" )= "-") {out.write( "0.00");}
else{out.write( dataRecord.get( "LAYO" ) + "\t" );}

However, although it isnt throwing any errors at me, it's not doing the job, it just seems to ignore it and even when my variable is "-" it still writes it out, not 0.00.

Anyone know what I'm doing wrong,

Thanks alot.

Sorry for the delay. I'm not

Sorry for the delay.

I'm not sure what might be wrong with your call to out.write("\n");...

for that if-else statement, Java requires that you use a method called "equals(someString)" when you want to compare one string to another. Using "==" is an identity comparison (it asks if string1 has the exact same address in memory as string2), and furthermore, the "=" that you've used is not comparing anything, but rather trying to assign "-" to the variable "LAYO", but that won't work for a couple of reasons.

Try this instead:


if (dataRecord.get("LAYO").equals("-"))
{
    out.write("0.00");
}
else
{
    out.write(dataRecord.get("LAYO") + "\t");
}

I would suspect that your call to "out.write("\n");" is probably not writing a tab character, but that the tab character is coming only from that if statement you had written. You can't assign "-" directly into another string, so the operation fails, and so the if statement returns "false", which in turn means that it will ALWAYS do the "else" part of the if statement. Using the ".equals" method will fix that, and will probably resolve your trouble writing out a new line character.

In addition, if you're on a Windows computer, writing "\n" won't be enough. Windows uses "\r\n" together to denote a new line. "\n" is really only for Unix/Linux computers. (And neither would work on a Mac, which requires only "\r".)

Does that help?
Tim