Making editors for cricket games

embi

International Coach
Joined
Dec 19, 2005
Location
guildford, surrey, england
Online Cricket Games Owned
Functions

This is the second part of my tutorial. It is another programming basic, and hopefully will be shorter.

Functions are very useful. You put a value into a function, and it pops another one out. For example, the Math.Sqr function, if you put 16 in, it will give you the square root of 16 (which is 4.).

To use a function, you need to store the value in a variable (see above). You can have a function on its own, but it won't do anything.

Subs
A sub is kind of liek a function, except it doesn't return a value. It just runs through all the instructions in the sub, for example form.Hide hides the form.

Properties
Colin also mentioned properties. A property of something is a variable, like a setting of it, for example form.Width sets the width of the form (duh) . Some properties you can't change, and they are used for you to use the value, for example strMsg.Length will tell you the number of characters (letters,number etc.) there is in strMsg.

Right thats enough theory. Next we'll be beginning to make the editor (the fun part!). Sorry I had to be boring above, but those are things you need to know.
 

cricket doctor

International Cricketer
Joined
Oct 11, 2005
Location
Doesn't matter
Online Cricket Games Owned
embi said:
Subs
A sub is kind of liek a function, except it doesn't return a value. It just runs through all the instructions in the sub, for example form.Hide hides the form.
..and to add to that, 'sub' is a keyword, which can't be used as a variable name.
embi said:
Sorry I had to be boring above, but those are things you need to know.

That wasn't boring at all mate. It is must for beginners, who haven't done any programming at all.
 

embi

International Coach
Joined
Dec 19, 2005
Location
guildford, surrey, england
Online Cricket Games Owned
One thing I forgot to mention is comments. Comments are one of the most important things in programming. In Visual Basic, any line with an apostrophe ( a ' ) before it is completely ignored. This is so that you can explain what something does in the source code without the compiler throwing an error.

Ok, on to it. We are going to make a simple program that can edit text files. I will then provide more tutorials (hopefully, don't quote me on this) on how to manipulate the text.

Ok, lets design the form. Put two buttons and a text box on. Now, as in Colin's tutorial, you are going to edit their properties.
Call the first button "btnOpen" and call the second button "btnSave" (change the name property). Next, change the text properties of both to Open and Save (isn't it obvious we were going to do that?)
Right. Now we need to change the textbox. Change the name property to txtFile (notice we are keeping in with the visual basic coding conventions), and clear the text property (set it to nothing).
Now find a property of the textbox called Multiline. You need to set this to True so that you can resize the textbox bigger. Do that now.

By now you should roughly have the following (don't worry about being exact, just about that layout looks nice) :
 

Attachments

  • tutorial.GIF
    tutorial.GIF
    82.6 KB · Views: 138

embi

International Coach
Joined
Dec 19, 2005
Location
guildford, surrey, england
Online Cricket Games Owned
..and to add to that, 'sub' is a keyword, which can't be used as a variable name.

Damn, key words, forgot those. If you try a nice variable name like Sub, you will get an error because Visual Basic thinks you're starting a sub.
If you want to name a variable sub, there are two things you can do:
Call it something other than sub (like _sub)
Put square brackets round it (like )

Final thing we need to do with the interface is to add an OpenFileDialog control to the form. In the toolbox (or whereever your controls are) find the OpenFileDialog control. Drag it onto the form, and a bar will appear at the bottom with it listed in. Click on it.
Set the name property to dlgOpen. If you want to, explore the other properties, but the only other you need to set is the filter. This only shows the files we specify. Type:
Text files (*.txt)|*.txt

The first part (before the vertical line |) is the description, the second is the filter (format *.extension). Seperate multiple filters with anthoer |. Another useful one might be All files, which is *.*


Right, on with this. We are now doing the coding to open and read the file. There are two ways to do it (traditional or modern): I am going to teach you both. It will be up to you to decide which is better.

First double click on the Open button. It should show the code screen.

Method 1: Traditional VB method

Ok, first we need to declare a couple of variables. One will be to store all the text in the file, and the other will store 1 line of text, so

Code:
Dim AllText, LineOfText As String

Note the comma. That just shortens it from two lines to one. It is the same as:
Code:
Dim AllText as String
Dim LineOfText as String

Next we need to show the File open dialog. Type

Code:
dlgOpen.ShowDialog

Right, that will have to get you through the weekend. I'll be back Monday night, so don't expect anything else until Tuesday. Meanwhile, tell us how you're all getting on. I'm sure the pros in here will be happy to answer your questions.

Please tell me how I am doing...
 

sid_19840

International Coach
Joined
Jun 28, 2005
Location
Kolkata,India
Online Cricket Games Owned
I think rather than teaching the basics,we should quicky move on to explaining files and how to load and save them.

Here is the source code of the AI manager that I had made earlier.Maybe this might help.
 

Attachments

  • AI Souce Code.zip
    185.8 KB · Views: 36

Skater

ICC Chairman
Joined
Jan 12, 2004
Profile Flag
England
Purely out of interest I had a go.
firstap0nv.jpg

Not bad!
 

embi

International Coach
Joined
Dec 19, 2005
Location
guildford, surrey, england
Online Cricket Games Owned
Yep, if more people join in, it would be better... When I find some time I will continue the tutorial on file opening/saving.
good work skateboarder
 

embi

International Coach
Joined
Dec 19, 2005
Location
guildford, surrey, england
Online Cricket Games Owned
Right, briefly from the beginning:
Create a form like this, naming the controls (objects) like this:
btnOpen, btnSave and txtFile.


030420061827318sf.png




Then drag an OpenFileDialog onto the form and name it dlgOpen:


030420061829321qp.png



Next double click the Open button, which should take you to a screen like this:


030420061831290az.png



Between the lines Private Sub... and End Sub, type the following:

Code:
        Dim AllText As String
        Dim LineOfText As String
        dlgOpen.ShowDialog()

Now run it, click on the Open button and this should be what you get:


030420061836443vn.png



Post a screenie of your effort and I'll rep you. Tomorrow I will continue, so that we actually open a file.

Also, as a side note, it would be nice to see more people taking interest in this, maybe we could get more publicity?
 

Skater

ICC Chairman
Joined
Jan 12, 2004
Profile Flag
England
I have managed to build on the application I made earlier to make it more useful and a bit easier on the eye. What do you think? Remember I only started to learn this at 12:00pm today!
screenshot2gb.jpg

I didn't know it was so easy to do.
 

usy

Chairman of Selectors
Joined
May 2, 2005
Online Cricket Games Owned
Good work SkateBoarder, i am about to download the Basic one, but it looks hard to me.
 

embi

International Coach
Joined
Dec 19, 2005
Location
guildford, surrey, england
Online Cricket Games Owned
Wow Skateboarder! Pretty impressive, reps just for improvising on your own... One thing you could change is to add a background to the checkboxes as well, but other than that it is very impressive...what happens when you click the submit button?
 

Skater

ICC Chairman
Joined
Jan 12, 2004
Profile Flag
England
A prompt came up saying how it was a minor miracle that everything worked!
 

Users who are viewing this thread

Top