|
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!
|
|
|
|
|
hi,
I'm just learning C# after being a Delphi coder for waayyy to long
I was wondering, why isn't it possible to use an else statement with the foreach statement?
Check out my quick and dirty demo code:
namespace ConsoleApplication
{
class Product
{
public string Code { get; set; }
public string Description { get; set; }
}
class Program
{
static void Main(string[] args)
{
IEnumerable<Product> myProductList = new List<Product>
{
new Product() {Code = "CDR", Description = "CD-Rom"},
new Product() {Code = "DVD", Description = "DVD-Rom"},
new Product() {Code = "BRD", Description = "BlueRay Disc"},
};
var myProductSelection = (from aProduct in myProductList where aProduct.Code.StartsWith("R") select aProduct);
Console.WriteLine("The products that were found:");
foreach (var aProduct in myProductSelection)
{
Console.WriteLine("Found product: " + aProduct.Code);
}
Console.ReadKey();
}
}
}
The above code returns nothing, since none of the product codes start with a "R".
Would be nice if I could do this when my result is empty:
Console.WriteLine("The products that were found:");
foreach (var aProduct in myProductSelection)
{
Console.WriteLine("Found product: " + aProduct.Code);
}
else
{
Console.WriteLine("No products were found!");
}
Just some ranting.. any good solutions to this unlike something like this?
Console.WriteLine("The products that were found:");
int x = 0;
foreach (var aProduct in myProductSelection)
{
x++;
Console.WriteLine("Found product: " + aProduct.Code);
}
if (x > 0)
Console.WriteLine("No products were found!");
thx for any suggestions offered - Life would be so much easier if I had the source code!
- If C# had true garbage collection, most applications would delete themselves upon execution
|
|
|
|
|
Ted On The Net wrote: Just some ranting.. any good solutions to this unlike something like this?
I can only think of 1 fundamentally different solution - explicitly test for the number of items in myProductSelection.
Personally I would set a bool to true in the foreach rather than counting the iterations, but that is not that much different from the solution you gave.
There is no build-in way to do this, as far as I know.
|
|
|
|
|
does myProductSelection have a count or a length? Most strucutres that implement IEnumerable do. If so just check to see if the count is greater than zero.
|
|
|
|
|
yes, it does. One could implement it like this:
if (myProductSelection.Count() != 0)
{
foreach (var aProduct in myProductSelection)
{
Console.WriteLine("Found product:" + aProduct.Code);
}
}
else
{
Console.WriteLine("No products found!");
}
But why should I? If the foreach loop doesn't get executed, I know I've got the same result as if I used the above if-statement. So imo this gives me redundant code. Or do you disagree?- Life would be so much easier if I had the source code!
- If C# had true garbage collection, most applications would delete themselves upon execution
|
|
|
|
|
Ted On The Net wrote: But why should I?
Because it expresses the intention of the code?
I.e. if there are items loop through them otherwise produce message. Regards
David R
---------------------------------------------------------------
"Every program eventually becomes rococo, and then rubble." - Alan Perlis
|
|
|
|
|
I understand why you want this, but there is no implicit way of doing it.
But, think that using foreach is a replacement for getting the enumerator, calling while(enumerator.MoveNext()) and setting a variable to enumerator.Current. (and at the end calling Dispose, if possible).
So, the best solution for this is doing something like:
using(var enumerator = enumerable.GetEnumerator())
{
if (enumerator.MoveNext())
{
do
{
var someVariable = enumerator.Current;
... the loop code...
}
while(enumerator.MoveNext());
}
else
{
... the else you want ...
}
}
And you can even create a method using delegates Action<T> for the value and non-generic Action for the else.
Something like:
ForEachOrElse(IEnumerable<T> enumerable, Action<T> actionForEachValue, action elseAction)
And to use it you call something like:
ForEachOrElse
(
enumerable,
(value) =>
{
... the code for each value...
},
() =>
{
... the code for else ...
}
); modified on Tuesday, March 9, 2010 9:34 AM
|
|
|
|
|
Well no offense, but I'm not really convinced that this is the best solution - it is rather confusing especially to people who never "manually" used an enumerator..
|
|
|
|
|
Console.WriteLine("The products that were found:");
foreach (var aProduct in myProductSelection)
{
Console.WriteLine("Found product: " + aProduct.Code);
}
else
{
Console.WriteLine("No products were found!");
}
Try this:
Console.WriteLine("The products that were found:");
int productsFound = 0;
foreach (var aProduct in myProductSelection)
{
Console.WriteLine("Found product: " + aProduct.Code);
productsFound++;
}
if (productsFound == 0)
Console.WriteLine("No products were found!");
|
|
|
|
|
Welcome
This is my first program. Sorry for my English.
My program runs some other program. Waits 10 seconds. I searched in hex 00 00 00 31 32 31 If you find it in the textbox will show the last 3 values and a search for 7 consecutive bytes. Please help
Process process = new Process();
process.StartInfo.FileName = "process.exe"
process.StartInfo.WindowStyle = ProcessWindowStyle.Minimized;
process.Start();
System.Threading.Thread.Sleep(10000);
And now do not know how to deal with and find MemoryRead
|
|
|
|
|
Did you look at ReadProcessMemory [^]?
I don't really understand what you're asking, though.
|
|
|
|
|
I want to write a program that runs another program (process.exe), waiting 10 seconds, and looks in memory (process.exe) value hex 00 00 00 31 32 31 if he finds that the value is shown 31 32 31 and another 7 value
I look to readprocessmemory but i dont understand this. Can U make for me this program?
Its something like this <a href="">http://www.codeproject.com/KB/trace/minememoryreader.aspx</a> but my program is looking for value in hex
|
|
|
|
|
So then you would be reading as much memory as you can and search for those bytes, right?
|
|
|
|
|
Yes thats right
When the program find in the memory process.exe value 00 00 00 31 32 31 xx xx xx xx xx xx xx
it displays 31 32 31 xx xx xx xx xx xx xx
|
|
|
|