#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2002
    Posts
    32
    Rep Power
    12

    Cannot implicitly convert type 'int' to 'string'


    I'm quite new at this so bare with me.

    I get the error for the following code

    Code:
    private void linkLabel1_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
    {
    	const int hoursCalc = (distance/speed);
    	const int minutesCalc = hoursCalc*60;
    	hours.Text = hoursCalc;
    	minutes.Text = minutesCalc;
    }
    I know I'm doing something wrong with the declaration of the vars. Anyway can someone helpme out.
    Thanks
  2. #2
  3. Sk8er Punk!
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Location
    Minneapolis, MN
    Posts
    96
    Rep Power
    11
    There are some issues here.

    When doing the calculations, you must have the varibles defined correctly.

    Use the convert class with which function you need.

    Convert.ToInt32(speed) should do the trick.

    Now what if you get a decimal, which is very likely here.

    You can't put a decimal in an int.

    Here is your code rewritten.

    private void linkLabel1_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
    {
    decimal hoursCalc = (Convert.ToInt32(distance)/Convert.ToInt32(speed));
    decimal minutesCalc = hoursCalc*60;
    hours.Text = Convert.ToString(hoursCalc);
    minutes.Text = Convert.ToString(minutesCalc);
    }

    It looks like you might need to use the Math.Round(decimal your result, int noPlaces) function too. You can do this on your hoursCalc and minutesCalc round to the nearest hour or minute.

    This is in C# by the way.
    if (Bush == "idiot") return "Bush is an Idiot";
    else if (Bush != "idiot") return "Bush is still an idiot";

    http://www.yourpolitics.org
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Location
    Brisbane, Australia
    Posts
    50
    Rep Power
    11
    instead of
    Convert.ToString(hoursCalc);
    Convert.ToString(minutesCalc);
    you can also do this way
    hoursCalc.ToString();
    minutesCalc.ToString();


    with VB.NET
    CStr(hoursCalc)
    CStr(minuteCalc)
    or
    hoursCalc.ToString();
    minutesCalc.ToString();
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2003
    Posts
    1
    Rep Power
    0
    Hi

    public Lexico (string X)
    {
    this.Programa = string.Copy (X);
    this.Programa = Convert.ToString(this.Programa.Split(this.Separate));
    }






    Lexico AnL = new Lexico( this.EspacioCod.Text);
    EspacioCod.AppendText( AnL.GetProgram());


    If I use Lexico and made the split it returns to me a

    "System.String[]"


    What can I do if I need to put the String in a richtext ??
    Always insert in the richtext "System.String[]"

    Thank's
    Last edited by Archylus; November 5th, 2003 at 10:46 PM.

IMN logo majestic logo threadwatch logo seochat tools logo