title: Character sequence UWP [Calculator]
body: <p>I am making a calculator on UWP. My problem is that i need a way to apply an equation to two buttons to convert Celsius to F and vise versa. But my main problem is that i don't know how to cast an Exception correctly if someone types in something like &quot;5+-*/6&quot;. The program works well if i try &quot;5--6 = 11&quot; but i dont want it to crash if someone types in too many characters, rather to then just say &quot;Failed&quot; and then reset it.</p>
  <p>How should i go about fixing this sequence and also apply the convertion for C and F when i am using a datatable to get my answers?</p>
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Data;
  using System.IO;
  using System.Linq;
  using System.Runtime.InteropServices.WindowsRuntime;
  using Windows.Foundation;
  using Windows.Foundation.Collections;
  using Windows.UI.Xaml;
  using Windows.UI.Xaml.Controls;
  using Windows.UI.Xaml.Controls.Primitives;
  using Windows.UI.Xaml.Data;
  using Windows.UI.Xaml.Input;
  using Windows.UI.Xaml.Media;
  using Windows.UI.Xaml.Navigation;
  
  // The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=402352&amp;clcid=0x409
  
  namespace Calc
  {
      /// &lt;summary&gt;
      /// An empty page that can be used on its own or navigated to within a Frame.
      /// &lt;/summary&gt;
      /// 
  
      
      
      public sealed partial class MainPage : Page
      {
  
  
          
          public static bool fClick = false; 
          string input = string.Empty;
          string x = string.Empty;
          string y = string.Empty;
          char operation;
          double result = 0.0;
  
  
          public MainPage()
          {
              this.InitializeComponent();
          }
  
          private void Button_Click(object sender, RoutedEventArgs e)
          {
              textBox.Text += '1';
  
            
          }
  
          private void Button_Click_1(object sender, RoutedEventArgs e)
          {
              textBox.Text += '2';
  
  
          }
  
          private void Button_Click_2(object sender, RoutedEventArgs e)
          {
              textBox.Text += '3';
  
          }
  
          private void Button_Click_3(object sender, RoutedEventArgs e)
          {
              textBox.Text += '4';
  
  
          }
  
          private void Button_Click_4(object sender, RoutedEventArgs e)
          {
              textBox.Text += '5';
  
          }
  
          private void Button_Click_5(object sender, RoutedEventArgs e)
          {
              textBox.Text += '6';
  
  
          }
  
          private void Button_Click_6(object sender, RoutedEventArgs e)
          {
              textBox.Text += '7';
  
  
          }
  
          private void Button_Click_7(object sender, RoutedEventArgs e)
          {
              textBox.Text += '8';
  
          }
  
          private void Button_Click_8(object sender, RoutedEventArgs e)
          {
              textBox.Text += '9';
  
  
          }
  
          private void Button_Click_9(object sender, RoutedEventArgs e)
          {
              textBox.Text += &quot;42&quot;;
       
          }
  
          private void Button_Click_10(object sender, RoutedEventArgs e)
          {
              textBox.Text += '0';
     
          }
  
          private void Button_Click_11(object sender, RoutedEventArgs e)
          {
              textBox.Text += '*';
  
          }
  
          private void Button_ClickPlus(object sender, RoutedEventArgs e)
          {
              textBox.Text += '+';
          }
  
          private void Button_ClickMinus(object sender, RoutedEventArgs e)
          {
              textBox.Text += '-';
          }
  
          private void Button_ClickTimes(object sender, RoutedEventArgs e)
          {
              textBox.Text += '*';
          }
  
          private void Button_ClickDEv(object sender, RoutedEventArgs e)
          {
              textBox.Text += '/';
          }
  
          private void Button_ClickEqual(object sender, RoutedEventArgs e)
          {
  
              try
              {
               object q = new DataTable().Compute(textBox.Text, null);
                          textBox.Text = q.ToString();
              }
              catch
              {
                  //? 
              }
             
          }
  
          private void Button_ClickReset(object sender, RoutedEventArgs e)
          {
              textBox.Text = string.Empty;
  
          }
  
          private void Button_Click_fc_(object sender, RoutedEventArgs e)
          {
              //F to C.
          }
  
          private void Button_Click_cf_(object sender, RoutedEventArgs e)
          {
              //C to F. 
          }
      }
  }
  
  </code></pre>
  <pre><code>&lt;Page
      x:Class=&quot;Calc.MainPage&quot;
      xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;
      xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;
      xmlns:local=&quot;using:Calc&quot;
      xmlns:d=&quot;http://schemas.microsoft.com/expression/blend/2008&quot;
      xmlns:mc=&quot;http://schemas.openxmlformats.org/markup-compatibility/2006&quot;
      mc:Ignorable=&quot;d&quot;
      Background=&quot;{ThemeResource ApplicationPageBackgroundThemeBrush}&quot; Width=&quot;1142&quot; Height=&quot;1289&quot;&gt;
  
      &lt;Grid Margin=&quot;0,0,10,10&quot;&gt;
          &lt;Button Content=&quot;1&quot; Margin=&quot;113,285,0,0&quot; VerticalAlignment=&quot;Top&quot; Height=&quot;64&quot; Width=&quot;133&quot; FontSize=&quot;48&quot; RenderTransformOrigin=&quot;0.795,2.202&quot; Click=&quot;Button_Click&quot;/&gt;
          &lt;Button Content=&quot;2&quot; Margin=&quot;293,285,0,0&quot; VerticalAlignment=&quot;Top&quot; Height=&quot;64&quot; Width=&quot;134&quot; FontSize=&quot;48&quot; Click=&quot;Button_Click_1&quot;/&gt;
          &lt;Button Content=&quot;3&quot; Margin=&quot;467,285,0,0&quot; VerticalAlignment=&quot;Top&quot; Height=&quot;64&quot; Width=&quot;134&quot; FontSize=&quot;48&quot; Click=&quot;Button_Click_2&quot;/&gt;
          &lt;Button Content=&quot;4&quot; Margin=&quot;113,377,0,0&quot; VerticalAlignment=&quot;Top&quot; Height=&quot;65&quot; Width=&quot;133&quot; FontSize=&quot;48&quot; RenderTransformOrigin=&quot;0.795,2.202&quot; Click=&quot;Button_Click_3&quot;/&gt;
          &lt;Button Content=&quot;5&quot; Margin=&quot;293,381,0,0&quot; VerticalAlignment=&quot;Top&quot; Height=&quot;65&quot; Width=&quot;134&quot; FontSize=&quot;48&quot; RenderTransformOrigin=&quot;0.795,2.202&quot; Click=&quot;Button_Click_4&quot;/&gt;
          &lt;Button Content=&quot;6&quot; Margin=&quot;467,381,0,0&quot; VerticalAlignment=&quot;Top&quot; Height=&quot;65&quot; Width=&quot;134&quot; FontSize=&quot;48&quot; RenderTransformOrigin=&quot;0.795,2.202&quot; Click=&quot;Button_Click_5&quot;/&gt;
          &lt;Button Content=&quot;7&quot; Margin=&quot;113,472,0,0&quot; VerticalAlignment=&quot;Top&quot; Height=&quot;64&quot; Width=&quot;133&quot; FontSize=&quot;48&quot; RenderTransformOrigin=&quot;0.795,2.202&quot; Click=&quot;Button_Click_6&quot;/&gt;
          &lt;Button Content=&quot;8&quot; Margin=&quot;293,472,0,0&quot; VerticalAlignment=&quot;Top&quot; Height=&quot;64&quot; Width=&quot;134&quot; FontSize=&quot;48&quot; RenderTransformOrigin=&quot;0.795,2.202&quot; Click=&quot;Button_Click_7&quot;/&gt;
          &lt;Button Content=&quot;9&quot; Margin=&quot;467,472,0,0&quot; VerticalAlignment=&quot;Top&quot; Height=&quot;64&quot; Width=&quot;134&quot; FontSize=&quot;48&quot; RenderTransformOrigin=&quot;0.795,2.202&quot; Click=&quot;Button_Click_8&quot;/&gt;
          &lt;Button Content=&quot;0&quot; Margin=&quot;293,563,0,0&quot; VerticalAlignment=&quot;Top&quot; Height=&quot;65&quot; Width=&quot;134&quot; FontSize=&quot;48&quot; RenderTransformOrigin=&quot;0.795,2.202&quot; Click=&quot;Button_Click_10&quot;/&gt;
          &lt;Button Content=&quot;Marcus&quot; Margin=&quot;113,563,0,0&quot; VerticalAlignment=&quot;Top&quot; Height=&quot;65&quot; Width=&quot;133&quot; FontSize=&quot;48&quot; RenderTransformOrigin=&quot;0.795,2.202&quot; Click=&quot;Button_Click_9&quot;/&gt;
          &lt;Button Content=&quot;F=M*A&quot; Margin=&quot;467,563,0,0&quot; VerticalAlignment=&quot;Top&quot; Height=&quot;65&quot; Width=&quot;134&quot; FontSize=&quot;48&quot; RenderTransformOrigin=&quot;0.795,2.202&quot; Click=&quot;Button_Click_11&quot;/&gt;
          &lt;Button Content=&quot;+&quot; Margin=&quot;651,285,0,0&quot; VerticalAlignment=&quot;Top&quot; Height=&quot;64&quot; Width=&quot;132&quot; FontSize=&quot;48&quot; RenderTransformOrigin=&quot;0.795,2.202&quot; Click=&quot;Button_ClickPlus&quot;/&gt;
          &lt;Button Content=&quot;-&quot; Margin=&quot;651,381,0,0&quot; VerticalAlignment=&quot;Top&quot; Height=&quot;65&quot; Width=&quot;132&quot; FontSize=&quot;48&quot; RenderTransformOrigin=&quot;0.795,2.202&quot; Click=&quot;Button_ClickMinus&quot;/&gt;
          &lt;Button Content=&quot;*&quot; Margin=&quot;651,472,0,0&quot; VerticalAlignment=&quot;Top&quot; Height=&quot;64&quot; Width=&quot;132&quot; FontSize=&quot;48&quot; RenderTransformOrigin=&quot;0.795,2.202&quot; Click=&quot;Button_ClickTimes&quot;/&gt;
          &lt;Button Content=&quot;/&quot; Margin=&quot;651,563,0,0&quot; VerticalAlignment=&quot;Top&quot; Height=&quot;65&quot; Width=&quot;132&quot; FontSize=&quot;48&quot; RenderTransformOrigin=&quot;0.795,2.202&quot; Click=&quot;Button_ClickDEv&quot;/&gt;
          &lt;Button Content=&quot;=&quot; Margin=&quot;113,651,0,0&quot; VerticalAlignment=&quot;Top&quot; Height=&quot;65&quot; Width=&quot;488&quot; FontSize=&quot;48&quot; RenderTransformOrigin=&quot;0.795,2.202&quot; Click=&quot;Button_ClickEqual&quot;/&gt;
  
          &lt;Button Content=&quot;Reset&quot; Margin=&quot;651,651,0,0&quot; VerticalAlignment=&quot;Top&quot; Height=&quot;65&quot; Width=&quot;132&quot; FontSize=&quot;48&quot; RenderTransformOrigin=&quot;0.795,2.202&quot; Click=&quot;Button_ClickReset&quot;/&gt;
          &lt;TextBox x:Name=&quot;textBox&quot; HorizontalAlignment=&quot;Left&quot; Margin=&quot;113,63,0,0&quot; Text=&quot;&quot; TextWrapping=&quot;Wrap&quot; VerticalAlignment=&quot;Top&quot; Height=&quot;190&quot; Width=&quot;833&quot; FontSize=&quot;72&quot;/&gt;
          &lt;Button Content=&quot;F&amp;gt;C&quot; Margin=&quot;813,285,0,0&quot; VerticalAlignment=&quot;Top&quot; Height=&quot;64&quot; Width=&quot;133&quot; FontSize=&quot;48&quot; RenderTransformOrigin=&quot;0.795,2.202&quot; Click=&quot;Button_Click_fc_&quot;/&gt;
          &lt;Button Content=&quot;C&amp;gt;F&quot; Margin=&quot;813,382,0,0&quot; VerticalAlignment=&quot;Top&quot; Height=&quot;64&quot; Width=&quot;133&quot; FontSize=&quot;48&quot; RenderTransformOrigin=&quot;0.795,2.202&quot; Click=&quot;Button_Click_cf_&quot;/&gt;
      &lt;/Grid&gt;
  &lt;/Page&gt;
  
  </code></pre>