Saturday, 4 January 2014

HOW TO: Programming: Episode 2: Basic Maths

If you've not checked out my introduction to programming go and look at it before you read this article here.

So you've come back for more I see? I'm glad that you want to continue your path in programming. As before we will be using Visual Basic .Net and IDEONE which we will be using again for out programming platform. 

This lesson we will be doing some simple mathematics, exploring the uses of operators and creating variable dimensions. Remember when you are entering code, make sure that you put capital letters exactly where I put them, or your results may vary!

1. Open IDEONE in a new window or tab on your browser and select Visual Basic .NET from the list of programming languages as we did in lesson 1. 



2. Clear all of the pre-made code in the window so we can input our own code. Clearing the code and re-writing it will help you to memorize the code for later use. So input the following into the code window:

Imports System
Public Class Test
Public Shared Sub Main()


3. At this stage we are now going to do something different from last time. We are going to write this into the code window:

Dim integer_1 as Integer = 5
Dim integer_2 as Integer = 10
Dim result_add as integer
Dim result_sub as integer
Dim result_mul as integer
Dim result_div as integer
Dim result_combi as integer

'Dim' stands for dimension, meaning you are setting the dimensions for the variable, and a variable is something which holds raw data. In this case our variable is 'integer_x'. You can set variables as something called an array which can hold multiple values by putting:

Dim integer_3(x) as Integer 1 Dimensional Array
Dim integer_4(x, x) as Integer 2 Dimensional Array

However we will be working with non array variables today. There are many different variable types within Visual Basic .NET including:
  • Integer - 4 bytes of data
  • Single - 4 bytes of data
  • Double - 8 bytes of data
  • Long - 8 bytes of data
  • String - A string of unicode text up to 2 billion characters 
  • Char - One unicode character 
  • Date - 8 bytes of data to hold a date
And of course a few more!

The part of the code we entered where we have placed '= x' is where we pre-define data for the variable, but we have not done that for the result as we want the code to generate data for the result automatically. You may have also noticed we have Dim'd a result variable for each operation and one for a combination of operations. 

There are several 'operators' in visual basic, but we will be focusing out attention on the four basic ones: Adding, Subtracting, Multiplying and Dividing; represented of course as '+,-,* and /'. 

Code time:

4. Now we can begin doing some maths, first we will add:

result_add = integer_1 + integer_2

'result_add' is at the start of the sum as we need to tell the computer that we want the value of 'result_add' to be equal to the sum of 'integer_1 + integer_2" as opposed to on a calculator where we would do 'integer_1 + integer_2 = result_add". 

Now we can finish off the other 3 operators using the same formula:

result_sub = integer_1 - integer_2
result_mul = integer_1 * integer_2
result_div = integer_1 / integer_2

Now to be really fancy we will combine some operators using brackets:

result_combi = (integer_1 + integer_2) * integer_2


Your code should now look like this:


5. Time to output your results, you may remember the 'console.writeline' statement from out last program, well we are going to use it again, this time a little more complexly):

Console.Writeline("Adding = {0}", result_add)
Console.Writeline("Subtracting = {0}", result_sub)
Console.Writeline("Multiplying = {0}", result_mul)
Console.Writeline("Dividing = {0}", result_div)
Console.Writeline("Adding then Multiplying = {0}", result_combi)

Lets dissect this part a bit:
'{0}', these curly brackets are holding the reference number to the argument outside of the speech marks. 0 is always the first number, no matter how many times you use this, always start with 0 and work up if there is more than one argument in your statement. 
', result_x', Here we place a comma marking the next argument, which is our variable.

This is the easiest way of having text and a variable appear in the same writeline statement. You could of course write multiple writeline statements, but this is untidy and will produce multiple lines when we really only need one.


6. Now we just need to round off our code with our closing statements:

End Sub
End Class

Now click run and see what it's like to be a true programming mathematician!


Your results should be:



Next time we will try our hand at inputting data!

Once again, thanks for reading.

Joseph Wright - SCOTECH













SHOWCASE: My office and personal space!

I like many people out there am a proper gadget man. My bedroom and office (it's one room...) is a place for me to work and relax, so I thought I'd give you a little tour of my room. Starting with the office space:


Directly to the left is my laptop table. On here is a HP Envy Touchsmart laptop with a Core i5 processor, NVidia GeForce GT740M and 8Gb of RAM. On top of that is my Beats By Dre Pro headphones, everybody slates Dre headphones as being overpriced and indeed they are... But I got these at a third of their price second hand so I'm not complaining. My speakers are a set of Logitech 5.1 Surround speakers, but I forget their model number, they are good though. Up on my desk the most prominent thing is my huge 32" TV which is being used as a computer screen at 1080p, giving me plenty of screen space. My keyboard is a 1990's Dell QuietKey and let it be told, I have not found a keyboard ever that has matched how nice it is to type on this keyboard. I have a Roccat Isku gaming keyboard which cost £70 and that doesn't even come close to the satisfaction of typing on this 99p keyboard from the second hand shop. 

Next to my 32" screen I have 2x 15 inch screens. These are auxiliary screens, one of which is connected to my main desktop as a secondary screen for web browsing while I program, it works very nicely. The screen next to that is simply for testing computers when they are up for bench testing and fixing. Next to the white monitor is my lovely little HTC Shift X9500 UMPC. It's a very under powered computer but is lovely for allowing me to test out mobile applications that I develop (I may do a very outdated review on this at some point).  At the very far right of my desk is a small Compaq Presario desktop computer which is used as a PXE server for testing computers and a mini web server for school projects and hosting files I may need in school (I access this through VNC on my main screen). 


Next is the leisure area of my room:

To the very far right is where the majority of my unused crap is, a didgeridoo, some Sanyo speakers and spare shelving (boring stuff..). To the distance is a Tannoy Mercury speaker, I have two of these and they sound IMPECCABLE.  Next are my two game stands, one is full of PS3 games (44 in total) and the one next to it is full of NES and Atari 2600 games, the NES is on top of the taller rack. My TV unit as on it (working from the right): XBOX 360, Nintendo Wii, Sony PS3, 50 Inch Samsung Plasma TV and a Dell Dimension 3100C (of which I did a strip down here: http://scotechnologyofficial.blogspot.co.uk/2014/01/dell-dimension-3100c-strip-down-and.html). 



Connected to the Dell is a 160Gb external hard drive for storing all my media. In the cabinet there is: A HP laptop from days gone by, Technics separates system and all of my XBOX 360 games. 

That's my home office. There are other little things like:
  • My office is networked wired not wireless, giving me a small layer of extra security. This is done with the use of a secondary sky hub and power-line adapter. I know this doesn't protect internet traffic, but at least it protects my internal traffic. 
  • My phone is a Samsung Galaxy Note 2, a fantastic bit of kit.
  • My iPad is hiding somewhere, I use this mostly for watching YouTube in bed and reading.
Thanks for reading,

Joseph Wright - SCOTech





FIX IT: Dell Dimension 3100C Strip Down and Generic Dell Trouble Shooting Guide!

Today I bought a new (old) computer from the pawn shop across the road for £10 as a little project to keep myself occupied, these computers are of course sold as spares or repairs. I love fixing up old computers, so I documented my project to share with you all! 

This will be a strip-down guide for the Dell Dimension 3100C and a generic trouble shooting guide for dell computers. 


The lovely Dell Dimension 3100C compact form factor computer that only cost £10. PAT Tested as well!







The computer still had its wrapping on in some places!









1. First thing you will need to do is gather the tools you need. There are only two important things, a Phillips-head screwdriver and an anti-static wristband or mat so you don't short out  the components. 



 Left: Anti-Static    wristband









Right: Phillips head screwdriver




2. Now we are going to open the computer up. On Dell computers this is done with the sliding latch on the top of the case, if your computer is not a dell then this can be done by generally removing the case screws on the back of the computer securing the side down. 


 Left: The catch should be easily found on the top of the computer.

Right: This latch is pulled outwards, releasing the side panel.

Bottom: The panel should now lift up.

3. Once the side panel has been fully removed, you can now see the insides of the computer. 


 Top Right: CD/DVD Combo drive. Top Left: Power Supply Unit (PSU)
 Middle Right: CPU Heat sink       Rest of computer: Motherboard

4. We are now going to remove the heat sink from the motherboard. This is done by removing 2 screws, one either side of the heat sink. Once the screws have been removed, the heat sink will then tilt upwards (pulling the end closest to the front of the case) and then will pull out once fully tilted. 


 The screws are recessed slightly into the heat sink allowing a screw driver to fit nicely. The screws cannot be completely removed so you can't lose them, but you will feel them slacken once fully undone.
 Left: The heat sink is removed by tilting the unit upwards away from the front of the case.

Right: Once the heat sink is fully tilted you can then pull the entire unit out.
Left: Place the heat sink with the part that was touching the CPU facing upwards, as it has paste on it!

Right: You can now see the processor in all of its glory, but don't touch it. LOOK AT THAT DUST!


5. The next step is to remove the RAM modules from the motherboard. This is done by pushing on two clips, one either side, of each ram module, this automatically pulls out the RAM chips. Set them aside on an anti-static bag if you have one, or a clean non-static surface. You can see in the picture bottom right (above) the 2 RAM chips near the blue cable, the little white notches are to be pushed down thus ejecting the RAM modules. 


Two RAM chips removed and ready to be replaced!


6. The next job is to remove the DVD/CD combo drive. This puzzled me for a little while as I started pulling the case apart, but Dell actually makes it easier than you realize to remove parts. There is a small lever next to the optical drive which once pulled up allows you to slide the drive back and pull it out. 

The red circle showing the location of the latch that you simply pull upwards, hold it and slide the drive backwards, then the drive can be easily removed. 

7. Once the optical drive has been removed you can then see the blue hard drive holder, there are two small latches on this plastic holder that you will need to pop out of place so you can slide the plastic holder back then pull up and out. 

The blue hard drive cradle is now exposed. The two terribly drawn yellow circles indicate where the latches are that you need to pop out of place, using a screw driver or your fingers...
8. Now that the computer is pretty much stripped, this moment in time is probably best to get rid of all that dust! Get the hoover and possibly a can of compressed air and spend a good 15 minutes hoovering up all the dust from the case. 

 Left: I love me a good hoover!





Right: The case is now all clean and shiny!
9. We can now start to re-assemble the computer. Place the hard drive into the cradle, making sure that the little notches are lined up with the screw holes on the HDD and the hard drive is of course in the cradle the correct way around. We can now plug the SATA connector and power connector into the hard drive. These two connectors can only go in one way around so it is pretty fool proof! Slide the hard drive back into its bay and re-seat the optical drive.

Left: Plugging the cables into the hard drive is a 'fool proof' thing to do!

Right: Placing the hard drive back into its pit!

Bottom: Slotting the optical drive back into its position above the                                                               HDD.


10. Replace the RAM modules. They can only go in one way around, but it's easy to mess this part up. If you try to force the RAM in the wrong way around you will destroy it. Make sure the line the notches up on the RAM and on the motherboard to make sure it fits properly!


Notice the notch on the bottom of this Stick of RAM. There is a matching notch on the motherboard. Be aware that the notch is not directly in the middle of the stick, as to make sure that it will only go into the motherboard one way. Press down hard on the RAM module!

11. The final stage of the reassembly is apply some new paste onto the CPU, if you don't have more paste then just leave it with the past that is already on there, but ideally applying more is favorable! Once you've done this, re-attach the heat-sink and reconnect any cables to the motherboard that you removed during the dis-assembly process. 



 Above: Good quality thermal past is applied directly to the CPU, a nice large dollop of it!

Left: Re-attach any cables you disconnected. SATA/PATA and ATX cables!

Right: Re-attach the heat sink by placing the notches into the holders, tilting it back into place and tightening the screws.

You have successfully stripped down and tidied up your Dell Dimension 3100C computer. If any faults occur on start-up however check this guide:


Power Button Light Codes:

Off: Power is off, light is not illuminated.
Blinking Amber: Initial state of light at power up. This light indicates that the system has power but is not yet fully turned on. If the hard drive light is not illuminated at this point it could indicate a faulty power supply. If the hard drive light is illuminated at this point then it could mean that the on-board power regulator is faulty. 
Solid Amber: Second state of the light at power up. This indicated that the power supply is good and is probably some other error. Check the diagnostic lights.
Blinking Green: System is in a low power state, this could mean that the computer is in standby. If your computer is booting from cold, check the diagnostic lights. 
Solid Green: This indicated that the computer is in a functioning state, check the POST screen for errors. 

Beep Codes: (most cannot be rectified at home)

1-1-2: Microprocessor register failure
1-1-3: NVRAM read/write failure
1-1-4: ROM BIOS checksum failure
1-2-1: Programmable interval timer failure
1-2-2: DMA initialization failure
1-2-3: DMA page register read/write failure
1-3: Video memory test failure (try re-seating GPU if you have one)
1-3-1 through 2-4-4: Memory not being registered (try re-seating RAM)
3-1-1: Slave DMA register failure
3-1-2: Master DMA register failure
3-1-3: Master interrupt mask register failure
3-1-4: Slave interrupt mask resister failure 
3-2-2: Interrupt vector loading failure
3-2-4: Keyboard controller test failure
3-3-4: Video memory test failure (try re-seating GPU if you have one)
3-4-1: Screen initialization failure
3-4-2: Screen retrace failure
3-4-3: Search for video ROM failure
4-2-1: No timer tick
4-2-2: Shutdown failure
4-2-3: Gate A20 failure
4-2-4: Unexpected interrupt in protected mode
4-3-1: Memory failure above address 0FFFFh
4-3-3: Timer-chip counter 2 failure
4-3-4: Time-of-day clock stopper (replace BIOS battery)
4-4-1: Serial or parallel port test failure (remove any serial or parallel devices)
4-4-2: Failure to decompress code to shadowed memory
4-4-3: Math-co processor test failure
4-4-4: Cache test failure. 

Diagnostic Light Codes:


1 2 3 4: The computer is either off, a pre-BIOS error has occurred or the computer has fully booted into the OS. 
1 2 3 4: A possible processor failure has occurred (Re-seat the processor).
1 2 3 4: Memory modules are detected but have failed to register (Re-seat the memory modules. If this doesn't solve the problem, remove all modules and test them one at a time in DIMM slot 1). 
1 2 3 4: A possible graphics card failure has occurred (Re-seat any graphics cards, or replace it if it's faulty).
1 2 3 4: A possible floppy drive error has occurred (Re-seat the cables).
1 2 3 4: A possible USB error has occurred. (remove all USB cables and try again).
1 2 3 4: No memory modules detected (Re-seat all memory modules, test each module in DIMM slot 1 to determine if any modules are faulty).
1 2 3 4: Memory modules detected but there is a problem with compatibility or configuration (check that there is no special requirements for memory with your computer and that the memory you are using is supported, EG. Using ECC memory in a NON-ECC motherboard). 
1 2 3 4:  A possible expansion card failure has occurred (Re-seat PCI cards, if problem persists, try removing them).
1 2 3 4: Another failure has occurred (Ensure that all cables are properly inserted into the correct components inside of the computer and that there are no new devices connected to the computer that might cause failure).

Thank you for reading my article and that I was of some use to you!

Joseph Wright - SCOTech