What are some good beginner programs I shouold make?

This is a discussion on What are some good beginner programs I shouold make? within the C# Programming forums, part of the General Programming Boards category; What are some good beginner programs I shouold make? I need pratice. They need to be beginner or near it ...

  1. #1
    Registered User
    Join Date
    Jul 2003
    Posts
    97

    What are some good beginner programs I shouold make?

    What are some good beginner programs I shouold make? I need pratice. They need to be beginner or near it however. A Bank is too hard for me it seems, so many commands I dont understand for the bank program.

  2. #2
    and the Hat of Clumsiness GanglyLamb's Avatar
    Join Date
    Oct 2002
    Location
    between photons and phonons
    Posts
    1,109
    What is too difficult for you exactly, the OO concept, the GUI - form controls, or something else.

    If its a basic understanding of C# that you lack maybe youŽre better of first writing some console program.
    Get familiar with OO and write some of your own classes. Learn how to use most common used libraries ( although there are alot )...

    I never really learned C# since i started out with Java, went to J# and recently started in C# but since most of the things are practically the same in C# as they are in J# I understood everything rather fast.

    The book Codenotes J#
    helped me alot, I dont know if thereŽs a codenote on C# but if there is i think it would be as good as the codenotes on J# from msdn.

    [edit]
    Have you looked at this thread
    Last edited by GanglyLamb; 08-09-2005 at 04:03 AM.

  3. #3
    Registered User
    Join Date
    Jul 2003
    Posts
    97
    I checked that thread before, and all those tutorials have nothing for Windows Applications. I know C++ already, well, 1/4 of it, If I wanted to make a Console app. , I would go to C++ and code that. I came to C# for the Visuals, and thats something I love.

    What I dont understand, is your code on the Bank program. I understand a lot of it, but dont understand the important parts. Ive just never seen that code before.

    Code:
        private void textBox_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e) {
          if(e.KeyCode == Keys.Enter){
            try{
              a.addToBalance(float.Parse(deposit_TextBox.Text));
              if(!a.subtractFromBalance(float.Parse(withdraw_TextBox.Text))){
                balance_lbl.Text = "Credit Exceeded"; 
              } else {
                balance_lbl.Text = ""+a.getBalance();
              }
              info_lbl.Text = "";
            } catch(FormatException fException){
              info_lbl.Text = "Verify that withdraw and deposit are numbers.";
            }
          }
        }
    What the heck is that LoL. I dont understand any of those code keywords. And tutorials cant help, Ive yet to find a Windows Application tutorial.

  4. #4
    and the Hat of Clumsiness GanglyLamb's Avatar
    Join Date
    Oct 2002
    Location
    between photons and phonons
    Posts
    1,109
    Alright Ill give a brief explanation on the code i used there.

    What i first did to make that bank program was to do my layout of the form.
    I added the textboxes, and all the labels.
    After that i wrote the Account class, which is self explanatory ( if not just tell me ).

    After that I went back to Form1.cs in the designer view, i double clicked the form, standard youŽll get thrown somewhere in the code of Form1. But Visual Studio already made a function for you ( because you double clicked the form ) thatŽs where this code comes from.
    Code:
    private void Form1_Load(object sender,System.EventArgs e) {
      a = new Account(50,100);
      balance_lbl.Text = a.getBalance().ToString();
      limit_lbl.Text = a.getLimit().ToString();
    }
    Now what does this code do:

    When the form gets loaded IŽll have an object created called a, using my own constructor written in the Account class. Thus already setting the limit and the starting balance of the account object. I then call the method getBalance and put the value into the balance label, the same happens for the limit value.

    After that I went to see how I could make sure that when you hit enter it will add or subtract from the account.

    So i went back to the designer view. I selected one of the two textboxes, at the properties of the selected control i then went to the thingy that looks like a flash ( the ones you have when it thunders ).
    Anyway those are the events which can be triggered from within this control - in this case the textbox.

    So there i select the KeyDown, and doubleclick.
    You should again enter into the code somewhere, visual studio should have made a method called textboxName_Keydown(...). Now do the same thing for the other textbox just dont double click again next to the KeyDown area, you use the selection option to select the methode that was previously created ( in my example the textBox_Keydown method.

    Now when either one of these two textboxes is selected - is focussed on. And you hit any key this method will start to run.
    First of all I check if the key that has been pressed is the ENTER key. If so we try to execute all the code that is between the
    Code:
    try{
    }
    This is just in case you enter a letter and then hit enter, since during the try we will try to convert the value from within the textboxes to floats, if this is a letter or a string it will not work and throw an exception, so if an exception is thrown we catch it - and thus making sure our program will not crash on an error like this.
    Code:
    catch(FormatException f) {
    }
    Within this piece of code you basically put everything that is needed to handle the error that is caused.
    This method is not 100% watertight though, since when you dont fill anything out in the textboxes, it wont throw an exception ( i think ) - but the cod can easily be modified to also check for this thing.

    So back to try block.
    Code:
    a.addToBalance(float.Parse(deposit_TextBox.Text));
    if(!a.subtractFromBalance(float.Parse(withdraw_TextBox.Text))){
      balance_lbl.Text = "Credit Exceeded"; 
    } else {
      balance_lbl.Text = ""+a.getBalance();
    }
    info_lbl.Text = "";
    Since we know we hit enter when we are in this block of code we do what is supposed to be done, add the deposit amount and withdraw the withdrawal amount.
    Since my method addToBalance accepts a float as argument i need to parse the deposit_Textbox - note that this is also the place where the FormatException can be thrown.
    Then we try to subtract the withdraw amount from our balance, if this amount is over our limit then we should tell the user that we exceeded our limit/credit. If not update the balance label with the right balance.

    After all this we clear our info label, because, suppose you enter a string in one of the textboxes an exception will be thrown, thus our info label will be updated and the string "Verify that withdraw and deposit are numbers." will sit as text in the label. It will stay there unless we remove it manually, thats why i putted this line:
    Code:
    info_lbl.Text = "";
    So the error wont keep showing although nothing is wrong with our input.

    Since this is a long post forgive me if there are any word mis spelled ( my english isnt that good so ...) or any typos.

    [edit]
    I learned alot myself by putting some controls onto the form, add some events and then go and look into your code, there should be something like
    Windows Form Designer generated code
    Expand this menu and youŽll see all your controls with the properties you selected in the designer view, it has helped me to understand alot of what is actually being done in the designer view.
    Last edited by GanglyLamb; 08-09-2005 at 01:03 PM.

  5. #5
    Registered User
    Join Date
    Jul 2003
    Posts
    97
    Ok, that cleared some up. Thanks

    But still, anybody know any beginner programs I should make for pratice, and/or WINDOWS APPLICATION C# tutorials?

  6. #6
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,048
    Tic-Tac-Toe is an essential. I also did Minesweeper (twice).

    [edit]
    Tutorials: try here.
    [/edit]
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  7. #7
    Registered User
    Join Date
    Jul 2003
    Posts
    97
    Sigh...ive done countless searches on Google. As said, NONE have Windows Application tutorials

    Isnt Tic Tac Toe hard though? I have no idea how I would even start a thing like it

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Question about atheists
    By gcn_zelda in forum A Brief History of Cprogramming.com
    Replies: 160
    Last Post: 08-11-2003, 12:50 PM
  2. Triying to make an RPG...... usuccesfully
    By Marcos in forum Game Programming
    Replies: 6
    Last Post: 06-12-2003, 12:33 AM
  3. Replies: 8
    Last Post: 07-20-2002, 10:23 AM
  4. Whats a very simple but good game i can try to make?
    By bluehead in forum C++ Programming
    Replies: 2
    Last Post: 11-06-2001, 09:24 PM
  5. programs to make
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 10-31-2001, 09:22 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21