Hints+2008+Semester+1

=Handy Hints Semester 1, 2008=

Note: If your Hint is more than a paragraph long, please put it on a separate page.
=Baker, Judith=  ==Comment Keyboard Shortcuts     == ==  <span style="font-size: 80%; font-family: 'Trebuchet MS',Helvetica,sans-serif">       ==

<span style="font-family: 'Trebuchet MS',Helvetica,sans-serif"><span style="font-size: 80%; font-family: 'Trebuchet MS',Helvetica,sans-serif">Comment blocks are great to comment/uncomment a whole section of code easily in VB. Once you know the shortcut keys for doing so, it is even easier, as you don't even have to reach for the mouse. <span style="font-size: 80%; font-family: 'Trebuchet MS',Helvetica,sans-serif"><span style="font-family: 'Trebuchet MS',Helvetica,sans-serif"> <span style="font-family: 'Trebuchet MS',Helvetica,sans-serif"><span style="font-size: 80%; font-family: 'Trebuchet MS',Helvetica,sans-serif"><span style="font-size: 130%; color: rgb(47, 10, 230)"><span style="font-size: 130%; color: rgb(47, 10, 230)">       <span style="font-size: 80%; font-family: 'Trebuchet MS',Helvetica,sans-serif"><span style="font-family: 'Trebuchet MS',Helvetica,sans-serif"> <span style="font-family: 'Trebuchet MS',Helvetica,sans-serif"><span style="font-size: 80%; font-family: 'Trebuchet MS',Helvetica,sans-serif"> <span style="font-size: 80%; font-family: 'Trebuchet MS',Helvetica,sans-serif"><span style="font-family: 'Trebuchet MS',Helvetica,sans-serif"> These shortcuts will comment/uncomment the current line if nothing is selected <span style="font-family: 'Trebuchet MS',Helvetica,sans-serif"><span style="font-size: 80%; font-family: 'Trebuchet MS',Helvetica,sans-serif"> Comment blocks are great to comment/uncomment a whole section of code easily in VB. Wrap Label Text on Forms <span style="font-size: 80%; font-family: 'Trebuchet MS',Helvetica,sans-serif"><span style="font-family: 'Trebuchet MS',Helvetica,sans-serif"> <span style="font-family: 'Trebuchet MS',Helvetica,sans-serif"><span style="font-size: 80%; font-family: 'Trebuchet MS',Helvetica,sans-serif"><span style="font-size: 130%; color: rgb(47, 10, 230)"><span style="font-size: 130%; color: rgb(47, 10, 230)">
 * <span style="font-family: 'Trebuchet MS',Helvetica,sans-serif"><span style="font-size: 80%; font-family: 'Trebuchet MS',Helvetica,sans-serif"> Ctrl + K + C = Comment Block the currently selected code
 * Ctrl + K + U = Uncomment Block the currently selected code

=Bick, Tanis=

=Bignell, Jason= Ctrl + Space is your friend. this handy shortcut can be used at anytime to look through all possible endings for what you have typed. However, it is so much more. it can also be used to look through varibles, object,methods etc, simpl by clicking it when on an empty line. but wait, there's more! If there is only one thing that starts with what you have typed, it will complete it for you. (note: while scrolling through it, if you press tab, it will fill in the selected item for you!)

The local window.... wow, why did i ever use quick watch? It is a very similar to the quick watch window, only it automaticly adds all current varibles. Handy no? =Dennison, Jennifer=

=Dixon, Steven=

=<span style="display: block; color: rgb(199, 0, 255); font-family: 'Comic Sans MS',cursive; background-color: rgb(231, 255, 0); text-align: center">Gilbert, Mary-Anne : - ) =

**Checking Input in Text Boxes**
=Hewton, Grant= eg. To disable multiple textboxes you would highlight and select all the required textboxes and then simply change the properties of all of them at once!
 * Setting Properties in Form Design for Multiple Controls**

procedure(ByVal sender as system.object)** procedure(sender) calling procedure passing sender as a system.object this allows you to case sender.tag in your procedure Select Case sender.tag case "1" do this stuff case "2" do this stuff End Select sender.tag = "" 'takes the tag away so the control wont be used twice
 * Using the Tag property so you can restrict the use of the control in question

=Jones, Alisha<span style="color: rgb(0, 0, 255)"> = Dim fname = <span style="color: rgb(128, 0, 0)">" Bill "

MessageBox.Show(<span style="color: rgb(128, 0, 0)">"Hello" & Trim(fname) & <span style="color: rgb(128, 0, 0)">"Gates" ) <span style="color: rgb(0, 128, 0)">' removes all spaces

MessageBox.Show(<span style="color: rgb(128, 0, 0)">"Hello" & LTrim(fname) & <span style="color: rgb(128, 0, 0)">"Gates" ) <span style="color: rgb(0, 128, 0)">' removes spaces to the left of the word

MessageBox.Show(<span style="color: rgb(128, 0, 0)">"Hello" & RTrim(fname) & <span style="color: rgb(128, 0, 0)">"Gates" ) <span style="color: rgb(0, 128, 0)">' removes spaces from the right of the word

the Trim function removes any spaces on the left or right of the word variable.

Randomize <span style="color: rgb(0, 0, 255)">Dim randomNumber = Int(100 * Rnd) MessageBox.Show(<span style="color: rgb(128, 0, 0)">"Random number: " & randomNumber)

Rnd displays a random number each time it is clicked on. You need a number to limit the range of random numbers

=Keating, Tristan=

Tab Order
When you are waiting to redo the //Tab Order// for a page, instead of redoing the tab order via the //Properties// task pane, use //View// » //Tab Order//. Numbers will appear, and then you click the controls in the order you like. Be sure to do every control. To stop //Tab Order//, turn it back off with //View// » //Tab Order//.

Adding Handlers
For those that seek to create new controls to forms at run-time, here's a great way to add functionality. This command is the key:

<span style="color: rgb(0, 0, 255)">AddHandler btnNew.Click, <span style="color: rgb(0, 0, 255)">AddressOf btnNew_Click

Where //btnNew.Click// is the click event of the new button and //btnNew_Click// is a sub.

=Kennett, Adam= ~ Using the directional arrows keys, you can move the selected object pixel by pixel for accurate assembly. ~ In the code view, click on the tab window. Then click add split. This will create a split half way down the screen allowed you to work or look at two different part of code in the code view. (ca you upload pics onto her, or do i just upload somewhere else and copy the url here??)

=Kenny, Owen= An easy way to convert numeric data to currency is the **FormatCurrency** function. Example: You have to display the result of a simple equation to calculate an employees pay in a text box using their hourly rate and the hours worked.

Dim hoursWorked as double Dim payRate as double

txtPay.Text = FormatCurrency( hoursWorked * payRate )

The result will display in the text box txtPay in currency format. Saves you having to put in your own format specification! =Kirkpatrick, Keiran=
 * Use regions to organise your code.**

Example:

Private Sub Me_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown Code goes here End sub
 * 1) Region "Example statements"
 * 1) End Region

This will allow you to sort your code into expandable/collapsible groups using the +/- icons on the left.

Methods that do not access instance data or instance methods can be marked as Shared. This will allow the compiler to generate code that is more optimized for performance.
 * Shared Methods**

=Ledo, Aiden= || <span style="color: rgb(9, 0, 255)"><span style="color: rgb(250, 249, 249); background-color: rgb(28, 29, 253)"><span style="color: rgb(243, 233, 205)"> **Description** || || <span style="color: rgb(9, 0, 255)"><span style="color: rgb(250, 249, 249); background-color: rgb(28, 29, 253)"><span style="color: rgb(243, 233, 205)"> Brings up the 'Object Browser' window || || <span style="color: rgb(9, 0, 255)"><span style="color: rgb(250, 249, 249); background-color: rgb(28, 29, 253)"><span style="color: rgb(243, 233, 205)"> Brings up the 'Properties Window' for the current form/control || || <span style="color: rgb(9, 0, 255)"><span style="color: rgb(250, 249, 249); background-color: rgb(28, 29, 253)"><span style="color: rgb(243, 233, 205)"> Executes the current project || || <span style="color: rgb(9, 0, 255)"><span style="color: rgb(250, 249, 249); background-color: rgb(28, 29, 253)"><span style="color: rgb(243, 233, 205)"> First checks for syntax errors and then executes the project || || <span style="color: rgb(9, 0, 255)"><span style="color: rgb(250, 249, 249); background-color: rgb(28, 29, 253)"><span style="color: rgb(243, 233, 205)"> Opens the code window for the current control || || <span style="color: rgb(9, 0, 255)"><span style="color: rgb(250, 249, 249); background-color: rgb(28, 29, 253)"><span style="color: rgb(243, 233, 205)"> Executes the project in 'Step mode'. Keep pressing F8 to execute the next statement; Press F5 to come out of step mode || || <span style="color: rgb(9, 0, 255)"><span style="color: rgb(250, 249, 249); background-color: rgb(28, 29, 253)"><span style="color: rgb(243, 233, 205)"> Inserts break point at the current line in the code window. Press F9 again to toggle the break point || || <span style="color: rgb(9, 0, 255)"><span style="color: rgb(250, 249, 249); background-color: rgb(28, 29, 253)"><span style="color: rgb(243, 233, 205)"> Brings up the 'Immediate window', which is useful for debugging purposes || || <span style="color: rgb(9, 0, 255)"><span style="color: rgb(250, 249, 249); background-color: rgb(28, 29, 253)"><span style="color: rgb(243, 233, 205)"> While writing code, this combination helps you see the available options/methods/properties based on what you are typing || || <span style="color: rgb(9, 0, 255)"><span style="color: rgb(250, 249, 249); background-color: rgb(28, 29, 253)"><span style="color: rgb(243, 233, 205)"> Same as above...    || || <span style="color: rgb(9, 0, 255)"><span style="color: rgb(250, 249, 249); background-color: rgb(28, 29, 253)"><span style="color: rgb(243, 233, 205)"> Place the cursor over any function call and press Shift + F2 to see the declaration of that function ||  || <span style="color: rgb(9, 0, 255)"><span style="color: rgb(0, 0, 0)"><span style="color: rgb(250, 249, 249); background-color: rgb(28, 29, 253)"><span style="color: rgb(243, 233, 205)"> Brings up the find dialog box ||  || <span style="color: rgb(9, 0, 255)"><span style="color: rgb(0, 0, 0)"><span style="color: rgb(250, 249, 249); background-color: rgb(28, 29, 253)"><span style="color: rgb(243, 233, 205)"> Brings up the replace dialog box ||   || <span style="color: rgb(9, 0, 255)"><span style="background-color: rgb(255, 255, 255)"><span style="color: rgb(0, 0, 0)"><span style="color: rgb(250, 249, 249); background-color: rgb(28, 29, 253)"><span style="color: rgb(243, 233, 205)"> Finds the previous occurrence of a string ||   || <span style="color: rgb(9, 0, 255)"><span style="background-color: rgb(255, 255, 255)"><span style="color: rgb(0, 0, 0)"><span style="color: rgb(250, 249, 249); background-color: rgb(28, 29, 253)"><span style="color: rgb(243, 233, 205)"> Clears all break points ||   || <span style="color: rgb(9, 0, 255)"><span style="background-color: rgb(255, 255, 255)"><span style="color: rgb(0, 0, 0)"><span style="color: rgb(250, 249, 249); background-color: rgb(28, 29, 253)"><span style="color: rgb(243, 233, 205)"> Deletes to the end of the word ||   || <span style="color: rgb(9, 0, 255)"><span style="color: rgb(250, 249, 249); background-color: rgb(28, 29, 253)"><span style="color: rgb(243, 233, 205)"> <span style="background-color: rgb(255, 255, 255)"><span style="color: rgb(0, 0, 0); background-color: rgb(68, 59, 241)">Deletes the current line of code ||  || <span style="background-color: rgb(18, 0, 255)"><span style="color: rgb(9, 0, 255)"><span style="color: rgb(250, 249, 249); background-color: rgb(28, 29, 253)"><span style="color: rgb(243, 233, 205)"> Undoes the last change in the code window ||  || <span style="color: rgb(9, 0, 255)"><span style="color: rgb(250, 249, 249); background-color: rgb(28, 29, 253)"><span style="color: rgb(243, 233, 205)"> <span style="background-color: rgb(18, 0, 255)">Helps you move between procedures/functions in the code window     || 2) global vairables: making global variables makes coding alot easier and faster because you dont have to mention or dim the varible each time you start a new private sub, hence a down fall if you do make the global variable it can be altered by a user that comes by it, hence why we make it private.
 * <span style="color: rgb(9, 0, 255)"><span style="color: rgb(250, 249, 249); background-color: rgb(28, 29, 253)"><span style="color: rgb(243, 233, 205)"> **Shortcut Keys**
 * <span style="color: rgb(9, 0, 255)"><span style="color: rgb(250, 249, 249); background-color: rgb(28, 29, 253)"><span style="color: rgb(243, 233, 205)"> F2
 * <span style="color: rgb(9, 0, 255)"><span style="color: rgb(250, 249, 249); background-color: rgb(28, 29, 253)"><span style="color: rgb(243, 233, 205)"> F3/F4/F6/F11
 * <span style="color: rgb(9, 0, 255)"><span style="color: rgb(250, 249, 249); background-color: rgb(28, 29, 253)"><span style="color: rgb(243, 233, 205)"> F5
 * <span style="color: rgb(9, 0, 255)"><span style="color: rgb(250, 249, 249); background-color: rgb(28, 29, 253)"><span style="color: rgb(243, 233, 205)"> Ctrl + F5
 * <span style="color: rgb(9, 0, 255)"><span style="color: rgb(250, 249, 249); background-color: rgb(28, 29, 253)"><span style="color: rgb(243, 233, 205)"> F7
 * <span style="color: rgb(9, 0, 255)"><span style="color: rgb(250, 249, 249); background-color: rgb(28, 29, 253)"><span style="color: rgb(243, 233, 205)"> F8
 * <span style="color: rgb(9, 0, 255)"><span style="color: rgb(250, 249, 249); background-color: rgb(28, 29, 253)"><span style="color: rgb(243, 233, 205)"> F9
 * <span style="color: rgb(9, 0, 255)"><span style="color: rgb(250, 249, 249); background-color: rgb(28, 29, 253)"><span style="color: rgb(243, 233, 205)"> Ctrl + G
 * <span style="color: rgb(9, 0, 255)"><span style="color: rgb(250, 249, 249); background-color: rgb(28, 29, 253)"><span style="color: rgb(243, 233, 205)"> Ctrl + Spacebar
 * <span style="color: rgb(9, 0, 255)"><span style="color: rgb(250, 249, 249); background-color: rgb(28, 29, 253)"><span style="color: rgb(243, 233, 205)"> Ctrl + J
 * <span style="color: rgb(9, 0, 255)"><span style="color: rgb(250, 249, 249); background-color: rgb(28, 29, 253)"><span style="color: rgb(243, 233, 205)"> Shift + F2
 * <span style="color: rgb(9, 0, 255)"><span style="color: rgb(0, 0, 0)"><span style="color: rgb(250, 249, 249); background-color: rgb(28, 29, 253)"><span style="color: rgb(243, 233, 205)"> Ctrl + F
 * <span style="color: rgb(9, 0, 255)"><span style="color: rgb(0, 0, 0)"><span style="color: rgb(250, 249, 249); background-color: rgb(28, 29, 253)"><span style="color: rgb(243, 233, 205)"> Ctrl + H
 * <span style="color: rgb(9, 0, 255)"><span style="background-color: rgb(255, 255, 255)"><span style="color: rgb(0, 0, 0)"><span style="color: rgb(250, 249, 249); background-color: rgb(28, 29, 253)"><span style="color: rgb(243, 233, 205)"> Shift + F3
 * <span style="color: rgb(9, 0, 255)"><span style="background-color: rgb(255, 255, 255)"><span style="color: rgb(0, 0, 0)"><span style="color: rgb(250, 249, 249); background-color: rgb(28, 29, 253)"><span style="color: rgb(243, 233, 205)"> Ctrl + Shift + F9
 * <span style="color: rgb(9, 0, 255)"><span style="background-color: rgb(255, 255, 255)"><span style="color: rgb(0, 0, 0)"><span style="color: rgb(250, 249, 249); background-color: rgb(28, 29, 253)"><span style="color: rgb(243, 233, 205)"> Ctrl + Delete
 * <span style="color: rgb(9, 0, 255)"><span style="background-color: rgb(255, 255, 255)"><span style="color: rgb(0, 0, 0)"><span style="color: rgb(250, 249, 249); background-color: rgb(28, 29, 253)"><span style="color: rgb(243, 233, 205)"> Crtl + Y
 * <span style="color: rgb(243, 233, 205)"> <span style="color: rgb(9, 0, 255)"><span style="color: rgb(250, 249, 249); background-color: rgb(28, 29, 253)">Ctrl + Z   <span style="background-color: rgb(18, 0, 255)"><span style="color: rgb(9, 0, 255)"><span style="color: rgb(250, 249, 249); background-color: rgb(28, 29, 253)">
 * <span style="background-color: rgb(18, 0, 255)"><span style="color: rgb(9, 0, 255)"><span style="color: rgb(250, 249, 249); background-color: rgb(28, 29, 253)"><span style="color: rgb(243, 233, 205)"> Ctrl + Up/Down arrows

3) commenting your coding: comment your code as you write your code could be a useful as a revising/learning tool not only for yourself but others aswell. By commenting your code you will be able to see what youve done and what it does and you understand your code better. also looking back at it in time may help you understand what you were doing aswell.

4) naming your controls: naming your controls is essential leaving them as the default name is considered slack in the programmers eye. to name your controls properly helps you remember what each of those controls are for and what they do. it also shows the individuality between other coders work.

=McCool, Joshua= When searching for a string (like you have to in set 16) there are lots of different ways to do so but i found the easiest way to do so was to use one of the below: <span style="color: rgb(0, 0, 255)"> Dim search <span style="color: rgb(0, 0, 255)">As <span style="color: rgb(0, 0, 255)">String
 * 1.**FindString - use if you are using a textbox that searches for items that begin with the letters you type
 * example**

search = txtSearch.Text <span style="color: rgb(0, 0, 255)">If lstNames.FindString(search) < 0 <span style="color: rgb(0, 0, 255)">Then

MessageBox.Show(<span style="color: rgb(128, 0, 0)">"Doesn't Exist", <span style="color: rgb(128, 0, 0)">"Search Failed" ) <span style="color: rgb(0, 0, 255)">Else

lstNames.SelectedIndex = lstNames.FindString(search) <span style="color: rgb(0, 0, 255)">End <span style="color: rgb(0, 0, 255)">If

Dim search <span style="color: rgb(0, 0, 255)">As <span style="color: rgb(0, 0, 255)">String
 * 2.**FindStringExact - this one is self explanatory, it searches for the exact string
 * example** <span style="color: rgb(0, 0, 255)">

search = txtSearch.Text <span style="color: rgb(0, 0, 255)">If lstNames.FindStringExact(search) < 0 <span style="color: rgb(0, 0, 255)">Then

MessageBox.Show(<span style="color: rgb(128, 0, 0)">"Doesn't Exist", <span style="color: rgb(128, 0, 0)">"Search Failed" ) <span style="color: rgb(0, 0, 255)">Else

lstNames.SelectedIndex = lstNames.FindStringExact(search) <span style="color: rgb(0, 0, 255)">End <span style="color: rgb(0, 0, 255)">If

List/Combo boxes start their numbering at 0 whereas the Items.Count begins numbering at 1 and thus can generate an error in your code. To overcome this simply put -1 at the end of the items.count <span style="color: rgb(0, 0, 255)"> For i = 0 <span style="color: rgb(0, 0, 255)">To cbofruit.Items.Count - 1 temp &= cbofruit.Items(i) & vbNewLine <span style="color: rgb(0, 0, 255)">Next
 * 3.** When using the items.count method for a combobox or list box it is important that you keep the following in mind.
 * example**

=Morrow, Alex=

=Neighbour, Tony= To save a variable that can exist outside of a sub, set it before anything else and make it public. however, if you want to use it in a module as well as in form code without it changing, be sure to state it in the module rather then in the form code. If you are going to repeatidly use a bit of code, it may be handy to save it into a sub or function. then you can just call it later with the correct variables it needs (or none if thats the way it is made). Do not underestimate the importance of the count method. if you make an array, a list box or a combo box. etc you can count how many items are in each. this is handy when using for loops as you will not need to change the loop (or when more advanced, many loops and if's). it just makes the code more flexible so to speak. =Nolan, AJ=

When making grid like components in run-time use a 2 dimensional array and a embedded For loop. EG.

Dim example(2, 2) as PictureBox

For i as integer = 0 to 2 For j as integer = 0 to 2 example( i, j ) = new picturebox example( i, j ).location = new point( i * 64, j * 64)

Form1.control.add(example( i, j )) next next

If you are required to validate the contents of an control array (the contents of example in this case) and need to go a specific location that is not x, nor y but rather xy (that is the line is not verticle, or horizontal, but diagional) then use an embeded while loop.

Dim example as Picturebox 'gets location of sender Dim currentX as Integer = sender.left / 64 Dim currentY as Integer = sender.top / 64

'sets initial value of destination (where we want to go) Dim destinatonX as Integer = currentX Dim destinationY as integer = currentY

'if destination is greater than where we want to go (left top corner) then -1 from destination until we get there While destinationX > 0 destinationY > 0 destinationX - = 1 destinationY - = 1

=Salway, Alexander=

=__┼<span style="color: rgb(0, 0, 0)">Tidball, Jim ┼__=

Tip 1

While this may appear, to some of you, to be blatantly obvious, Google is your friend when dealing with problems with Visual Basic.Net. Visual Basic has existed, in varies forms, since 1991 therefore, there are many large and well established online locales where you can find information on absolutely everything you may need to know. Many people will probably have asked the same questions you have and the answers these individuals have recieved are freely available.

Also note that if your find a solution to your problem that is only available in visual basic 6 source code, all is not lost. Due to the significant changes Microsoft made for visual basic.net and the large user base visual basic 6 had, they had to be excruciatingly detailed in their explanations of changes between vb6 and vb.net. If you have visual basic 6 source code which could fix your problem, translating this code into visual basic.net source can take little more than a quick visit to the msdn website. _

Tip 2

Microsoft has left a number of legacy (Read: outdated) features in visual basic.net to ease migration of old visual basic 6 code to the .NET framework. It is important that you avoid getting into the habit of using these features as it is likely that in the future they will be removed completely.