IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C# Discussion :

utilise la convertion string to int


Sujet :

C#

  1. #1
    Candidat au Club
    Femme Profil pro
    Étudiant
    Inscrit en
    Mars 2015
    Messages
    5
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 32
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Électronique et micro-électronique

    Informations forums :
    Inscription : Mars 2015
    Messages : 5
    Points : 4
    Points
    4
    Par défaut utilise la convertion string to int
    bonjour
    mon objectif faire une graphe en temps réel j'ai récupéré mes informations dans un ritechtextbox puis j'ai réalise la conversion string en int
    et j'ai l'ajouté dans une liste est ce qu'il y'a une solution ou bien autre idée et merci d'avance!!

  2. #2
    Membre averti Avatar de pascalCH
    Homme Profil pro
    Formateur en informatique
    Inscrit en
    Juillet 2006
    Messages
    187
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 66
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Formateur en informatique
    Secteur : Aéronautique - Marine - Espace - Armement

    Informations forums :
    Inscription : Juillet 2006
    Messages : 187
    Points : 369
    Points
    369
    Par défaut
    Citation Envoyé par zikose Voir le message
    bonjour
    mon objectif faire une graphe en temps réel j'ai récupéré mes informations dans un ritechtextbox puis j'ai réalise la conversion string en int
    et j'ai l'ajouté dans une liste est ce qu'il y'a une solution ou bien autre idée et merci d'avance!!
    pas de soucis, il faut juste que tu commences par dire ce que tu veux faire, dans quel contexte, et en français ... d'accord ?
    La nature fait des choses extraordinaires, observons la et restons humble, on ne nous demande pas de refaire le monde mais juste de reproduire virtuellement des choses existantes ....

    et n'oubliez pas si vous aimez et quand vous avez la réponse

  3. #3
    Candidat au Club
    Femme Profil pro
    Étudiant
    Inscrit en
    Mars 2015
    Messages
    5
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 32
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Électronique et micro-électronique

    Informations forums :
    Inscription : Mars 2015
    Messages : 5
    Points : 4
    Points
    4
    Par défaut
    convertir le contenue de richtextbox pour construire une graphe

  4. #4
    Membre régulier
    Homme Profil pro
    Inscrit en
    Mai 2012
    Messages
    151
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mai 2012
    Messages : 151
    Points : 87
    Points
    87
    Par défaut
    Les string contenu dans la ritechtextbox sont-ils des nombres ? Du genre "32", "364", ... ? Sont-ils en décimal ou en héxadécimal (ou autres) ?

    Sinon, il me semble qu'un simple Convert.ToInt32(machainestring) devrait suffire, ou avec Int32.Parse(machainestring), puis rentrer ces valeurs dans un tableau par exemple.

    https://msdn.microsoft.com/fr-fr/library/bb397679.aspx

  5. #5
    Candidat au Club
    Femme Profil pro
    Étudiant
    Inscrit en
    Mars 2015
    Messages
    5
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 32
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Électronique et micro-électronique

    Informations forums :
    Inscription : Mars 2015
    Messages : 5
    Points : 4
    Points
    4
    Par défaut
    Les string contenu dans la ritechtextbox sont en décimal . voila le code
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.Windows.Forms.DataVisualization.Charting;
    using System.Threading;
    using System.IO.Ports;
    using System.IO;
     
     
    namespace source_reel
    {
        public partial class Form1 : Form
        {
     
            private delegate void CanlJust();
            private List<float> _valueList;
            private List<string> _stringList;
            private Thread _thread;
            private CanlJust _dolt;
            // private int bytesRead;
            private Random _ran;
            private int _interval;
            private List<double> _timeList;
            private List<int> _customValueList;
           // private string zak=null;
           // char[] zak = new char[20];
           //private double a ;
           private string zak=null ;
           private string reader ;
          // private List<string> listofIDs;
            public Form1()
            {
                InitializeComponent();
     
            }
     
            private void richTextBox1_TextChanged(object sender, EventArgs e)
            {
     
            }
     
            private void button1_Click(object sender, EventArgs e)
            {
                SerialPort sp = new SerialPort("COM1", 9600, Parity.None, 8, StopBits.One);
                sp.Open();
                sp.DataReceived += new SerialDataReceivedEventHandler(DataReceivedHandler);
                chart1.ChartAreas[0].AxisX.IsStartedFromZero = true;
                chart1.ChartAreas[0].AxisX.ScaleView.Zoomable = false;
                chart1.Series[0].XValueType = ChartValueType.Time;
                chart1.ChartAreas[0].AxisX.ScaleView.SizeType = DateTimeIntervalType.Seconds;
                chart1.ChartAreas[0].AxisX.IntervalAutoMode = IntervalAutoMode.FixedCount;
                chart1.ChartAreas[0].AxisX.IntervalType = DateTimeIntervalType.Seconds;
                chart1.ChartAreas[0].AxisX.Interval = 0;
                _valueList = new List<float>();
     
               // _stringList = new List<string>();
     
               _ran = new Random();
               //double a = Single.Parse(zak);
                _interval = 800;
                // serial();
                Goboy();
                _timeList = new List<double>();
                _customValueList = new List<int>();
     
     
            }
     
             void DataReceivedHandler(object sender, SerialDataReceivedEventArgs e)
            {
     
                SerialPort sp = (SerialPort)sender;
             string w = sp.ReadLine();
     
     
               zak = w.Replace(".",",");
     
     
             // _stringList.Add(w);
     
     
              //_valueList.Add(int );
            //  MessageBox.Show(_valueList.ToString()); 
          //   List<string> listofIDs = _stringList.ToList();
     
     
     
     
                 if (zak != String.Empty)
                {
                    Invoke(new Action(() => richTextBox1.AppendText(zak)));
                    //richTextBox1.Text.Replace('.', ',');
                  //Invoke(new Action(() => textBox1.AppendText(zak)));
                }
     
               //zak1 = string.Copy(zak);
     
     
            }
     
             private void Goboy()
             {
                 _dolt += new CanlJust(AddData);
                 DateTime now = DateTime.Now;
                 chart1.ChartAreas[0].AxisX.Minimum = now.ToOADate();
                 chart1.ChartAreas[0].AxisX.Maximum = now.AddSeconds(5).ToOADate();
                 _thread = new Thread(new ThreadStart(ComeOnYouThread));
                 _thread.Start();
     
             }
             private void ComeOnYouThread()
             {
                 while (true)
                 {
                     try
                     {
                         chart1.Invoke(_dolt);
                         Thread.Sleep(_interval);
     
                     }
                     catch (Exception e)
                     {
                         System.Diagnostics.Debug.WriteLine("Exception ; " + e.ToString());
                     }
                 }
             }
             private void AddData()
             {
                 DateTime now = DateTime.Now;
                // StreamReader zak = new StreamReader(richTextBox1.Text);
                 //richTextBox1.Text = zak.ReadLine();
               // line
                // try
                 //{
              //   if (int.TryParse(monstring, out num))
                //     line = Convert.ToInt32(zak);
     
                // }
                 //catch { 
     
                 //}
                // bool success = Int32.TryParse(richTextBox1.Text, out val);
                // richTextBox1.
     
     
                 //int number = Convert.ToInt32(richTextBox1.Text);
                // zak = richTextBox1.Text.Replace('.', ',');
                 //string zak1;
               //  zak1 = textBox1.Text;
                //if (string.IsNullOrEmpty(richTextBox1.Text))
                 //{
               //  richTextBox1.Clear();
                 //StringReader reader;
                // reader = new StringReader(richTextBox1.Text);
     
                 if (textBox1.Text != String.Empty)
                 {
                     _valueList.Add(float.Parse("54"));
                 }
                 else {
                     _valueList.Add(float.Parse("20,45857"));
     
                 }
     
                     // MessageBox.Show(zak1);
                 //}
                 //else 
                 //{
                //     _valueList.Add(float.Parse(richTextBox1.Text));
     
                 //}
     
                // _valueList.Add(double.Parse(textBox1.Text.Replace('.',',')));
                 chart1.ResetAutoValues();
     
                 if (chart1.Series[0].Points.Count > 0)
                 {
                     while (chart1.Series[0].Points[0].XValue < now.AddSeconds(-5).ToOADate())
                     {
                         chart1.Series[0].Points.RemoveAt(0);
                         chart1.ChartAreas[0].AxisX.Minimum = chart1.Series[0].Points[0].XValue;
                         chart1.ChartAreas[0].AxisX.Maximum = now.AddSeconds(20).ToOADate();
     
                     }
     
                 }
                 try
                 {
                     chart1.Series[0].Points.AddXY(now.ToOADate(), _valueList[_valueList.Count - 1]);
                     chart1.Invalidate();
                 }
                 catch
                 {
                 }
     
             }
             protected override void OnClosed(EventArgs e)
             {
                 base.OnClosed(e);
                 if (_thread != null)
                     _thread.Abort();
     
             }
     
             private void textBox1_TextChanged(object sender, EventArgs e)
             {
     
     
             }
     
     
        }
    }
    le message de retour
    le format de la chaîne d'entré est incorrecte .

  6. #6
    Membre averti Avatar de solaar
    Homme Profil pro
    Inscrit en
    Septembre 2007
    Messages
    607
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Côte d'Ivoire

    Informations professionnelles :
    Secteur : Industrie

    Informations forums :
    Inscription : Septembre 2007
    Messages : 607
    Points : 314
    Points
    314
    Par défaut
    Bonjour !
    Excuse moi .... sois précis.
    Sur quelle fonction sa coince ?

Discussions similaires

  1. [Débutant] convert. ToInt32 string to int 32
    Par xingjing910 dans le forum VB.NET
    Réponses: 7
    Dernier message: 19/03/2012, 09h25
  2. Convertion char vers int
    Par barthelv dans le forum C
    Réponses: 8
    Dernier message: 08/10/2011, 22h45
  3. convertion string en int : demande explication
    Par kuja2053 dans le forum C++
    Réponses: 4
    Dernier message: 20/04/2008, 01h10
  4. PL-pgsql : convert string to int
    Par Latmy dans le forum PostgreSQL
    Réponses: 3
    Dernier message: 22/02/2008, 18h29
  5. [convertion]String vers int
    Par laclac dans le forum Langage
    Réponses: 4
    Dernier message: 12/04/2007, 11h49

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo