Jump to content


Check out our Community Blogs

CommittedC0der

Member Since 13 Nov 2009
Offline Last Active Apr 07 2016 04:17 PM
-----

#592018 Application with Accessibility for Blind People

Posted by CommittedC0der on 21 February 2011 - 05:37 PM

Its actually not to hard to make the computer talk in C#.
Speaking Computer in C# (C# Programming Tutorial) • Geekpedia

It might be another story if you want to read text of another application(not in the winForms).
~ Committed.
  • 1


#591999 Multiplayer online browser game!

Posted by CommittedC0der on 21 February 2011 - 12:54 PM

Well the best solution would be to use Flash, the most common tool to create 2D(and some 3D) online games. You can get a free 30 day trail of Flash here: animation software, multimedia software | Adobe Flash Professional CS5

Once you have that you can start looking around, and get some experience with flash before you start creating your chess game.(if thats what you wish to create)
http://www.google.co...5fc6a07c812d0bf

And these tutorials are pretty good.
Play Shootorial #1: ActionScript 3, a free online game on Kongregate

Good luck ~ Committed.
  • 1


#591252 Learn Hacking

Posted by CommittedC0der on 13 February 2011 - 02:20 PM

This is a pretty cool site, it has alot of tutorials, and challenges to work through.
Hack This Site!

~ Committed.
  • 1


#591080 Lua - What to code?

Posted by CommittedC0der on 11 February 2011 - 09:36 AM

I agree, it is hard to come up with an idea sometimes, but just start out with the basics, maybe a simple guess the number game, or calculator. You can also check out this huge list of projects.
http://www.dreaminco...ect-ideas-list/

Good luck ~ Committed. :)
  • 1


#590923 Working With Functions(A.K.A Methods)

Posted by CommittedC0der on 09 February 2011 - 07:24 PM

Ello, everyone! :)

Alright lets jump right in and go over how this is gonna work. In this tutorial we will go over Functions! I will explain what we are doing, or what need to do, and try to comment out every line of code, so you know exactly whats happening in every line.

Be for we get started, create a new windows form application, and just add a button along with a buttonClick event.

So lets explain what a function is, and how its different from a method.

What Is a Function? How Is It Different From A Method?
To answer the first question, a function is a block of code which we can call upon from multiple places in our code. This is very useful if you need to repeat a piece of code, but dont want to write it out 2 or 3 times. Now the difference between a method and a function as I see it is; A method is a function declared within a class. So if you create a "function" in your code, its called a function, but if you create a function in a separate class, its called a "Method". (Hope that was understandable)

How A Function Works, And Where To Use It.
First lets go over where to use a function. You should use a function anywhere you would normally have to write the same code over multiple times. For example if you wanted to write a big line of text into a textBox multiple times, it would be wise to create a function that did this for you. Then you wouldnt have to write the big line of text every time you needed it to go into the textbox, you would just let the function do it for you.
Another reason to use a function is to clean up code. If for instance you want to write the big line of text to the textBox and do some other things, it would be nice to just call the function and let it do the work for you while keeping the mess elsewhere, making it much easier for you to work with the "other things".

Now hopefully you where able to understand what I was saying above. Lets learn how a function works!
We declare a function like this:
<Access Modifier> <return type> <name> (<parameters>)
{
<OurCodeGoesHere>
}

What do these things mean?
<modifier> - View Link
This link will show the different type's of modifiers and what they do.
Access Modifiers (C# Programming Guide)

<return type> - This can be any variable type: Int, Double, String, Char ect...
This is the type of return variable we want to use in our function. When we create a function we can create a "return" statement that will return the value of the given variable, so we must assign the type of variable we want to return. If you dont have any variable value to return you simple type "void" meaning its void of a return value.

<name>
Simply what ever you wish to name function, but also how we will reffer to it. Since we refer to the function by its name its normally named something descriptive to what it does.

<parameters>
- Any variable type or object.
Parameters allow us to take dynamic value's and use them in our function. For instance if we wanted to create a function that took the users name and display it in our function, we would have a string parameter. As we called that function we could fill that parameter with the username and the function could display it for us. If you dont want any parameters, you can simply leave the parenthesis empty.
We'll have some examples later.

<OurCodeGoesHere>
Pretty obvious, but this is where the code we want to execute will go in the function.

Alright you should understand the basics of a function, so lets continue.

Creating Our First Function.
Lets go ahead and create our first function! In this function we will simply display a welcome message in a messageBox.
public void DisplayWelcome()[COLOR=green]//Create a new public function with no return type, named "DisplayWelcome".[/COLOR]
{
MessageBox.Show("Welcome User");[COLOR=green]//Welcome the user...[/COLOR] [COLOR=red]lol[/COLOR]
}
Now that we have a function declared we can call it, in our buttonClick event like so:
DisplayWelcome();[COLOR=green]//Call the function by its name "DisplayWelcome" follow by parentheses '(' and ')' which is where parameters would go if we had any.(we'll go over them shortly)[/COLOR]
And thats really the basics of a function. I hope your starting to understand how they work.

Using "return" In Our Function.
Now, lets learn to make our function a little more dynamic, by using the "return" statement.

As we went over before we can return a variable from are function with the "return" statement. So lets create a function that returns someones userName.
public string  DisplayWelcome()[COLOR=green]//Create our public function, this time with a return type of "string".[/COLOR]
{
string userName = "John";[COLOR=green]//Create a new userName string, John.[/COLOR]
return userName; /[COLOR=green]/return the value of userName( or "John" basically)[/COLOR]
}
Now with the above function declared we can call it in our code, although we call it slightly different from our first example, since its actually returning the value of userName we can use it, in a messageBox like this:
MessageBox.Show("Welcome, " + DisplayWelcome().ToString());
Then when the function is executed it will display "Hello, " plus the return value of "DisplayWelcome" which is userName, giving the outcome of, "Welcome, John".

Using Parameters.
We will once again use our "DisplayWelcome" function, although it will be a little different since where adding parameters. As you know, parameters will allow us to take value's given when we call the function. For example, this time lets actually assign the userName when we call the function, so its not just set as "John".
public void DisplayWelcome(string Name)[COLOR=green]//Our previous function, now with a string parameter(Name) to hold the value of our name.(notice a void return type since we wont be needing any return value's.)[/COLOR]
{
MessageBox.Show("Welcome, " + Name);[COLOR=green]//This will display "Welcome, " then the value of Name, which we give when calling the function.[/COLOR]
}
Now to call out function in the buttonClick event
DisplayWelcome("c0der");[COLOR=green]//We call our "DisplayWelcome" filling the parameter with the string "c0der".[/COLOR]
Run your application and you should see "Welcome, c0der" or whatever name you entered for the parameter.

And thats it for functions!

Wrapping Up.
So we've learn what a function is, how its different from a Method, and where to use them in our code. We also learn how to use functions, the "return" statement, and parameters. I hope that covers everything, and that you enjoyed this tutorial without to much confusion.

As always +rep, comments, and suggestions welcome!
Happy C0ding ~ Committed. :)
  • 1


#590881 Chat spammer

Posted by CommittedC0der on 09 February 2011 - 12:24 PM

In the timer porperties change the interval value. The frequance is in milliseconds, so the ratio is 1000m = 1 second.
Or you can use this code.
timer1.Interval = 1000

~ Committed. :)
  • 1


#590645 Adobe Flex/Air RIA developement under GNU/Linux

Posted by CommittedC0der on 07 February 2011 - 01:07 PM

In that case this may help.
Free IDEs for Flex and AIR Development | rainwebs.net

Good luck ~ Committed. :)
  • 1


#589891 Writing multiline txt to richTextBox - data from checbkoxes

Posted by CommittedC0der on 31 January 2011 - 12:19 PM

You mean like write teh text from the textBox into a .txt file on your HD?

Try this tutorial.
http://forum.codecal...text-files.html
  • 1


#589659 Connecting a button to picturebox and putting up random images in the picture...

Posted by CommittedC0der on 29 January 2011 - 06:08 PM

First off please use code tags like this: [CODE*]Code here[/CODE*] just remove the '*' symbol. ;)

And I think this code should work. It may not be the best solution, but for now I gtg.
private void button1_Click(object sender, EventArgs e)
        {

            int index = rand.Next(0, RemainNums.Count - 1);
            ARandomNumber = RemainNums[index];
            RemainNums.RemoveAt(index);

            string path = @"\\Fs\Homedir\sys09gma\Desktop\Kortlek\Kortlek  \";
            pictureBox1.Image = Image.FromFile(path + ARandomNumber + ".png");
 index = rand.Next(0, RemainNums.Count - 1);
             ARandomNumber = RemainNums[index];
             RemainNums.RemoveAt(index);
            pictureBox2.Image = Image.FromFile(path + ARandomNumber + ".png");
 index = rand.Next(0, RemainNums.Count - 1);
             ARandomNumber = RemainNums[index];
             RemainNums.RemoveAt(index);
            pictureBox3.Image = Image.FromFile(path + ARandomNumber + ".png");
 index = rand.Next(0, RemainNums.Count - 1);
             ARandomNumber = RemainNums[index];
             RemainNums.RemoveAt(index);
            pictureBox4.Image = Image.FromFile(path + ARandomNumber + ".png");
            Console.WriteLine(ARandomNumber);

        }
Also check out: Using a Timer in C# - Stack Overflow
I think the 3rd post from BFree may help you.
Good Luck ~ Committed.
  • 1


#589653 IP chat C#

Posted by CommittedC0der on 29 January 2011 - 05:46 PM

This article may be of interest to you. :)
C# Chat: Part 1 - Building the Chat Client (C# Programming Tutorial) • Geekpedia

~ Committed.
  • 1


#588881 Duriosoft.com really needs some review

Posted by CommittedC0der on 23 January 2011 - 01:46 PM

I like the website alot! Its very clean and has nice amounts of color. :thumbup1:
  • 1


#588655 Read & Replace - .txt files

Posted by CommittedC0der on 21 January 2011 - 04:34 PM

Whoa boy! Im pretty sure the only way to go about doing something like that is Regular expressions(Regex). Just to let you know Regex is NOT fun! This is what your code might look like to do what you stated above:
Regex rex = new Regex("123.*?\\ ");[COLOR=green]//See that "[COLOR=red].*?\\ [/COLOR]" ? Yeah thats regex, it finds '123' and searches until it finds a space.[/COLOR]
            int selectionStart = textBox1.SelectionStart;
            foreach (Match m in rex.Matches(textBox1.Text))
            {
                textBox1.Select(m.Index, m.Value.Length);
                textBox1.SelectedText = "New Text here";
                textBox1.Select(selectionStart, 0);
            }
I believe this is the Regex to pick up urls: (Got it offline so not sure if its exact)
[COLOR=blue]/[^="]http|ftp|gopher:\/\/[^ \n\r]+ (?=[\s\.,]) /
[/COLOR]
Not fun stuff.

~ Committed.
  • 1


#588625 Read & Replace - .txt files

Posted by CommittedC0der on 21 January 2011 - 11:11 AM

Here try this:
string tb = textBox1.Text;
            string[] file = File.ReadAllLines(@"C:\Users\Bot\Desktop\work\test.txt");

            foreach (string line in file)[COLOR=green]//Where searching the file for occurrences of 'line' not tb.[/COLOR]
            {

                if (line.Contains("Text What Needs Replacing"))
                {
                    tb = line.Replace("Text What Needs Replacing", "Replacement Text");
                    continue;
                }

            }
EDIT: Are you trying to remove 'x' from the textbox? And not a file?
EDIT2: If you are you can just use this code:
textBox1.Text = textBox1.Text.Replace("replace this", "with this");

Hope this works. ~ Committed. :)
  • 1


#588553 Read & Replace - .txt files

Posted by CommittedC0der on 20 January 2011 - 02:42 PM

Well you can sort data stored in an array. So I suggest you read up on arrays, how to read .txt files into an array, and how to sort data in arrays. Here's some links:
My Array Tutorial: http://forum.codecal...ial-arrays.html
Still trying to find a nice tutorial on reading a .txt file into an array. :P
Sorting Arrays [C#]

Good Luck ~ Committed. :)
  • 1


#588547 Read & Replace - .txt files

Posted by CommittedC0der on 20 January 2011 - 02:13 PM

Alright try reading this code.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main([COLOR=red][COLOR=black]string[] [/COLOR]args[/COLOR])
        {
            [COLOR=red]StringBuilder [/COLOR]newFile = new [COLOR=red]StringBuilder[/COLOR]();[COLOR=green]//StringBuilder is a built in class in C# That lets you construct large strings in a more efficient manner,[/COLOR] [COLOR=green]then just using a normal string.[/COLOR] [URL="http://www.switchonthecode.com/tutorials/csharp-snippet-tutorial-using-stringbuilder"]StringBuilder[/URL] [COLOR=green]<-- Nice Tutorial explaining it a little more clearly.[/COLOR]
            string temp = "";

            [COLOR=black]string[] file [/COLOR]= File.ReadAllLines(@"C:\Users\Bot\Desktop\work\test.txt");

            foreach (string line in file)
            {

                if (line.[COLOR=red]Contains[/COLOR]("Text What Needs Replacing"))[COLOR=green]//If 'line', which is obviously a line in the .txt file, contains "Text What Needs Replacing" continue, if not, goto the next 'line'.[/COLOR]
                {

                    temp = line.[COLOR=red]Replace[/COLOR]("Text What Needs Replacing", "Replacement Text");[COLOR=green]//This code works like this: line.Replace("text to replace", "text to replace with"); so it would change all occurrences of "text to replace" to "text to replace with".[/COLOR] 

[COLOR=red]                    newFile.Append(temp + "\r\n");[/COLOR][COLOR=green]//What '.Append' does is add a the given string(temp + \r\n) to a string which is newFile. BTW \r\n go's to the next line in the file.

                    [/COLOR][COLOR=black]continue;

                }

               [/COLOR][COLOR=black][COLOR=red]newFile.Append(line + "\r\n");[COLOR=green]//Same as before accept this time where adding 'line' to the string.[/COLOR][/COLOR]

            }

            [/COLOR][COLOR=black][COLOR=red]File.WriteAllText[/COLOR](@"C:\Users\Bot\Desktop\work\test.txt", [/COLOR][COLOR=black]newFile.ToString());[COLOR=green]//All File.WriteAllText does is writes a string(in this case newFile) to a given file.
    [COLOR=black]    }
    }
}


[/COLOR][/COLOR][/COLOR]
OK, well I hope this answered your questions, if you still dont understand just ask. ~ Committed. :)
  • 1




Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download