Last visit was: It is currently Thu Mar 28, 2024 12:56 pm


All times are UTC-05:00




Post new topic Reply to topic  [13 posts ] 
    Author Message
     Post subject:Help with C# program
    PostPosted:Thu Sep 27, 2007 10:58 am 
     

    Joined:Sun Jun 10, 2007 11:41 am
    Posts:344
    Location:Ninjaville
    So I have a C# project that is supposed to calculate the amount of skateboards, and the total price, but I've run into two problems.

    1.When I hit calculate it is supposed to add the Text property of xYellowTextBox and xBlueTextBox, and populate xTotal. However it treats xYellowTextbox and xBlueTextBox's Text property as a string, so 15+10 would be 1510. In VB I would simply use the Val function, but I don't want to do that here.

    2.I can't figure out how to do multiplication in C#, how would I take xTotal.Text and multiply it by 10?

    I could do this easily in VB, but I want to try rewriting it in pure C#.


    Top
    Offline  
     Post subject:
    PostPosted:Thu Sep 27, 2007 7:53 pm 
    Sagely Amphibian
    User avatar
     

    Joined:Sun Jun 18, 2006 3:06 pm
    Posts:69
    You need to think in the Object paradigm. Try something like int.Parse("23");, same should go for VB.NET, Integer.Parse("23").

    EDIT: Don't forget to catch the possible exceptions.


    Top
    Offline  
     Post subject:
    PostPosted:Thu Sep 27, 2007 11:37 pm 
     

    Joined:Mon Sep 17, 2007 5:57 pm
    Posts:57
    I think the function is
    Code:
    Convert.ToInt32(string input)
    It also has a built in failsafe to return a 0 if they dont enter anything thats valid


    Top
    Offline  
     Post subject:
    PostPosted:Fri Sep 28, 2007 12:14 pm 
     

    Joined:Sun Jun 10, 2007 11:41 am
    Posts:344
    Location:Ninjaville
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;


    namespace SkateAway_Sales
    {
    public partial class Form1 : Form
    {
    public Form1()
    {
    InitializeComponent();
    }

    private void Form1_Load(object sender, EventArgs e)
    {

    }

    private void exitbutton_Click(object sender, EventArgs e)
    {
    Close();
    }

    private void cls_Click(object sender, EventArgs e)
    {
    xNameTextbox.Text = String.Empty;
    xAddressTextbox.Text = String.Empty;
    xCityTextBox.Text = String.Empty;
    xStateTextbox.Text = String.Empty;
    xZipTextBox.Text = String.Empty;
    xBlueTextBox.Text = String.Empty;
    xYellowTextBox.Text = String.Empty;
    xTotal.Text = String.Empty;
    xPrice.Text = String.Empty;
    }

    private void xYellowTextBox_TextChanged(object sender, EventArgs e)
    {

    }

    private void calculate_Click(object sender, EventArgs e)
    {



    }
    }
    }
    Code:
    Thats the Source code, in VB.Net I would simply use val(), however I can't figure out how to use convert or intParse, would you mind demonstrating it for me?


    Top
    Offline  
     Post subject:
    PostPosted:Fri Sep 28, 2007 6:16 pm 
    Sagely Amphibian
    User avatar
     

    Joined:Sun Jun 18, 2006 3:06 pm
    Posts:69
    eh; Guessing(here);
    Code:
    int numberb = int.Parse(xPrice.Text); int numbera = Convert.ToInt32(xPrice.Text);


    Top
    Offline  
     Post subject:
    PostPosted:Fri Sep 28, 2007 9:08 pm 
     

    Joined:Mon Sep 17, 2007 5:57 pm
    Posts:57
    waht he said
    Code:
    numbera=Convert.ToInt32(xPrice)


    Top
    Offline  
     Post subject:
    PostPosted:Mon Oct 01, 2007 9:31 am 
     

    Joined:Sun Jun 10, 2007 11:41 am
    Posts:344
    Location:Ninjaville
    Hmm, that seems to work but I need to then convert it back into a string to populate a different text box. Is this doable?


    Top
    Offline  
     Post subject:
    PostPosted:Mon Oct 01, 2007 6:25 pm 
    Sagely Amphibian
    User avatar
     

    Joined:Sun Jun 18, 2006 3:06 pm
    Posts:69
    Please, learn to use the msdn or google ;)
    Quote:
    ToString Overloaded. Overridden. Converts the numeric value of this instance to its equivalent string representation.


    Top
    Offline  
     Post subject:
    PostPosted:Mon Oct 01, 2007 9:09 pm 
     

    Joined:Mon Sep 17, 2007 5:57 pm
    Posts:57
    google FTW!


    Top
    Offline  
     Post subject:
    PostPosted:Mon Oct 01, 2007 9:24 pm 
    User avatar
     

    Joined:Sat Mar 11, 2006 8:28 am
    Posts:365
    Location:Canada
    I love this sitehttp://justfuckinggoogleit.com/

    _________________
    Best file compression around: "DEL *.*" = 100% compression
    "640K ought to be enough for anybody." - Bill Gates, 1981


    Top
    Offline  
     Post subject:
    PostPosted:Mon Oct 01, 2007 11:58 pm 
     

    Joined:Mon Sep 17, 2007 5:57 pm
    Posts:57
    i think taht site sums it up dark


    Top
    Offline  
     Post subject:
    PostPosted:Mon Oct 22, 2007 6:14 am 
    User avatar
     

    Joined:Sun Feb 12, 2006 8:56 pm
    Posts:1019
    Website:http://eddieringle.com
    Location:Detroit, MI
    Google solves most of my problems, either Google or ChaosR. :P

    The only reason I don't put up a link on my site is because of the language, (I like to be at the most PG-13).

    _________________
    -- Eddie Ringle

    Check out Elysian Shadows and consider backing us on Kickstarter!

    ====================================

    Image


    Top
    Offline  
     Post subject:
    PostPosted:Mon Oct 22, 2007 5:21 pm 
     

    Joined:Mon Sep 17, 2007 5:57 pm
    Posts:57
    yeah. and i never mentioned that hte fool can just typecast it :D


    Top
    Offline  
    Display posts from previous: Sort by 
    Post new topic Reply to topic

      All times are UTC-05:00


      Who is online

      Users browsing this forum: No registered users and 16 guests


      You cannot post new topics in this forum
      You cannot reply to topics in this forum
      You cannot edit your posts in this forum
      You cannot delete your posts in this forum
      You cannot post attachments in this forum

      Search for:
      Jump to:  
      cron
      Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
      Theme created by Miah with assistance from hyprnova