Results 1 to 11 of 11
  1. #1
    thekm1994's Avatar
    Join Date
    Jan 2010
    Gender
    male
    Posts
    79
    Reputation
    8
    Thanks
    1
    My Mood
    Daring

    Talking Hello Guys ! I am strting to learn a C# languge and i dont know ...

    I am Starting to learn C# and i dont know how to get a value for a variable while the program is runing , Lets say ' it should be like a progrram that you run it ' (output) "Put in a number" (input) value for the varable (output) "You choosed number {varible value}" ! Thanks /yea/me
    If you wanna see how to make a someone dumb press here

  2. #2
    'Bruno's Avatar
    Join Date
    Dec 2009
    Gender
    male
    Location
    Portugal
    Posts
    2,883
    Reputation
    290
    Thanks
    1,036
    My Mood
    Busy
    Quote Originally Posted by thekm1994 View Post
    I am Starting to learn C# and i dont know how to get a value for a variable while the program is runing , Lets say ' it should be like a progrram that you run it ' (output) "Put in a number" (input) value for the varable (output) "You choosed number {varible value}" ! Thanks /yea/me
    Console? Use the Console. Object...

    Console.ReadLine()
    Light travels faster than sound. That's why most people seem bright until you hear them speak.

  3. #3
    thekm1994's Avatar
    Join Date
    Jan 2010
    Gender
    male
    Posts
    79
    Reputation
    8
    Thanks
    1
    My Mood
    Daring
    Yes . I know that , Console.ReadLine(); , But how can i use it for reading a value into a variable ? should it be like C++ ?
    If you wanna see how to make a someone dumb press here

  4. #4
    Kuro Tenshi's Avatar
    Join Date
    Jan 2009
    Gender
    male
    Location
    Where arth thou be
    Posts
    3,635
    Reputation
    70
    Thanks
    746
    My Mood
    Blah
    Quote Originally Posted by thekm1994 View Post
    I am Starting to learn C# and i dont know how to get a value for a variable while the program is runing , Lets say ' it should be like a progrram that you run it ' (output) "Put in a number" (input) value for the varable (output) "You choosed number {varible value}" ! Thanks /yea/me
    [php]
    static void Main(string[] args)
    {
    int variable_value;


    Console.WriteLine("Put in a number");
    variable_value = Convert.ToInt32(Console.ReadLine());
    Console.WriteLine("You choosed number {0}", variable_value);

    Console.WriteLine("\n" + "Press any key to exit.");
    Console.ReadKey();
    }
    [/php]
    Last edited by Kuro Tenshi; 09-15-2010 at 01:59 AM.
    DigiDrawing|+ ( (Elfen Archer) )
    Link:
    https://www.mpgh.net/forum/148-showro...en-archer.html


    @ Anime Section,Otaku/weeabo (orz.) @Graphics Section, Novice DigiArtist


    neuest gift from Yura~Chan:
    https://bakyurayuu.deviantar*****m/#/d372taw
    2nd Place MOTM#9 Theme: CharMods - Combat Arms [No - Thanks] button
    come on you know that don't want to push that ordinary button

  5. #5
    'Bruno's Avatar
    Join Date
    Dec 2009
    Gender
    male
    Location
    Portugal
    Posts
    2,883
    Reputation
    290
    Thanks
    1,036
    My Mood
    Busy
    It should be obvious btw Kuro is using Convert.ToInt32 because ReadLine returns a String, and you obviously can't get a string on a int var.

    If you are saving on a string, you won't need any convert.
    Light travels faster than sound. That's why most people seem bright until you hear them speak.

  6. #6
    Kuro Tenshi's Avatar
    Join Date
    Jan 2009
    Gender
    male
    Location
    Where arth thou be
    Posts
    3,635
    Reputation
    70
    Thanks
    746
    My Mood
    Blah
    ehm try it, i know its not 100% correct but it started whining when i implemented tostring @ variable_value and yeah this works.
    DigiDrawing|+ ( (Elfen Archer) )
    Link:
    https://www.mpgh.net/forum/148-showro...en-archer.html


    @ Anime Section,Otaku/weeabo (orz.) @Graphics Section, Novice DigiArtist


    neuest gift from Yura~Chan:
    https://bakyurayuu.deviantar*****m/#/d372taw
    2nd Place MOTM#9 Theme: CharMods - Combat Arms [No - Thanks] button
    come on you know that don't want to push that ordinary button

  7. #7
    'Bruno's Avatar
    Join Date
    Dec 2009
    Gender
    male
    Location
    Portugal
    Posts
    2,883
    Reputation
    290
    Thanks
    1,036
    My Mood
    Busy
    Quote Originally Posted by Kuro Tenshi View Post
    ehm try it, i know its not 100% correct but it started whining when i implemented tostring @ variable_value and yeah this works.
    man all i said was that you were right and explained the OP why you used convert... what's wrong with you? oO
    Light travels faster than sound. That's why most people seem bright until you hear them speak.

  8. #8
    Kuro Tenshi's Avatar
    Join Date
    Jan 2009
    Gender
    male
    Location
    Where arth thou be
    Posts
    3,635
    Reputation
    70
    Thanks
    746
    My Mood
    Blah
    Everything

    but yeah i added a fail safe just incase, but yeah i think im overrushing him with these codes no?

    [php]
    static void Main(string[] args)
    {
    main:
    int variable_value;


    Console.WriteLine("Put in a number");
    try
    {
    variable_value = Convert.ToInt32(Console.ReadLine());
    Console.WriteLine("You choosed number {0}", variable_value);
    Console.WriteLine("\n" + "Press any key to exit.");
    Console.ReadKey();
    }
    catch
    {
    Console.WriteLine("Wrong input!");
    Console.WriteLine("\n" + "Press any key to retry.");
    Console.ReadKey();
    Console.Clear();
    goto main;
    }
    }
    [/php]

    i could have used an int main but its to anoying to add an return command @ try
    at least its shorter then a while loop and then all those if fuctions...
    DigiDrawing|+ ( (Elfen Archer) )
    Link:
    https://www.mpgh.net/forum/148-showro...en-archer.html


    @ Anime Section,Otaku/weeabo (orz.) @Graphics Section, Novice DigiArtist


    neuest gift from Yura~Chan:
    https://bakyurayuu.deviantar*****m/#/d372taw
    2nd Place MOTM#9 Theme: CharMods - Combat Arms [No - Thanks] button
    come on you know that don't want to push that ordinary button

  9. #9
    thekm1994's Avatar
    Join Date
    Jan 2010
    Gender
    male
    Posts
    79
    Reputation
    8
    Thanks
    1
    My Mood
    Daring
    Wow that is a tuff thing !!! Any way thanks you all for helping me out :P
    If you wanna see how to make a someone dumb press here

  10. #10
    Kuro Tenshi's Avatar
    Join Date
    Jan 2009
    Gender
    male
    Location
    Where arth thou be
    Posts
    3,635
    Reputation
    70
    Thanks
    746
    My Mood
    Blah
    here you want so something tuff, im learning webparts now this is how far i progressed in 1.5 weeks:

    i was stuck at the ip checker but this pc had IPV6 also enabled now all i need to do is fix the counter(halfway there) and add a sharepoint modifier for the admins of the site to set the settings for the viewers.

    this is a simple program =-= god cant wait for the next prject the original thing i had to make i already had done for a week/half a week. but i need to add protection with ip and refresh and such so it takes a while to do.

    [php]
    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Data.SqlClient;
    using System.Data;
    using System.Collections;
    using System.Text.RegularExpressions;
    using System.Data.Linq;
    using System.Linq;
    using System.Xml;
    using System.Xml.Serialization;
    using System.ComponentModel;
    using System.Runtime.InteropServices;
    using Microsoft.SharePoint;
    using Microsoft.SharePoint.WebPartPages;

    namespace BadgeProjectIn_Out
    {
    /// <summary>
    /// Summary description for CustomPropertyWebPart.
    /// </summary>
    [DefaultProperty("Text"),
    ToolboxData("<{0}:BadgeProjectIn_Out runat=server></{0}:BadgeProjectIn_Out>"),
    XmlRoot(Namespace = "BadgeProjectIn_Out")]
    public class InOutDirectory : Microsoft.SharePoint.WebPartPages.WebPart
    {
    #region bootInfo::Int's,Buttons
    //private const string defaultText = "";
    //private string text = defaultText;
    int valueSelectScreen = 1;
    double Counter = 0;
    public LinkButton bAanwezig;
    public LinkButton bAfwezig;
    bool ValueCounterAtiveThreading = false;
    public Label main1;
    double val;
    string host = HttpContext.Current.Request.Url.Host;

    In_OutConnectDataContext InOutDataBase = new In_OutConnectDataContext();

    public static int DEFAULT_BORDER_SIZE = 1;
    /*
    ///<summary>

    /// This property will determine, wether to display the selected customer

    /// information in a detail pane in label controls.

    /// This will be available in a check box.

    ///</summary>

    /// <summary>
    /// Default property available form the template
    /// </summary>
    [Browsable(true), Category("Miscellaneous"),
    DefaultValue(defaultText),
    WebPartStorage(Storage.Personal),
    FriendlyName("Text"), Description("Text Property")]
    public string Text
    {
    get
    {
    return text;
    }

    set
    {
    text = value;
    }
    }*/

    #endregion

    public void CounterSettings(double setValueInSeconds)
    {
    //main1:
    this.val = setValueInSeconds;
    /*if (Counter < val)
    {
    TimeSpan.FromMilliseconds(100);//100ms waiting time for 1 sec is /10 @ counter
    Counter += 0.1;
    }
    else if (Counter >= val)
    {
    //site refresh
    InOutDataBase.Refresh(RefreshMode.KeepChanges,InOu tDataBase.Badges);
    //RefreshMode.KeepCurrentValues();
    Counter = 0;
    }*/
    }

    #region define_Table/TableStyle_Void's
    public void Add_Subtable_Style(HtmlTextWriter writer, double valuePixelWidth)
    {
    writer.AddStyleAttribute(HtmlTextWriterStyle.Borde rColor, "black");
    writer.AddStyleAttribute(HtmlTextWriterStyle.Borde rStyle, "solid");
    writer.AddStyleAttribute(HtmlTextWriterStyle.Borde rWidth, Convert.ToString(valuePixelWidth));
    writer.AddAttribute(HtmlTextWriterAttribute.Align, "left");
    writer.AddAttribute(HtmlTextWriterAttribute.Width, "400");
    }

    public void Add_Table_Styled(HtmlTextWriter writer, double valuePixelWidth)
    {
    writer.AddAttribute(HtmlTextWriterAttribute.Width, Convert.ToString(valuePixelWidth));
    writer.RenderBeginTag(HtmlTextWriterTag.Table);
    }

    public void Add_Table(HtmlTextWriter writer)
    {
    writer.RenderBeginTag(HtmlTextWriterTag.Table);
    }
    #endregion

    protected override void CreateChildControls()
    {
    bAanwezig = new LinkButton();
    bAanwezig.Text = "Afwezig";//Button Naam Van De Page = andersom dan HyperLink
    //bAanwezig.BorderStyle = BorderStyle.Inset;
    bAanwezig.Click += new EventHandler(bAanwezig_Click);



    bAfwezig = new LinkButton();
    bAfwezig.Text = "Aanwezig";//Button Naam Van De Page = andersom dan HyperLink
    //bAfwezig.BorderStyle = BorderStyle.Inset;
    bAfwezig.Click += new EventHandler(bAfwezig_Click);

    this.Controls.Add(bAanwezig);
    this.Controls.Add(bAfwezig);
    }

    public override void RenderControl(HtmlTextWriter writer)
    {
    //refresh:
    host = HttpContext.Current.Request.UserHostAddress;
    if ((hos*****ntains("192.168.") || hos*****ntains("127.0.0") || hos*****ntains("fe80::") || hos*****ntains("fec0::")) && !hos*****ntains("192.168.0.247"))
    {
    CounterSettings(20000);

    if (valueSelectScreen == 1)
    {
    bAfwezig.Style["font-weight"] = "bold";
    }
    else if (valueSelectScreen == 2)
    {
    bAanwezig.Style["font-weight"] = "bold";
    }

    //In_OutConnectDataContext InOutDataBase = new In_OutConnectDataContext();

    Table<Badge> badges = InOutDataBase.Badges;

    List<Badge> _badgesIn = (from b in badges where b.InUit_Status == 1 orderby b.Bezoeker select b).ToList();
    List<Badge> _badgesOut = (from b in badges where b.InUit_Status == 0 orderby b.Bezoeker select b).ToList();

    #region table_1_Aanwezig
    if (valueSelectScreen == 1)
    {
    writer.Write("Timer-Refresh Page:" + Convert.ToString(Counter));
    //writer.Write("<B>Aanwezig:</B>");
    writer.AddAttribute(HtmlTextWriterAttribute.Align, "center");
    Add_Table(writer);

    writer.RenderBeginTag(HtmlTextWriterTag.Tr);
    writer.AddAttribute(HtmlTextWriterAttribute.Align, "right");
    writer.RenderBeginTag(HtmlTextWriterTag.Td);
    bAfwezig.RenderControl(writer);
    writer.RenderEndTag();//td
    writer.AddAttribute(HtmlTextWriterAttribute.Align, "left");
    writer.RenderBeginTag(HtmlTextWriterTag.Td);
    bAanwezig.RenderControl(writer);
    writer.RenderEndTag();//td
    writer.RenderEndTag();//tr

    writer.AddAttribute(HtmlTextWriterAttribute.Align, "center");
    Add_Subtable_Style(writer, DEFAULT_BORDER_SIZE);
    Add_Table_Styled(writer, 200);

    for (int i = 0; i <= _badgesIn.Count - 1; i = i + 2)
    {
    writer.RenderBeginTag(HtmlTextWriterTag.Tr);
    Add_Subtable_Style(writer, 1);
    writer.RenderBeginTag(HtmlTextWriterTag.Td);
    writer.Write(_badgesIn[i].Bezoeker);
    writer.RenderEndTag();//td
    Add_Subtable_Style(writer, 1);
    writer.RenderBeginTag(HtmlTextWriterTag.Td);
    if (i + 1 < _badgesIn.Count)
    writer.Write(_badgesIn[i + 1].Bezoeker);
    else
    writer.Write("");
    writer.RenderEndTag();//td
    writer.RenderEndTag();//tr
    }


    writer.RenderEndTag();
    writer.RenderEndTag();
    ValueCounterAtiveThreading = true;
    }
    #endregion
    #region table_1_Afnwezig
    else if (valueSelectScreen == 2)
    {
    writer.Write("Timer-Refresh Page:" + Convert.ToString(Counter));
    //writer.Write("<B>Afwezig:</B>");
    writer.AddAttribute(HtmlTextWriterAttribute.Align, "center");
    Add_Table(writer);

    writer.RenderBeginTag(HtmlTextWriterTag.Tr);
    writer.AddAttribute(HtmlTextWriterAttribute.Align, "right");
    writer.RenderBeginTag(HtmlTextWriterTag.Td);
    bAfwezig.RenderControl(writer);
    writer.RenderEndTag();//td
    writer.AddAttribute(HtmlTextWriterAttribute.Align, "left");
    writer.RenderBeginTag(HtmlTextWriterTag.Td);
    bAanwezig.RenderControl(writer);
    writer.RenderEndTag();//td
    writer.RenderEndTag();//tr

    writer.AddAttribute(HtmlTextWriterAttribute.Align, "center");
    Add_Subtable_Style(writer, DEFAULT_BORDER_SIZE);
    Add_Table_Styled(writer, 200);

    for (int i = 0; i <= _badgesOu*****unt - 1; i = i + 2)
    {
    writer.RenderBeginTag(HtmlTextWriterTag.Tr);
    Add_Subtable_Style(writer, 1);
    writer.RenderBeginTag(HtmlTextWriterTag.Td);
    writer.Write(_badgesOut[i].Bezoeker);
    writer.RenderEndTag();//td
    Add_Subtable_Style(writer, 1);
    writer.RenderBeginTag(HtmlTextWriterTag.Td);
    if (i + 1 < _badgesOu*****unt)
    writer.Write(_badgesOut[i + 1].Bezoeker);
    else
    writer.Write("");
    writer.RenderEndTag();//td
    writer.RenderEndTag();//tr
    }


    writer.RenderEndTag();
    writer.RenderEndTag();
    ValueCounterAtiveThreading = true;
    }
    if (ValueCounterAtiveThreading == true)
    {
    writer.Write("Updating Counter TEST:");
    main1:
    writer.Write("<br>" + Convert.ToString(Counter) + "</br>");
    if (Counter < val)
    {
    //TimeSpan.FromMilliseconds(100);//100ms waiting time for 1 sec is /10 @ counter
    TimeSpan.FromSeconds(5);
    Counter += 0.1;
    goto main1;
    }
    else if (Counter >= val)
    {
    //site refresh

    InOutDataBase.Refresh(RefreshMode.KeepChanges, InOutDataBase.Badges);
    //RefreshMode.KeepCurrentValues();
    Counter = 0;
    //goto refresh;
    }
    }
    else if (ValueCounterAtiveThreading == false)
    {
    //nothing
    }
    #endregion
    }
    else
    {
    writer.Write("Deze site is alleen te bezoeken via de school.");
    writer.Write("Dit is uw huidige ip-adress:" + host);
    }
    }

    #region button_Events
    public void bAanwezig_Click(object sender, EventArgs e)
    {
    valueSelectScreen = 2;
    }

    public void bAfwezig_Click(object sender, EventArgs e)
    {
    valueSelectScreen = 1;
    }
    #endregion
    }
    }


    #region Auto Table Test
    /*
    #region AutoTypTableAttempt
    public void AutoAddTable(HtmlTextWriter writer, string[] table_Input, double border_PixelWidth, string Border_Colour, double tablebox_TD_PixelWidth, string tablebox_TD_Border_Colour, double tablebox_TD_Border_PixelWidth)
    {
    writer.AddStyleAttribute(HtmlTextWriterStyle.Borde rColor, Border_Colour);
    writer.AddStyleAttribute(HtmlTextWriterStyle.Borde rStyle, "solid");
    writer.AddStyleAttribute(HtmlTextWriterStyle.Borde rWidth, Convert.ToString(border_PixelWidth));
    writer.AddAttribute(HtmlTextWriterAttribute.Align, "left");
    writer.AddAttribute(HtmlTextWriterAttribute.Width, Convert.ToString(tablebox_TD_PixelWidth));
    writer.RenderBeginTag(HtmlTextWriterTag.Table);
    writer.RenderBeginTag(HtmlTextWriterTag.Tr);

    writer.AddStyleAttribute(HtmlTextWriterStyle.Borde rColor, tablebox_TD_Border_Colour);
    writer.AddStyleAttribute(HtmlTextWriterStyle.Borde rStyle, "solid");
    writer.AddStyleAttribute(HtmlTextWriterStyle.Borde rWidth, Convert.ToString(tablebox_TD_Border_PixelWidth));

    writer.RenderBeginTag(HtmlTextWriterTag.Td);

    writer.Write(table_Input);

    writer.RenderEndTag();//td
    writer.RenderEndTag();//tr
    writer.RenderEndTag();//table
    }
    #endregion

    int ival = 2;

    public override void RenderControl(HtmlTextWriter writer)
    {
    string[] test = new string[100];
    test[0] = "blah";
    test[1] = "blis";
    if (ival < 100)
    {
    test[ival] = "test";
    ival++;
    }

    AutoAddTable(writer, test, 2, "Black", 2, "Black", 1);
    }
    */
    #endregion
    [/php]
    DigiDrawing|+ ( (Elfen Archer) )
    Link:
    https://www.mpgh.net/forum/148-showro...en-archer.html


    @ Anime Section,Otaku/weeabo (orz.) @Graphics Section, Novice DigiArtist


    neuest gift from Yura~Chan:
    https://bakyurayuu.deviantar*****m/#/d372taw
    2nd Place MOTM#9 Theme: CharMods - Combat Arms [No - Thanks] button
    come on you know that don't want to push that ordinary button

  11. #11
    ZEROI9's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Posts
    88
    Reputation
    10
    Thanks
    18
    My Mood
    Amazed
    Simple?

    Console.WriteLine("Whats your age?");
    string age = Console.ReadLine();
    int yourAge = string.Parse(age);
    if(yourAge < 18)
    Console.WriteLine("You're not allowed to see this content!");
    else
    Console.WriteLine("Welcome.");