Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Help with number to string conversion

Help with number to string conversion

Scheduled Pinned Locked Moved C / C++ / MFC
helpcsharpvisual-studiowinformstutorial
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    TabascoSauce
    wrote on last edited by
    #1

    I've been working my way out of the console apps and I am now trying to learn how to use windows forms in visual studio 2008. Anyway, onward to the question. I am trying to display a numerical value as text in a label on a windows form. I looked around for an answer on the internet and I found some, but I couldn't get them to work for me. So I decided to start from scratch and just ask this forum for help. Here's the section of code I'm dealing with, I bolded my problem areas. Oh and to avoid confusion, click this: http://img100.imageshack.us/img100/4479/form1w.jpg[^]. Its a picture of my form with all of the variables and etc labeled.

    private: System::Void numberDisp_Click(System::Object^ sender, System::EventArgs^ e)
    {
    numberDisp->Text = ticketNumber->Value
    }
    private: System::Void priceDisp_Click(System::Object^ sender, System::EventArgs^ e)
    {
    //Variable
    int tickNum = 0;
    double price = 0;

    		 //Get # of tickets
    		 tickNum = ticketNumber->Value;
    		 
    		 //Calculate Price
    		 if (locB->Checked == true)
    		 {
    			 price = tickNum \* 75;
    		 }
    		 if (locP->Checked == true)
    		 {
    			 price = tickNum \* 30;
    		 }
    		 if (locL->Checked == true)
    		 {
    			 price = tickNum \* 21;
    		 }
    
    		 //Display Price
    		 **priceDisp->Text = price;**
    	 }
    
    S 1 Reply Last reply
    0
    • T TabascoSauce

      I've been working my way out of the console apps and I am now trying to learn how to use windows forms in visual studio 2008. Anyway, onward to the question. I am trying to display a numerical value as text in a label on a windows form. I looked around for an answer on the internet and I found some, but I couldn't get them to work for me. So I decided to start from scratch and just ask this forum for help. Here's the section of code I'm dealing with, I bolded my problem areas. Oh and to avoid confusion, click this: http://img100.imageshack.us/img100/4479/form1w.jpg[^]. Its a picture of my form with all of the variables and etc labeled.

      private: System::Void numberDisp_Click(System::Object^ sender, System::EventArgs^ e)
      {
      numberDisp->Text = ticketNumber->Value
      }
      private: System::Void priceDisp_Click(System::Object^ sender, System::EventArgs^ e)
      {
      //Variable
      int tickNum = 0;
      double price = 0;

      		 //Get # of tickets
      		 tickNum = ticketNumber->Value;
      		 
      		 //Calculate Price
      		 if (locB->Checked == true)
      		 {
      			 price = tickNum \* 75;
      		 }
      		 if (locP->Checked == true)
      		 {
      			 price = tickNum \* 30;
      		 }
      		 if (locL->Checked == true)
      		 {
      			 price = tickNum \* 21;
      		 }
      
      		 //Display Price
      		 **priceDisp->Text = price;**
      	 }
      
      S Offline
      S Offline
      Stuart Dootson
      wrote on last edited by
      #2

      Try using the ToString method:

      priceDisp->Text = price.ToString();

      Also, maybe you could use the correct forum[^] - you're more likely to get the correct answer there.

      Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

      T 1 Reply Last reply
      0
      • S Stuart Dootson

        Try using the ToString method:

        priceDisp->Text = price.ToString();

        Also, maybe you could use the correct forum[^] - you're more likely to get the correct answer there.

        Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

        T Offline
        T Offline
        TabascoSauce
        wrote on last edited by
        #3

        Bah, sorry about the forum :( This is the second time I've done this (accident).

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups