|
That is a trivial amount of data and any method that you come up with that doesn't have bugs will process it in a trivial amount of time.
|
|
|
|
|
Now that your specification is clear(er), I can suggest to you some architectural features of the C# code you might employ. I won't "flesh that out," since if I did I think I'd be writing commercial code for free, and that's not what CP is for. Also, I am confident that if you can code this in VBA, you can code it in C# !
Given your possible 400 lines of distilled analysis, I'd see no problem reading/parsing your data into a generic List<struct>. The struct and the List<struct> might look like this:
private struct DayTrade
{
public DateTime DateOpen;
public DateTime StartTime;
public double OpenPrice;
public double StartPrice;
public double HighPrice;
public double LowPrice;
public int SharesTraded;
}
private List<DayTrade> DayTradeList = new List<DayTrade>(); I would create the generic List, and then serialize/deserialize it to save/access the data. For serialization to XML, or binary, you could evaluate .NET's built-in facilities in System.Xml and System.Runtime.Serialization; or, you could look into using the MS DataContractSerializer Class, or you could check out Mehdi Gholam's excellent fastJSON and fastBinaryJSON libraries published here on CodeProject.
To get ready to parse the data into structs, I'd define these variables:
private char[] splitLineBreak = Environment.NewLine.ToCharArray();
private char[] splitComma = new char[] {','};
private string currentLine;
private List<string> lineList = new List<string>();
private List<string> splitLineList = new List<string>(); Steps in parsing would be:
1. split the data into lines:
lineList = data.Split(splitLineBreak, StringSplitOptions.RemoveEmptyEntries).ToList<string>(); 2. in the parsing loop:
for (int i = 0; i < lineList.Count; i++)
{
// create a new struct
DayTrade OneDaysTrade = new DayTrade();
// get the current line
currentLine = lineList[i];
// split the current line by comma
splitLineList = currentLine.Split(splitComma, StringSplitOptions.RemoveEmptyEntries).ToList<string>();
// somewhere in your parsing algorithm you are going to be using code like this:
// OneDaysTrade.DateOpen = Convert.ToDateTime(splitLineList[0]);
// OneDaysTrade.StartTime = Convert.ToDateTime(splitLineList[1]);
// OneDaysTrade.OpenPrice = Convert.ToDouble(splitLineList[2]);
//
// and so forth
// finally you are going to add the fleshed out struct to your List
DayTradeList.Add(OneDaysTrade);
} Of course your parsing code will have to handle the transition in reading the data from one day to the next, but I am sure you are already aware of how to do that, and how to create any intermediate variables required. And I'm sure you know how to compare each current day's high and low, and save the highest high, and lowest low, etc.
If you seek to aid everyone that suffers in the galaxy, you will only weaken yourself … and weaken them. It is the internal struggles, when fought and won on their own, that yield the strongest rewards… If you care for others, then dispense with pity and sacrifice and recognize the value in letting them fight their own battles." Darth Traya
|
|
|
|
|
Thanks a lot!! This is a great help!
Kind regards
Espen
|
|
|
|
|
Hi there, I am using VS2012 and .NET Framework 4.5
I am making a simple picture viewer. I have completed,
Creating a picture viewer, which has open, previous, and next buttons.
Now i was wondering how i can add in the Zoom feature into this.
What i exactly want is, according to mouse wheel movement the picture should zoom in or out corresponding to direction of rotation of the mouse wheel. Also the image should zoom in or out based on the point where the mouse pointer is currently present.
One more thing, the picture viewer is fullscreen at all time.
I hope somebody could reply soon... Thank you
|
|
|
|
|
|
Guessing for your text, you will need to built the zoom functionality yourself (Which is actually quite easy btw). Just catch the mouse scroll and recalculate the amount of pixels to show. Ie; Zoom in once; 1px becomes 4pxs etc..
|
|
|
|
|
|
CodeProject is your friend: [^], [^].
For an old (but still relevant, imho) caution against using the PictureBox to pan and zoom: [^].
If you seek to aid everyone that suffers in the galaxy, you will only weaken yourself … and weaken them. It is the internal struggles, when fought and won on their own, that yield the strongest rewards… If you care for others, then dispense with pity and sacrifice and recognize the value in letting them fight their own battles." Darth Traya
|
|
|
|
|
I'm stuck on a problem and would like your help. I have a class - “public class NmeaInterpreter” well known and written by Jon Person - , where it is sent and receive events through delegates / events:
/ / **********
public class NmeaInterpreter
public delegate void PositionReceivedEventHandler (string latitude, string longitude);
....
....
PositionReceivedEventHandler PositionReceived public event;
....
...
/ / ************
I have two more Forms( ) :
Form 2 ( ) - where I set the serial port, and sending the sentences received by GPS.
Form 1 ( ) - generally where I analyze and get the values and step formatted for a TextBox.
Although the Form1 ( ) deal with events :
/ / ****
NmeaInterpreter GPS NmeaInterpreter = new ( ) ;
public Form1 ( )
{
InitializeComponent ( ) ;
GPS.PositionReceived = new NmeaInterpreter.PositionReceivedEventHandler ( GPS_PositionReceived ) ;
}
private void GPS_PositionReceived (string latitude, string longitude )
{
TestBox.Text latitude.ToString = ();
}
/ / **************
- I cannot read or have no value in Textboxes ! Any idea?
When I debug step by step, just noticed that it ignores the methods created ...
Another thing is that if I have only one Form( ), where I treat the events and do the settings of the serial ports , it works ... but if I want to pass the data / strings from “class NmeaInterpreter” and show to another Form ( ) , does not work ! Where is the error?
Thanks for the support
Jose
|
|
|
|
|
You aren't wiring your event up with +=. So, your GPS.PositionReceived should have += after it, instead of =.
|
|
|
|
|
Greetings
Something happen with my code when I posted here. Here you are again (Form1()):
NmeaInterpreter GPS = new NmeaInterpreter();
public Form1()
{
InitializeComponent();
GPS.PositionReceived += new NmeaInterpreter.PositionReceivedEventHandler(GPS_PositionReceived);
}
private void GPS_PositionReceived(string latitude, string longitude)
{
TestBox.Text = latitude.ToString();
}
Anyway, I tested and nothing! I should receive on my TextBox the returned values. I tested the code with step info and I got the date from GPS, I receive the data in the class, but no output to my Form () TextBox.
Thank you for your reply.
Rgds
Jose
|
|
|
|
|
This would suggest that the PositionReceived event is not being fired.
|
|
|
|
|
Greetings,
Yes. But why? Whats wrong? The
public class NmeaInterpreter is a well known one, written by Jon Person, author of "GPS.NET" (www.gpsdotnet.com).
Rgds
Jose
|
|
|
|
|
How the heck would I know? Why not ask the author? He's the best placed person to answer questions about his code. He should be able to tell you why his code is not raising this event.
|
|
|
|
|
It has nothing to do with the author code. It's something I did wrong and now can not uncover. The author has done much sharing. Anyway, thank you for your reply.
Rgds
Jose
|
|
|
|
|
If you think about it, your code will be receiving this event because you have subscribed to it (tick, you have done that) and there is something in the component itself that is triggering the event. Now, this may be raised due to a combination of things that you need to set; the author is the best person to tell you under what circumstances this event is raised, and what else you need to do. As far as I can see in your code, there is absolutely nothing wrong with your syntax.
|
|
|
|
|
Nevermind, the syntax that you should be using to hook up your event is:
GPS.PositionReceived += new EventHandler(OnPositionReceived);
|
|
|
|
|
Or simply:
GPS.PositionReceived += OnPositionReceived;
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Greetings,
Just want to add the following:
If you handle events in the Form() where you have the Serial Port, and creating new TextBox on the same Form() where you have the SerialPort, I get no problem and I can read the values in the TextBox. But if you create a new Form2(), and you try to call events on this new Form2(), nothing happens when you open. Should we need to do some more when we open a new Form ()?
Rgds
Jose
|
|
|
|
|
Your code and your questions indicate to me you really need to get a good basic book on C#, and review the fundamentals of the language. Remember: that we were all confused ... once
You need to understand how you subscribe to multi-cast delegates by "hooking them up" using the += operator.
CodeProject has two articles by Jon Person, himself, on his NMEA library, and he gives working examples, like this one, of how to use his code: [^]:
public class HighPrecisionTest
{
private NmeaInterpreter MyInterpreter = new NmeaInterpreter();
private int MaximumDOPAllowed = 6;
private double CurrentHDOP;
public HighPrecisionTest()
{
MyInterpreter.HDOPReceived += new System.EventHandler(OnHDOPReceived);
MyInterpreter.PositionReceived += new System.EventHandler(OnPositionReceived);
}
If you seek to aid everyone that suffers in the galaxy, you will only weaken yourself … and weaken them. It is the internal struggles, when fought and won on their own, that yield the strongest rewards… If you care for others, then dispense with pity and sacrifice and recognize the value in letting them fight their own battles." Darth Traya
|
|
|
|
|
Greetings,
In fact I really need to have this book. But did you read the code I posted? It is exactly the same what you post, much more that I can get it working. My problem is on the following question, which apparently is not so easy, and I repeat:
If you handle events in the - lets call Form1() - where you have the Serial Port, and creating new TextBox on the same Form1() where you have the SerialPort, I get no problem and I can read the values in the TextBox (in Form1()). But if you create a new - lets call Form2()-, and you try to call events on this new Form2(), nothing happens when you open. Should we need to do some more when we open a new Form2()?
Any way to "force" the new created Form2() to run the methods?
Rgds and Thank you.
Jose
|
|
|
|
|
If you want a Form you create to have access to, and be able to use, an instance of a Class created outside the Form, you must take action to give the created Form a valid reference to the instance of the Class.
There are several ways to do that; here's an example of one way:
In the Form(s) you create define a Public Property that will hold a valid reference to the NMEA Class:
// in created Forms
// enable access
using NmeaInterpreter;
// to hold reference to instance of NmeaInterpreter
Public NmeaInterpreter theNMEAInterpreter { get; set; }
In the Form that creates the instance of the NmeaInterpreter, at the point where you have a valid reference to an instance of the NmeaInterpreter called 'myInterpreter, and you create the new Form:
// rough sketch of code
NMEAUsingForm newNMEAUsingForm = new NMEAUsingForm();
// insert the reference to the instance of NmeaInterpreter
newNMEAUsingForm.theNMEAInterpreter = myInterpreter;
At this point any method in the created Form(s) can access, and use, the instance of the NmeaInterpreter.
If you seek to aid everyone that suffers in the galaxy, you will only weaken yourself … and weaken them. It is the internal struggles, when fought and won on their own, that yield the strongest rewards… If you care for others, then dispense with pity and sacrifice and recognize the value in letting them fight their own battles." Darth Traya
|
|
|
|
|
Greetings BillWoodruff,
Thanks for the reply. I am learning.
The question here is slightly different than is proposed.
Please See:
I have a class : public class NmeaInterpreter (well known);
I have a Form2() : where dealing with Serial Ports , and sending NMEA sentences from the GPS module to the class NmeaInterpreter ;
Now I have the main Form1() : where I should get the values (Lat, Longit, North, South, etc.), in TextBoxs ;
How it works:
1. After configuring the Serial Ports, I go out/hide the Form2(Serial Port) , and return to Form1 (main)
2. In main - Form1() - , I should receive sentences formatted sentences in the TextBox .
- Problems:
a) If I create in the Form2(Serial Port), a TextBox to test, I can easily receive, for example " Latitude ", etc.
b) But in Form1(main), where I should deal with events, I cannot do this (and I should receive direct formatted sentences from Class NmeaInterpreter).
Through the "Step Into", I noticed that I get the values in the constructor - public Form1() - but then leaves without sweeping methods. This is what the problem is!
c ) Why it works on Form2(Serial Ports ) and not on Form1(main)?
d ) Any error in the structure built ?
Well, I would like to thank the patience and your support
Jose
|
|
|
|
|
I assume your problem is, that you send the NMEA sentences to a different instance of the NmeaInterpreter than you hooked up your event handler to.
- You should create only one NmeaInterpreter instance in Form1.
- Hook up your event handler there.
- Pass a reference of the NmeaInterpreter instance to Form2 either as constructor parameter or by using a property as already demonstrated by someone else.
- Then you can further adapt the settings and pass the NMEA sentences in Form two.
- Now you should receive the result in the event handler in Form1.
If that doesn't work, you could still consider storing the NMEA sentences in some List and passing them back to Form1. Then you can can send them to the NmeaInterpreter instance from Form1 and receive the result.
The good thing about pessimism is, that you are always either right or pleasently surprised.
|
|
|
|
|
Are you the same person, named Jose, who is also Member jfxdasilva [^], and who previously posted an almost identical question: [^] ?
If you seek to aid everyone that suffers in the galaxy, you will only weaken yourself … and weaken them. It is the internal struggles, when fought and won on their own, that yield the strongest rewards… If you care for others, then dispense with pity and sacrifice and recognize the value in letting them fight their own battles." Darth Traya
|
|
|
|
|