|
Thanks for all your responses
Is there a way where I can change the .MaxValue Property?
Presently it displays in MM/DD/YYYY(12/31/9999 11:59 PM).
Can I set it to DD/MM/YYYY(31/12/1999).
|
|
|
|
|
Do we have any event for Paste where I can trigger and reformat the Date and paste it in the control ?
|
|
|
|
|
You didn't specify WPF, Windows Forms or ASP.NET or ...
If you're going to use a "date picker", you need to "learn it" before "looking around" for "other" solutions.
This may help; also note the reference to "system settings".
c# - Getting date from DatePicker in format yyyy/MM/dd - Stack Overflow
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Thank you for your suggestions.
I have achieved it using ParseExact function with some formatting the DateTime value.
Thanks
Sharan
|
|
|
|
|
Hi
if you are into privacy, freedom of speech and like things like Tor or whatsApp then read on because I want to build a network unlike one ever built before that is sort of a mix between Bitcoin, Tor, WhatsApp that is decentralized and uses Sept256k security (Pinched from Bitcoin) to send messages or requests for services around the world.
The services provided by other nodes on this new network could be anything from file storage to proxy servers or even highly encrypted messages delivered to email type services so the network itself become plugable using internal packages that look something a bit like socket addresses but instead of the IP-Address we use the public key of host service followed by the well known name of the service.
abcdef1234567-32-bit-key-abcdef:DNS
abcdef1234567-32-bit-key-abcdef:Proxy
abcdef1234567-32-bit-key-abcdef:Mail
This project will be open source and might even include a type of "Gas" at a future date with the apps talking to to the main network entry nodes using sockets with encrypted data (Will need ASE key) or decrypted data can then be pumped down the network pipe depending on how the entry node (Windows .EXE) has been configured.
Please PM me if you are interested or have any thoughts on the subject.
|
|
|
|
|
Wrong forum - try here: Collaboration / Beta Testing Discussion Boards[^]
But ... unless you spell out what part you will play in this, and what you expect a collaborator to add then don;t expect much in the way of responses.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Well i would say I am the best guy for writing the network component but would be happy to be proven wrong so its hard to disuse formal rolls or requirements at this point in time because I am very open to suggestion and kind of like equal partners myself.
Hidden away from the main forum might be the reason I don't get much of a response I suspect if anything but thank you for your comments !
|
|
|
|
|
stopthespying wrote: Please PM me if you are interested or have any thoughts on the subject. Be mega big bucks involved?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I like your style so I will hand my thoughts over to you and let you pay me instead not that I really care much for money having lived a full life already
Signed
The string butcher.
|
|
|
|
|
Not likely.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I have installed C# 2008 express and use a local database to create tables and show the contents in a DataGridView which show a table I have created. My problem is I have two table that are joined and I would like to show a view in the DataGridView is this possible.
|
|
|
|
|
Yes, assuming you have two tables which share a common value.
For example, an Invoice would be two tables:
Invoices
ID INT, IDENTITY
Issued DATE
Company NVARCHAR(256)
InvoiceLines
ID INT, IDENTITY
InvoiceID INT, FOREIGN KEY to Invoices.ID
Product NVARCHAR(256)
Value MONEY Then you might retrieve data like this:
SELECT i.ID, i.Date, i.Company, il.Product, il.Value
FROM Invoices i
JOIN InvoiceLines il ON il.InvoiceID = i. ID And you would get the appropriate rows in the DGV
Or
SELECT i.ID, i.Date, i.Company, il.Total
FROM Invoices i
JOIN (SELECT InvoiceID, SUM(Value) AS Total
FROM InvoiceLines
GROUP BY InvoiceID) il
ON il.InvoiceID = i. ID And you would get invoice detail and total value
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
I think you can do this using table joints in a dataset and then binding that and not the table to the grid but it's been a long time since I did this.
Top credit for using an old version of visual studio and I try to stick with using VS2010 because it runs much faster and cleaner than 2017 that I only use when forced too.
|
|
|
|
|
Really struggling with these fairly simple thing.
I have some sensor values randomly generated from a class I call Sensor.cs. I use GeAnaloValues() method to get these values and display them in a text box i Form1.cs in the GUI. Now I need to make moving average filter and take moving average of the for example last 5 sensor values displayed on the screen.
I just don't know how to implement these values generated from the method GetAnalogValues() in the moving average algorithm ?
I also wonder if I should make a separate class for the implementation of the MA-Filter?
This is my code:
Form1.cs class
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Xml.Linq;
using System.Windows.Forms;
using System.Globalization;
namespace DAQ_Simulator
{
public partial class Form1 : Form
{
int counter;
int count_lines;
System.Timers.Timer t;
int LoggingTime=56;
int LogTimeLeft;
float SamplingTime = 5.9f;
private int clickcounter;
private DateTime datetime;
private DateTime datetime2;
private DateTime NextLoggingTime;
int maxAI = 7;
int maxDI = 3;
int maxSid = 9;
String sTxt;
String sTxt1;
Sensor[] sObj = new Sensor[10];
MA_Filter[] fObj = new MA_Filter[10];
public Form1()
{
InitializeComponent();
for (counter = 0; counter < maxSid; counter++)
{
sObj[counter] = new Sensor(counter);
}
}
private void displaySensorData(object sender, EventArgs e)
{
}
private void groupSampl_Enter(object sender, EventArgs e)
{
}
private void textSampling_TextChanged(object sender, EventArgs e)
{
}
private void btnSampling_Click(object sender, EventArgs e)
{
clickcounter++;
if (clickcounter == 1)
{
textSensorValues.Text = "TimeStamp AI.1, AI.2, AI.3, AI.4, AI.5, AI.6, AI.7, DI.1, DI.2, DI.3" + "\r\n";
}
if (SamplingTime <= 0)
{
SamplingTime = SamplingTime + 5.9f;
}
if (SamplingTime <= 5.9f && SamplingTime >= 0)
{
btnSampling.Enabled = false;
}
timer1 = new System.Windows.Forms.Timer();
timer1.Tick += new EventHandler(timer1_Tick);
timer1.Interval = 1000;
timer1.Start();
datetime2 = DateTime.Now.AddSeconds(5).AddMilliseconds(900);
String time2 = datetime2.ToString("HH:mm:ss.FFF", CultureInfo.InvariantCulture);
textSampling.Text = time2;
sampling();
}
private void groupLogg_Enter(object sender, EventArgs e)
{
}
private void txtLogging_TextChanged(object sender, EventArgs e)
{
}
private void labelLoggingText_Click(object sender, EventArgs e)
{
}
private void btnLogging_Click(object sender, EventArgs e)
{
if (LoggingTime == 0)
{
LoggingTime = LoggingTime + 56;
}
if (LoggingTime <= 56 && LoggingTime >= 0)
{
btnLogging.Enabled = false;
}
timer2 = new System.Windows.Forms.Timer();
timer2.Tick += new EventHandler(timer2_Tick);
timer2.Interval = 1000;
timer2.Start();
txtLogging.Text = LoggingTime.ToString();
NextLoggingTime = DateTime.Now.AddSeconds(4);
String time3 = NextLoggingTime.ToString("HH:mm:ss.FFF", CultureInfo.InvariantCulture);
txtLogging.Text =time3;
Logging();
}
private void labelSensorValues_Click(object sender, EventArgs e)
{
}
private void textSensorValues_TextChanged(object sender, EventArgs e)
{
}
private void timer1_Tick(object sender, EventArgs e)
{
SamplingTime--;
txtNextSamplingTime.Text = SamplingTime.ToString("F2")+"sec";
if (SamplingTime <= 0)
{
timer1.Stop();
btnSampling.Enabled = true;
txtNextSamplingTime.Clear();
}
}
private void sampling()
{
datetime = DateTime.Now;
textSensorValues.Text += datetime.ToString("HH:mm:ss.FFF", CultureInfo.InvariantCulture) + " ";
for (int id = 0; id < maxAI; id++)
{
double AnalogSensorValues = sObj[id].GetAnalogValue();
sTxt = AnalogSensorValues.ToString("F3");
textSensorValues.Text += sTxt + " ";
}
for (int id = maxSid - maxDI; id < maxSid; id++)
{
int DigitalSensorValues = sObj[id].GetDigitalValue();
sTxt1 = DigitalSensorValues.ToString();
textSensorValues.Text += " " + sTxt1 + " ";
}
textSensorValues.Text += "\r\n";
}
private void helpToolStripMenuItem_Click(object sender, EventArgs e)
{
}
private void Logging()
{
count_lines = textSampling.Lines.Length;
txtNumberWritings.Text = count_lines.ToString();
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
using (Stream s = File.Open(saveFileDialog1.FileName,FileMode.CreateNew))
using (StreamWriter sw = new StreamWriter(s))
{
sw.WriteLine(textSensorValues.Text);
textFilePath.Text = string.Format("{0}", openFileDialog1.FileName);
}
textFilePath.Text = saveFileDialog1.FileName.ToString();
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void richTextBox1_TextChanged(object sender, EventArgs e)
{
}
private void folderBrowserDialog1_HelpRequest(object sender, EventArgs e)
{
}
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
}
private void timer2_Tick(object sender, EventArgs e)
{
LoggingTime--;
txtNextLogg.Text = LoggingTime.ToString()+"sec";
if (LoggingTime <= 0)
{
timer2.Stop();
btnLogging.Enabled = true;
txtNextLogg.Clear();
txtNextLogg.Text = "56 sec";
}
}
private void label3_Click(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
}
}
}
My Sensor class where I generate my random values:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DAQ_Simulator
{
public class Sensor
{
double AnalogVal;
int DigVal;
int sId;
Random rSensVal;
Random digSensVal;
public Sensor(int id)
{
sId = id;
rSensVal = new Random(id);
digSensVal = new Random(id);
AnalogVal = 0.0F;
}
public double GetAnalogValue(double minAnalogVolt=0.00F,double maxAnalogVolt=1.00F)
{
if(minAnalogVolt <= AnalogVal && AnalogVal<= maxAnalogVolt)
AnalogVal = rSensVal.NextDouble();
return AnalogVal;
}
public int GetDigitalValue(int digMin = 0, int digMax = 1)
{
DigVal = digSensVal.Next(0,2);
return DigVal;
}
public int GetSensId()
{
return sId;
}
}
}
|
|
|
|
|
For starters, don't use two Random instances:
rSensVal = new Random(id);
digSensVal = new Random(id);
Because they are initialized with the same value, they will have the same sequence - use a single instance (or better a single static instance) and you will get a "more random" set of values. You might want to consider using the parameterless version of the constructor, which uses the system clock as the seed value so it gives a different sequence each time your app runs.
For a moving average, just add an array of values the same size as the group, an index, and a count. This will become a basic queue.
So for five values, you would have five elements:
private double[] samples = new double[5];
private int index = 0;
private int count = 0; Then its just a case of a simple method:
private double GetMovingAverage(double newValue)
{
if (count != samples.Length) count++;
samples[index++] = newValue;
if (index == samples.Length) index = 0;
double sum = 0.0;
for (int i = 0; i < count; i++)
{
sum += samples[i];
}
return sum / (double) (count);
}
And you are done.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
OriginalGriff, a bit confused in terms how I should implement the code you gave me here to my program?
I am assuming that method GetMovingAverage() shall be in the main class Form1.cs, correct ?
Also I tried to put in your code snippet, but what is newValue here?? Is that my AnalogValues?
I have a series of "random" sensor values every time I click Sampling button.
I tried to do something like this
private double GetMovingAverage(double AnalogValue)
{
if (count != samples.Length) count++;
samples[index++] = AnalogValue;
if (index == samples.Length) index = 0;
double sum = 0.0;
for (int i = 0; i < count; i++)
{
sum += samples[i];
}
return sum / (double)(count);
}
I tried to print the Moving average values here,
for (int id = 0; id < maxAI; id++)
{
double AnalogSensorValues = sObj[id].GetAnalogValue();
sTxt = AnalogSensorValues.ToString("F3");
textSensorValues.Text += sTxt + " ";
txtFilterValues.Text = fTx1;
txtFilterValues.Text = GetMovingAverage(id).ToString("F3");
}
However when I printed to my Filter text box, I got rubbish
I must have misinterpreted what you meant.
My main problem is I don't know how I get those values inside the moving average.
Any comments ?
|
|
|
|
|
You should give your actual Analogue-Value to the Method from OG (as it's parameter) and you will get the Average-Value as Result back from this method.
The Variables 'Count' and 'Samples' and 'Index' must be declared outside this method ...
|
|
|
|
|
Nice, but how about ditching the loop? Just add the newValue to the sum (as a member, not local) each time, then deduct the number which it replaces in the array and you've just reduced the algorithmic complexity.
I know, I'm just in one of those picky moods today.
Regards,
Rob Philpott.
|
|
|
|
|
Yeah, but he seems to be a beginner, so I thought I'd make it as obvious as possible.
I'd probably make it a MovingAverage<T> class in my code, and complicate it that way!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Yes I am a beginner
Now I made some slight changes and I am getting average of the last 5 numbers, but still my problems is not solved
When I generate my Sensor values in the text box , they appear like this:
TimeStamp AI.1 AI.2 AI.3 AI.4 AI.5 AI.6 AI.7
13:29:05.091 0.726 0.249 0.771 0.294 0.816 0.338 0.861
13:30:40.325 0.817 0.111 0.404 0.698 0.991 0.284 0.962
13:31:19.709 0.768 0.467 0.166 0.865 0.564 0.263 0.915
13:32:00.943 0.558 0.772 0.985 0.198 0.412 0.625 0.594
13:32:31.391 0.206 0.658 0.109 0.560 0.012 0.463 0.720
What happens is that program calculates average of the last five numbers in the text box which means in this case Moving Average=(0.109+0.560+0.012+0.463+0.720)/5=0.373.
While the moving average for example for AI.1 would be:(0.726+0.817+0.758+0.558+0.206)/5=0.615
This is obviously Wrong as I am getting average of the values from different sensors.
I need average of the last five values for Sensor AI.1, AI2,....etc
So I need to make some more changes to get this done.
Here is the code I have changed:
No changes to your method:
private double GetMovingAverage(double newVal)
{
if (count != samples.Length) count++;
samples[index++] = newVal;
if (index == samples.Length) index = 0;
double sum = 0.0;
for (int i = 0; i < count; i++)
{
sum += samples[i];
}
return sum / (double)(count);
}
The method was implemented like this:
for (int id = 0; id < maxAI; id++)
{
double AnalogSensorValues = sObj[id].GetAnalogValue();
sTxt = AnalogSensorValues.ToString("F3");
textSensorValues.Text += sTxt + " ";
txtFilterValues.Text = fTx1;
txtFilterValues.Text = GetMovingAverage(AnalogSensorValues).ToString("F3");
}
modified 15-Feb-18 7:44am.
|
|
|
|
|
If you want separate moving averages, then you want to set up separate values stores - the array in my code is what you need for a single sensor, for t=five sensors you need five arrays.
The way I would do it is to set up a MovingAverage class, with its own count, index, and array, and move the method to that.
Then in your "main code" you create five instances of the MovingAverage class and use one for each sensor.
Does that make sense? (Remember, I don't know what "level" of beginner you are! )
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
I am a complete beginner, started with C# like days ago.What you are saying makes sense , but another thing is how to do it?
What confuses me generally are arrays, I have noticed I find working with those challenging right now.

|
|
|
|
|
If you are having difficulty with arrays, then you probably need to shelve this project for a while - a week or two maybe - and focus on learning the basics before you continue to work on it.
Classes, arrays, and so forth are the "Building blocks" of the language, and you really do need to understand them properly before you get much beyond "Hello world!"
If you don't, then you will end up with something that works - probably - but you have no real idea of how or why, and that means that it becomes unmaintainable which is very bad news!
I can't teach you classes - there is far too much for a little text box like this, and I can't see when your eyes start to glaze over - and the only other way to do this is to have arrays of arrays, and several arrays of integers, which gets extremely clumsy and hard to read very, very quickly.
Seriously: go back to your book - or your course - and follow it through. trying to jump ahead to "the interesting stuff" just leaves huge holes in your knowledge that makes more complicated things very difficult to work out.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
There is also another way to build this Average without using an array - but the base-problem is the same : it is necessary to know what the code does and how it works.
Independant from this - here is another Code-Solution :
int CountAct = 0;
double ValueLast = 0;
public double getAverage(double actValue, int Smoothing)
{
if (Smoothing < 1)
Smoothing = 1;
CountAct = Math.Min(CountAct + 1, Smoothing);
double myDivider = Math.Max((double)CountAct - 1, 0);
double Result = (ValueLast * myDivider + actValue) / (myDivider + 1);
ValueLast = Result;
return Result;
}
Here you can build an average from as much values you like - you only have to tell the method the smoothing-value you like to have ...
modified 16-Feb-18 6:33am.
|
|
|
|
|
Thanks for the reply. Don't see exactly how this code snippet is gonna solve my exact problem, but thanks anyways .
Original Griff's code for getting the moving average of the last five values works , but problem is as I mentioned that I am getting moving average of last 5 values displayed on the screen and they are from different sensors so that obviously gives undesirable result.
I need to make some sort of array to store my past values for the respective sensors and than apply the GetMovingAverage() on each of the stored arrays.
The thing is I don't know how to do that 
|
|
|
|
|