|
Thank you for the detailed responses! I think I'll give your "Simple Way" a shot since I'm already doing most of that stuff anyway and I can make it work with a fixed string length.
Thank you very much!
|
|
|
|
|
I've been looking through some code with the Reflector, and I've kept seeing things like if (this <= null) and if (obj > null) etc
In MSIL the code was this:
L_0001: ldarg.0
L_0002: ldnull
L_0003: cgt.un
Well huh? What is going on here? What is it supposed to do? Is it just a weird way to check whether something is null ? But then why check this ?
The code looks as if it was produced by an F# compiler. Is it just that the F# compiler is being lame?
|
|
|
|
|
I don't know about F# but in C# the (this <= null) doesn't compile.
So yeah I guess the F# compiler is a little wierd.
|
|
|
|
|
Hi,
I am reading a text file successfully with the code below but the result is rounding down instead of rounding up I have tried to use Math.Ceiling to resolve this issue and have now come unstuck. Appreciate the help.
[Description("Displays Levels")]
public class MyCustomIndicator2 : Indicator
{
#region Variables
private string path = Cbi.Core.UserDataDir.ToString() + "PIn.txt";
private int[] levels;
private int count = 0;
private string readText = "";
private int roundedValue;
private int diff = int.MaxValue;
private int tmp, res = 0;
#endregion
protected override void Initialize()
{
CalculateOnBarClose = true;
Overlay = true;
PriceTypeSupported = false;
levels = new int[100000];
}
protected override void OnBarUpdate()
{
readText = File.ReadAllText("C:\\PIn.txt");
int roundedValue = ((int)Math.Ceiling(Close[0]));
string [] split = readText.Split(new Char [] {';'});
foreach (string s in split)
{
count++;
tmp = int.Parse(s);
levels[count] = tmp;
if (tmp > roundedValue)
{
if(diff == null)
diff = roundedValue;
if ((tmp - roundedValue) < diff)
{
res = tmp;
diff = tmp - roundedValue;
}
}
}
Print(res);
}
#region Properties
#endregion
}
}
Regards,
suprsnipes
|
|
|
|
|
The relevant code is missing - what is Close and how is it filled?
|
|
|
|
|
I have just tried your code and it finds the smallest number greater than X, where X is a float that I invented. Check your values to see where the discrepancy is. I also think the statement(s)
if(diff == null)
diff = roundedValue;
should read
if(diff == 0)
diff = roundedValue; txtspeak is the realm of 9 year old children, not developers. Christian Graus
|
|
|
|
|
"If you have to include code, include the smallest snippet of code you can."
You really should only need to include
int roundedValue = ((int)Math.Ceiling(Close[0]));
and tell us the input and output values.
|
|
|
|
|
Hi again,
3.
if(diff == null) diff = roundedValue; is redundant (assuming it would compile, which it won't)
4.
levels = new int[100000]; will make it fail for a file with > 100000 numbers.
|
|
|
|
|
Luc Pattyn wrote: if(diff == null) diff = roundedValue; is redundant (assuming it would compile, which it won't)
Hm, it compiles fine on VC# Express 2008, just gives a warnimg that the expression always evaluates to false .txtspeak is the realm of 9 year old children, not developers. Christian Graus
|
|
|
|
|
Indeed, it does. But it shouldn't, as the types are incompatible and the equality test is doomed to fail.
|
|
|
|
|
You're right of course, so why does my compiler allow it, even at warning level 4? Now my program won't work, and yet the error is not obvious. I wonder if this happens in the full Visual Studio version? txtspeak is the realm of 9 year old children, not developers. Christian Graus
|
|
|
|
|
Richard MacCutchan wrote: I wonder if this happens in the full Visual Studio version?
I don't know, yet I am unaware of any difference, other than functionality, between them. I also assume it is the same csc.exe compiler after all (which is part of .NET, not of VS).
|
|
|
|
|
When you say you've tried using Math.Ceiling to resolve the issue, what were you using before? Some rounding functions use the acccountacy standard, where odd number round up and even round down (or the other way round) - is that what you were experiencing?Regards,
Rob Philpott.
|
|
|
|
|
Hi,
Yes but the code doesn't appear to do what I intended. I had to change the code because I was trying to compare an int to a double and when I made the appropriate changes the output was incorrect.
I then looked into trying to achieve what I require another way. I have managed to get the text document into a list and now need to create a loop function to compare the double value of Close[0] to find the nearest value within the list above the Close[0] which is what I have been researching today.
As a newbie I apologise for not having a very good understanding of C# but I'm having a crack and I'm sure as time goes by I will be better equipped.
Appreciate the help,
suprsnipes
|
|
|
|
|
I am try to Implement a graphical Password system .Can anyone help me with writing C# to implement Robust Discretization.
|
|
|
|
|
A quick Google woul dhave helped you: Robust Discretization[^].Tychotics
"The dinosaurs became extinct because they didn't have a space program. And if we become extinct because we don't have a space program, it'll serve us right!"
Larry Niven
|
|
|
|
|
But.. but.. but.. the number one hit is this thread!!! ARGH, infinite loops.
|
|
|
|
|
Hello people,
I have the following problem.
I have a class with a property like in the below example:
class myClass:INotifyPropertyChanged
{
private string theProp;
public string TheProp
{
get{ return theProp; }
set
{
if( string.IsNullOrEmpty(value) )
theProp = "Another Value";
else
theProp = value;
NotifyPropertyChanged("TheProp");
}
}
}
So in case an empty or null is set I set the internal value of the property to a default string.
The object is doing this just fine. But the problem I have is with a textBox that is bound to this property. When I delete the text in the textbox, the textbox does not represent the different value.
Probably I'm doing something wrong with the binding, it seems like a common way to set a different value, so I suppose there must be a way to make this work.
thanks for any help you might provide.
Davy
|
|
|
|
|
public partial class Form1 : Form
{
myClass o = new myClass();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
this.textBox1.DataBindings.Add("Text", o, "TheProp", false, DataSourceUpdateMode.OnPropertyChanged, string.Empty);
}
}
class myClass : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private string theProp;
public string TheProp
{
get { return theProp; }
set
{
if (string.IsNullOrEmpty(value))
theProp = "Another Value";
else
theProp = value;
NotifyPropertyChanged("TheProp");
}
}
private void NotifyPropertyChanged(String info)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(info));
}
}
}
|
|
|
|
|
Thanks!
It works like a charm now...
I had set the databinding via the Visual Studio GUI using a BindingSource.
Apparantly it doesn't set the parameters exactly the same way. Setting the binding myself the way you showed made it work.
Greetings,
Davy
|
|
|
|
|
Hello,
I am new to C# and I was wondering how does one verify the prescence of the back end of a database? I am using my app as the front end for an MS access database. As an expert in VBA this was easy and you could call the windows dialog to find the backend.
Any help is greatly appreciated.
Art
|
|
|
|
|
2010JohnFByers wrote: verify the prescence of the back end of a database
Just try connecting to it.
2010JohnFByers wrote: call the windows dialog to find the backend.
Any help is greatly appreciated.
Art
So then you don't even have a connection string yet?
What are you asking?
|
|
|
|
|
That depends on how you communicate with the backend (if I have undertsood you correctly).
For instance, if you were to use Linq2Sql there is a "DatabaseExists" method which will return a boolean denoting that the database has a valid connection and is available (or not).
I'm sure there are plenty of other ways to do this but this might get you started.Tychotics
"The dinosaurs became extinct because they didn't have a space program. And if we become extinct because we don't have a space program, it'll serve us right!"
Larry Niven
|
|
|
|
|
I looked into Linq DatabaseExists code with Reflector, and actually it just tries to connect to the database and returns false if an exception is thrown.
|
|
|
|
|
Yes I am looking to verify that the backend exists and if not shutdown the app. I may be misunderstanding this but the reason I want to do this is that if you establish a connection to the backend and for some unknown reason it isn't there you would get an error. Actually I'd like to know what is done programnmatically to prevent errors when the backend isn't available etc. for a dataset and its binding?
Thanks!
|
|
|
|