Click here to Skip to main content
15,885,546 members
Home / Discussions / C#
   

C#

 
GeneralRe: sevenzipsharp password Pin
Dave Kreskowiak12-Feb-18 2:30
mveDave Kreskowiak12-Feb-18 2:30 
AnswerRe: sevenzipsharp password Pin
BillWoodruff11-Feb-18 23:11
professionalBillWoodruff11-Feb-18 23:11 
SuggestionMessage Removed Pin
10-Feb-18 9:12
Markhoernchen10-Feb-18 9:12 
GeneralMessage Removed Pin
10-Feb-18 9:59
mveRichard MacCutchan10-Feb-18 9:59 
AnswerMessage Removed Pin
10-Feb-18 11:28
Markhoernchen10-Feb-18 11:28 
QuestionError with Primary key in Sql database Pin
Member 1367168610-Feb-18 7:32
Member 1367168610-Feb-18 7:32 
AnswerRe: Error with Primary key in Sql database Pin
Wendelius10-Feb-18 8:27
mentorWendelius10-Feb-18 8:27 
QuestionSplit a String of numbers in textfield Pin
auting829-Feb-18 11:06
auting829-Feb-18 11:06 
I have 5 randomly generated numbers type in text field every time I press a button:
Something like this: 0.5670.9870.3420.5210.07 etc......They represent sensor values in range 0-1V
I would like to split them so that I get something like this:
0.567 0.987 0.342 0.521 0.07

Also I would like to add a line shift so that every time I press the button the number series goes onto next line.
Anybody has an idea ?

This is my main Form1.cs class:

C#
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.Windows.Forms;

namespace DAQ_Simulator
{
    public partial class Form1 : Form
    {
        int counter;
        
        private DateTime datetime;
        private DateTime datetime2;
        //double next_samplingtime += DateTime.Now;
        //int maxSid = 10; //Number of sensors 7analog and 3 digital
        int maxAI = 7; 
        int maxDI=3;
        int maxSid =10;
        

        // string sensor_values;
        string sTxt; //get analog values
        string sTxt1; //get digital states


        // Create an array of 10 sensor objects
        Sensor[] sObj = new Sensor[10];

        //DateTime dt = new DateTime(2018, 2, 8, 14, 22, 30, 123);


        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)
        {
            timer1.Interval = 5900; // here in miliseconds
            timer1.Start();
            btnSampling.Enabled = false;
            sampling();
            

            if (textSampling.Text == "")
            {
                textSampling.Text = "Sample";
            }

            datetime2 = DateTime.Now.AddSeconds(5).AddMilliseconds(900);
            string time2 = datetime2.Hour + ":" + datetime2.Minute + ":" + datetime2.Second + "." + datetime2.Millisecond;
            textSampling.Text =time2;
            System.TimeSpan diff1 = datetime2.Subtract(datetime);
         
        }

    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)
    {

    }
    private void labelSensorValues_Click(object sender, EventArgs e)
    {

    }
    private void textSensorValues_TextChanged(object sender, EventArgs e)
    {

    }
    private void timer1_Tick(object sender, EventArgs e)
    {
         btnSampling.Enabled = true;
         timer1.Stop();
    }
    private void sampling()
    {
            datetime = DateTime.Now;
           
            string time = datetime.Hour + ":" + datetime.Minute + ":" + datetime.Second + "." + datetime.Millisecond;
            
            // Get the object values as a string
            
            for (counter = 0; counter < maxAI; counter++)
        {
            sTxt += sObj[7].GetAnalogValue().ToString("F3");
            
        }
            for (counter = 0; counter < maxDI; counter++)
            {
              
                sTxt1 += sObj[3].GetDigitalValue().ToString();

            }
            textSensorValues.Text = time + "\r\n" + sTxt+sTxt1;
    }
        
    }
}


This is my Sensor.cs class:

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DAQ_Simulator
{
    public class Sensor
    {
        double dVal;
        int DigVal;
        int sId;
        Random rSensVal;

        public Sensor(int id)
        {
            sId = id;
            rSensVal = new Random(id);
            dVal = 0.0F;
        }
       
        public double GetAnalogValue()
        {
            dVal = rSensVal.NextDouble();
            return dVal;         
       }
        public double GetDigitalValue()
        {
           Random ranDigVal = new Random();
           DigVal= ranDigVal.Next(0,2);
            return DigVal;
        }
        public int GetSensId()
        {
            return sId;
        } 
    }
}

AnswerRe: Split a String of numbers in textfield Pin
Luc Pattyn9-Feb-18 16:22
sitebuilderLuc Pattyn9-Feb-18 16:22 
GeneralRe: Split a String of numbers in textfield Pin
auting8210-Feb-18 8:03
auting8210-Feb-18 8:03 
GeneralRe: Split a String of numbers in textfield Pin
Luc Pattyn10-Feb-18 8:41
sitebuilderLuc Pattyn10-Feb-18 8:41 
AnswerRe: Split a String of numbers in textfield Pin
Richard MacCutchan9-Feb-18 21:58
mveRichard MacCutchan9-Feb-18 21:58 
Questionmodeling n-variable polynomial where n isn't known until runtime Pin
Alexander Kindel9-Feb-18 10:06
Alexander Kindel9-Feb-18 10:06 
AnswerRe: modeling n-variable polynomial where n isn't known until runtime Pin
Alexander Kindel10-Feb-18 4:03
Alexander Kindel10-Feb-18 4:03 
QuestionI do not know English very well, so my question may be incomprehensible .I wanted to create a program that should determine the frequency of spreading it. Pin
Bek Boltayev9-Feb-18 9:48
Bek Boltayev9-Feb-18 9:48 
AnswerRe: I do not know English very well, so my question may be incomprehensible .I wanted to create a program that should determine the frequency of spreading it. Pin
Pete O'Hanlon9-Feb-18 10:10
mvePete O'Hanlon9-Feb-18 10:10 
QuestionHow can I create a program that shows information on DVB-T2 USB and shows it in a noutbook ??? Pin
Bek Boltayev9-Feb-18 9:42
Bek Boltayev9-Feb-18 9:42 
AnswerRe: How can I create a program that shows information on DVB-T2 USB and shows it in a noutbook ??? Pin
Dave Kreskowiak9-Feb-18 13:27
mveDave Kreskowiak9-Feb-18 13:27 
QuestionMultiple sliders or trackbars Pin
Member 136704429-Feb-18 8:07
Member 136704429-Feb-18 8:07 
QuestionRe: Multiple sliders or trackbars Pin
Maciej Los9-Feb-18 9:03
mveMaciej Los9-Feb-18 9:03 
AnswerRe: Multiple sliders or trackbars Pin
ZurdoDev9-Feb-18 9:10
professionalZurdoDev9-Feb-18 9:10 
AnswerRe: Multiple sliders or trackbars Pin
BillWoodruff10-Feb-18 23:23
professionalBillWoodruff10-Feb-18 23:23 
GeneralRe: Multiple sliders or trackbars Pin
Member 1367044211-Feb-18 12:59
Member 1367044211-Feb-18 12:59 
GeneralRe: Multiple sliders or trackbars Pin
BillWoodruff11-Feb-18 16:56
professionalBillWoodruff11-Feb-18 16:56 
GeneralRe: Multiple sliders or trackbars Pin
Member 1367028512-Feb-18 0:54
Member 1367028512-Feb-18 0:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.