11 June 2012

Post-install procedure in Lazarus


This is post-install procedure for fresh lazarus build :

1. Install Fortes report package
    from http://fortes4lazarus.svn.sourceforge.net/viewvc/fortes4lazarus/?view=tar
    and copy file rlreportshared.dll to c:\lazarus folder
2. Install ZeosDBO database package
    from http://sourceforge.net/projects/zeoslib/files/Zeos%20Database%20Objects/
3. Install ZVDateTimeControls package
    from http://sourceforge.net/projects/lazarus-ccr/files/Time%20and%20Date/ZVDateTimeControls%20Pack/
4. Install zeddbtreeview package
    from http://code.google.com/p/zeddbtreeview/
5. Install uniqueinstance package
    from http://code.google.com/p/luipack/downloads/detail?name=uniqueinstance-1.0.zip
6. Install Lazarus Data Dictionary package
    from c:\lazarus\components\datadict\lazdatadict.lpk
7. Install PowerPDF package
    from http://sourceforge.net/projects/lazarus-ccr/files/PowerPDF
8. Install UNIDAC packages, in this order:
    C:\lazarus\components\UniDAC\Source\Lazarus1\dclunidac10.lpk
    C:\lazarus\components\UniDAC\Source\Lazarus1\accessprovider10.lpk
    C:\lazarus\components\UniDAC\Source\Lazarus1\msprovider10.lpk
    C:\lazarus\components\UniDAC\Source\Lazarus1\myprovider10.lpk
    C:\lazarus\components\UniDAC\Source\Lazarus1\pgprovider10.lpk

 

9. Build the project Lazarus Data Desktop
    from c:\lazarus\tools\lazdatadesktop\lazdatadesktop.lpr

10. Activate sqlite3laz package throw menu Package option Install/Uninstall
    (if you are in Linux, add packages : sqlite3, sqlite3devel, before,
     or on Windows download dll from https://sqlite.org/download.html and
     put in lazarus folder)
11. Activate lazreport package throw menu Package option Install/Uninstall
12. Activate lazreportpdfexport package throw menu Package option Install/Uninstall

13. Copy sqliteadmin folder to c:\lazarus\tools\
      from http://sqliteadmin.orbmu2k.de/
      and register it in Tools/Configure External Tools menu item

14. Install Help in Lazarus IDE :
    * Install CHM Help package
       from c:\lazarus\components\chmhelp\packages\idehelp\chmhelppkg.lpk
    * Build the project lazarus/components/chmhelp/lhelp/lhelp.lpi
    * Download the latest stable Lazarus CHM help files
       from http://sourceforge.net/projects/lazarus/files/Lazarus%20Documentation/
       and copy all CHM files to c:\lazarus\docs\chm
    * Go to the Environment Options, tab "Help Options' and select the "CHM Help Viewer".
       "HelpExe" should be the lhelp you just built - lhelp.exe.
       "HelpFilesPath" should be, where you put the CHM files - c:\lazarus\docs\chm
     Now context sensitive help using F1 should work.

24 May 2012

Delphi XE2 : Compile error : Invalid PLATFORM variable "HPD"

Problem :

I just install a new Delphi XE2.
I create a new classical VCL project and I try to compile it.
I obtain this message :

'[Error Erreur] Invalid PLATFORM variable "HPD". PLATFORM must be one of the following: "Win32", "Win64", or "OSX32". If PLATFORM is defined by your system's environment, it must be overridden in the RAD Studio IDE or passed explicitly on the command line to MSBuild; e.g., /p:Platform=Win32.'

Reason :

It's a battle between Microsoft and Hewlett Packard over
the use of the PLATFORM environment variable.

"HP Easy Setup" uses it for it's own purposes.
MSBUILD uses it for another purpose.

Solution :

Right click on "My Computer" and select Properties. In the Advanced tab,
you will find a button for "Environment Variables". Click on it, and in
the list that follows, delete the PLATFORM variable from the list of
System variables.
Close the dialog, restart XE2, you should now be able to recompile
without further problems

Source :

https://forums.embarcadero.com/thread.jspa?threadID=59930

16 April 2012

Installing ClockworkMod Recovery


This is the same ClockworkMod Recovery 4.0.1.5 as in this post, just with the kernel patched to run on phones upgraded to Android 2.3.4.

    Windows users should download and install One Touch Upgrade Q (it includes the needed Windows drivers). Linux and Mac OS X users should download and install the Android SDK starter package, then use the Android SDK and AVD Manager to install at least the Android SDK Platform-tools component. Linux users should also configure the system as described in the Google Android development documentation.
    Download the attached file: recovery-clockwork-4.0.1.5-ot990-kernel-v53B-0-anyboot.zip, unpack it.
    Switch the phone into fastboot mode:
        disconnect the USB cable, turn off the phone;
        press and hold the Volume Down button;
        while holding the Volume Down button, press the Power button;
        when the phone vibrates, release the Power button, but keep holding the Volume Down button;
        keeping the Volume Down button pressed, connect the phone to your computer with the USB cable;
        wait 3 seconds after connecting the USB cable, then release the Volume Down button.
    If using Windows, just run the install.bat file included in the archive. For other systems you need to run the commands manually:
    Code:

    fastboot erase recovery
    fastboot flash recovery recovery.img
    fastboot reboot

Entering ClockworkMod Recovery

    Disconnect the USB cable, turn off the phone.
    Press and hold the Volume Up button.
    While holding the Volume Up button, press the Power button.
    When the phone vibrates, keep holding the Volume Up button, release the Power button, and immediately press and hold the Home button.
    Continue holding both the Volume Up and the Home buttons until the Android logo disappears, and you see a black screen with the keypad light turned on, then release both buttons.
    Wait while CWM recovery boot completes; you should see the menu as shown here.

WARNING: If you forget to press the Home button, or release it too early, a hardreset will be performed instead of entering the recovery — it will wipe all user data from the phone memory (but files on the microSD card will not be affected).

When working with the CWM recovery, use the Volume Up and Volume Down buttons to move between menu items, and the Home button to activate the selected item. Use the "reboot system now" item to exit the recovery.

Rooting the phone with ClockworkMod Recovery

    Download Superuser-3.0.7-efghi-signed.zip (or maybe a newer version from the Superuser home page).
    Place the downloaded file on the microSD card.
    Enter CWM recovery on the phone as described above.
    Select "install zip from sdcard" in the menu, then select the Superuser-3.0.7-efghi-signed.zip file.
    Select "reboot system now" to exit from recovery.

(from forum.xda-developers.com)

15 April 2012

Alcatel OT-990 (Telenor OneTouch) on Gingerbread 2.3 from XDA


BOOTLOADER SUCCESSFULLY UPGRADED WITHOUT OTU!!!!!!!!! GINGERBREAD 2.3 BOOTED ON TELENOR ONE TOUCH SERBIA

WE HAVE A WORKING GINGERBREAD ON A TELENOR ONE TOUCH SERBIA!!! THANK YOU EVERYONE FOR YOUR HELP, ESPECIALLY qltsar, sigprof, gulyuk.s !!!!
***-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------***

This is how I did it, step by step. I CHECKED THESE STEPS SEVERAL TIMES BUT THERE IS A POSSIBILITY THAT I FORGOT SOMETHING!!!!!!!!!

IF YOU DONT KNOW WHAT ARE YOU DOING PLEASE DONT FOLLOW THIS MANUAL. I'M NOT RESPONSIBLE FOR BRICKED PHONES OR ANY DAMAGE CAUSED BY YOUR OWN ACTIONS. IT WORKED FOR ME AND IT'S DONE ONLY ON TELENOR ONE TOUCH SERBIA. ITS FUNCTIONALITY IS NOT FULLY TESTED YET, THERE COULD BE BUGS*!! YOU ARE DOING IT AT YOUR OWN RISK!!!
* currently known bugs: cant update google apps, gmail,search,youtube..
THESE STEPS WERE TESTED ON TELENOR BRANDED OT-990 WITH v53R-0 BUILD NUMBER. THE PHONE WAS PREVIOUSLY UPDATED FROM v53H-0 to v53R-0 WITH OTU(ONE TOUCH UPGRADE) APPLICATION

BACKUP EVERYTHING BEFORE YOU PROCEED!!

DO NOT PROCEED WITH STEPS IF ANYTHING DIFFERS FROM THIS MANUAL!!

THESE ARE INSTRUCTIONS FOR WINDOWS 7, i did it on Win7 64bit

1. You need to install Alcatel Android Manager and One Touch Upgrade from THIS LINK.Find it in Download tab. All the drivers are here.
Also download and install Android SDK Tools. I have installed all this things so maybe you should too.
2. Download CWM recovery image, Recovery Manager apk, FOTA update.zip. Unpack the RecoveryManager_v0.34b.zip. Put those recovery-clockwork-4.0.1.5-ot990.img, RecoveryManager_v0.34b.apk and update.zip (dont unpack this archive) files in the root of SD card.
3. Download the Hungarian rom dump 2.2.2. Unpack the archive, you'll see two folders - dump and firmware. Copy boot.img, custpack.img, recovery.img, system.img files from 'firmware' folder and FOTA.img, FOTAFLAG.img files from 'dump' folder to a new folder with name 'gingerbread' (for example).
4. Download fotaflag_modem_upgrade.zip and unpack the fotaflag_modem_upgrade.mbn file to a 'gingerbread' folder.
5. Download the Telenor Gingerbread rom dump Unpack it, and copy(dont move, just copy) adb.exe, AdbWinApi.dll, AdbWinUsbApi.dll, fastboot.exe,install.bat files to the 'gingerbread' folder. (REMEMBER WHERE YOU EXTRACTED THIS ARCHIVE, WE WILL NEED THIS FOLDER IN STEP 17!!!)
6. Right click on install.bat in 'gingerbread' folder and choose Edit. Replace the whole content of file with following commands:


adb.exe reboot-bootloader
ping 1.1.1.1 -n 1 -w 10000
fastboot.exe -w
fastboot.exe erase boot
fastboot.exe erase recovery
fastboot.exe erase system
fastboot.exe erase custpack
fastboot.exe flash boot boot.img
fastboot.exe flash recovery recovery.img
fastboot.exe flash system system.img
fastboot.exe flash custpack custpack.img
fastboot.exe flash FOTA FOTA.img
fastboot.exe flash FOTAFLAG FOTAFLAG.img
fastboot.exe flash FOTAFLAG fotaflag_modem_upgrade.mbn
fastboot.exe reboot

Save it and exit.

7. Shutdown the phone and then when its off enter the fastboot mode by holding the Volume Down and Power button. When you feel the vibration, release the Power button but hold the Volume Down a few seconds longer, dont let the android logo appear. Release the Volume Down button. The screen will be black, and you'll see the light from Options, Search, Back buttons of the phone.
8. Connect your phone with usb cable.
9. Double click on the install.bat in a 'gingerbread' folder and wait for process to finish. If everything is ok, the DOS prompt window will close and phone will reboot. He'll still be off, showing Battery charging.
10. Disconnect the usb cable and power on the phone. When you walk through the Setup process of the phone (Language, Google account etc.) you'll have a rooted 2.2 ROM on your phone.
11. Allow non-market applications to be installed by checking 'Unknown sources' in Setting/Applications, then go to File Manager and click on RecoveryManager_v0.34b.apk to install it.
12. When Recovery Manager is installed open it and go to Recovery tab, choose install recovery and when he shows you a recovery-clockwork-4.0.1.5-ot990.img select it. After he is done select the Reboot into Recovery option. Phone will reboot.
13. When phone enters a Recovery mode you will see something like this. (You are moving through the menu with Volume Up and Volume Down buttons and select with Home button.) Choose a second option apply sdcard:update.zip. Confirm this decision when he ask you are you sure. Wait him to finish. When he is done choose reboot, i think its a first option.
14. Have patience, booting will be slow. At this point Gingerbread should be installed and offer you to choose a language. But after that when you try to select a keyboard he will probably give an error, something like 'android.process... blah blah..' and give you a force quit option. SHUT DOWN THE PHONE!
15. When the phone is off we are doing the step 7 again. Enter the fastboot mode!
16. Connect the usb cable!
17. Find the folder from step 5 where we extracted the Telenor Gingerbread romdump archive (folder name will be 'original_telenor_GB_v5GY-0' - DONT USE THE 'gingerbread' folder we previously used) and execute install.bat. Wait him to finish, when its done phone will reboot and start charging battery.
18. Disconnect the usb cable.
19. Power on the phone and go through the setup.

YOU ARE DONE!


Telenor Hungary 2.2 and 2.3 ROMS, FOTA Update.zip are provided by qltsar,
FOTAFLAG modem upgrade is provided by sigprof.

ONE MORE TIME, IF YOU DONT KNOW WHAT THESE THINGS ARE THEN YOU SHOULD PROBABLY NOT DOING THIS!!

(from forum.xda-developers.com)

13 February 2012

Ubutnu 11.10 install additional things

Type in terminal window :

sudo apt-get install ubuntu-restricted-extras

sudo apt-get install vlc

sudo apt-get install gimp

sudo apt-get install gnome-panel
sudo apt-get install gnome-shell
sudo apt-get install kde-standard


sudo add-apt-repository ppa:danielrichter2007/grub-customizer
sudo apt-get update
sudo apt-get install grub-customizer



Install PostgreSQL on Ubuntu 11.10

Just type in terminal window :

sudo apt-get install postgresql
sudo apt-get install postgresql-contrib
sudo apt-get install pgadmin3

24 December 2011

C# Lesson 24 : Understanding Event-Driven Programming

Learn how events are utilized in the .NET Framework Class Library specific to WPF and ASP.NET Web Forms applications. In these examples, we see how C# is generated by the IDE to "wire up" a user action or application event to the code that handles that event.

WPF

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WPFEvents
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();

            MyButton.Click += MyButton_Click;
            MyButton.Click += MyButton_IClickedThis;
        }

        void MyButton_Click(object sender, RoutedEventArgs e)
        {
            //throw new NotImplementedException();
            MyLabel.Content = "Hello World!";
        }

        void MyButton_IClickedThis(object sender, RoutedEventArgs e)
        {
            //throw new NotImplementedException();
            MyLabel.Content = "Hello World again!";
        }

    }
}


ASP.NET

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ASPNETEvents
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            MyButton.Click += MyButton_Click;
        }

        void MyButton_Click(object sender, EventArgs e)
        {
            //throw new NotImplementedException();
            MyLabel.Text = "Hello world!";
        }

 
    }
}

Source : MS Virtual Academy

23 December 2011

C# Lesson 23 : Filtering and Managing Data Collections Using LINQ

In this lesson, we discuss how Structured Query Language provides a means of working with sets of data. Similarly, the LINQ syntax provides a simple way of working with groups of data in generic collections. We demonstrate projecting data onto existing types and new anonymous types.

Before

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace UnderstandingLINQ
{
    class Program
    {
        static void Main(string[] args)
        {
            List<Car> myCars = new List<Car>() {
                new Car() { Make = "BMW", Model= "550i", Color=CarColor.Blue, StickerPrice=55000, Year=2009},
                new Car() { Make="Toyota", Model="4Runner", Color=CarColor.White, StickerPrice=35000, Year=2010},
                new Car() { Make="BMW", Model = "745li", Color=CarColor.Black, StickerPrice=75000, Year=2008},
                new Car() {Make="Ford", Model="Escape", Color=CarColor.White, StickerPrice=25000, Year=2008},
                new Car() {Make="BMW", Model="55i", Color=CarColor.Black, StickerPrice=57000, Year=2010}
            };

            foreach (var car in myCars)
                Console.WriteLine("{0} - {1} - {2}", car.Make, car.Model, car.Year);

            Console.ReadLine();
        }
    }

    class Car
    {
        public string Make { get; set; }
        public string Model { get; set; }
        public int Year { get; set; }
        public double StickerPrice { get; set; }
        public CarColor Color { get; set; }
    }

    enum CarColor
    {
        White,
        Black,
        Red,
        Blue,
        Yellow
    }

}


After

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace UnderstandingLINQ
{
    class Program
    {
        static void Main(string[] args)
        {
            List<Car> myCars = new List<Car>() {
                new Car() { Make = "BMW", Model= "550i", Color=CarColor.Blue, StickerPrice=55000, Year=2009},
                new Car() { Make="Toyota", Model="4Runner", Color=CarColor.White, StickerPrice=35000, Year=2010},
                new Car() { Make="BMW", Model = "745li", Color=CarColor.Black, StickerPrice=75000, Year=2008},
                new Car() {Make="Ford", Model="Escape", Color=CarColor.White, StickerPrice=25000, Year=2008},
                new Car() {Make="BMW", Model="55i", Color=CarColor.Black, StickerPrice=57000, Year=2010}
            };

            /*
            var bmws = from car in myCars
                       where car.Make == "BMW"
                       && car.Year == 2010
                       select new { car.Make, car.Model, car.Year };
            */

            /*
            var orderedCars = from car in myCars
                              orderby car.Year descending
                              select car;
            */

            //var _bmws = myCars.Where(p => p.Year == 2010).Where(p => p.Make == "BMW");

            //var _orderedCars = myCars.OrderByDescending(p => p.Year);

            var sum = myCars.Sum(p => p.StickerPrice);

            /*
            foreach (var car in _orderedCars)
                Console.WriteLine("{0} - {1} - {2}", car.Make, car.Model, car.Year);
            */

            Console.WriteLine(sum);
            Console.ReadLine();
        }
    }

    class Car
    {
        public string Make { get; set; }
        public string Model { get; set; }
        public int Year { get; set; }
        public double StickerPrice { get; set; }
        public CarColor Color { get; set; }
    }

    enum CarColor
    {
        White,
        Black,
        Red,
        Blue,
        Yellow
    }

}
Source : MS Virtual Academy

22 December 2011

C# Lesson 22 : Working with Collections

Collections are a more powerful form of arrays. In this lesson, we demonstrate an "old style" collection (pointing out its limitations), along with several of the newer, strongly typed generic collections (List<T> and Dictionary<T1, T2>) utilizing the generics syntax.

Before

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WorkingWithCollections
{
    class Program
    {
        static void Main(string[] args)
        {
            Car car1 = new Car();
            car1.Make = "Oldsmobile";
            car1.Model = "Cutlas Supreme";

            Car car2 = new Car();
            car2.Make = "Geo";
            car2.Model = "Prism";

            Book b1 = new Book();
            b1.Author = "Robert Tabor";
            b1.Author = "Microsoft .NET XML Web Services";
            b1.ISBN = "0-000-00000-0";


            Console.ReadLine();
        }
    }

    class Car
    {
        public string Make { get; set; }
        public string Model { get; set; }
    }

    class Book
    {
        public string Title { get; set; }
        public string Author { get; set; }
        public string ISBN { get; set; }
    }

}


After

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WorkingWithCollections
{
    class Program
    {
        static void Main(string[] args)
        {
            /*
            Car car1 = new Car();
            car1.Make = "Oldsmobile";
            car1.Model = "Cutlas Supreme";

            Car car2 = new Car();
            car2.Make = "Geo";
            car2.Model = "Prism";

            Book b1 = new Book();
            b1.Author = "Robert Tabor";
            b1.Author = "Microsoft .NET XML Web Services";
            b1.ISBN = "0-000-00000-0";
             */

            // ArrayLists are dynamically sized, and support other
            // cool features like sorting, removing items, etc.
            /*
            System.Collections.ArrayList myArrayList = new System.Collections.ArrayList();
            myArrayList.Add(car1);
            myArrayList.Add(car2);
            myArrayList.Add(b1);
            myArrayList.Remove(b1);

            foreach (object o in myArrayList)
            {
                Console.WriteLine(((Car)o).Make);
            }
            */

            // Dictionaries allow you to save a key along with
            // the value, and also support cool features.
            // There are different dictionaries to choose from ...
            /*
            System.Collections.Specialized.ListDictionary myDictionary
                = new System.Collections.Specialized.ListDictionary();

            myDictionary.Add(car1.Make, car1);
            myDictionary.Add(car2.Make, car2);
            myDictionary.Add(b1.Author, b1);


            // Easy access to an element using its key
            Console.WriteLine(((Car)myDictionary["Geo"]).Model);

            // But since its not strongly typed, we can easily break it
            // by adding a different type to the dictionary ...
            // Obviously, I'm trying to retrieve a book here, and then get its ... model?
            Console.WriteLine(((Car)myDictionary["Robert Tabor"]).Model);
            */

            /*
            List<Car> myList = new List<Car>();

            myList.Add(car1);
            myList.Add(car2);
            //myList.Add(b1);

            foreach (Car car in myList)
            {
                // No casting!
                Console.WriteLine(car.Model);
            }
            */

            /*
            Dictionary<string, Car> myDictionary = new Dictionary<string, Car>();
            myDictionary.Add(car1.Make, car1);
            myDictionary.Add(car2.Make, car2);

            Console.WriteLine(myDictionary["Geo"].Model);
            */

            //string[] names = { "Bob", "Steve", "Brian", "Chuck" };


            Car car1 = new Car() { Make = "Oldsmobile", Model = "Cutlas Supreme" };
            Car car2 = new Car() { Make = "Geo", Model = "Prism" };
            Car car3 = new Car() { Make = "Nissan", Model = "Altima" };

            List<Car> myList = new List<Car>() {
                new Car { Make = "Oldsmobile", Model = "Cutlas Supreme"},
                new Car { Make = "Geo", Model="Prism"},
                new Car { Make = "Nissan", Model = "Altima"}
            };



            Console.ReadLine();
        }
    }

    class Car
    {
        public string Make { get; set; }
        public string Model { get; set; }
    }

    class Book
    {
        public string Title { get; set; }
        public string Author { get; set; }
        public string ISBN { get; set; }
    }

}
Source : MS Virtual Academy

21 December 2011

C# Lesson 21 : Gracefully Handling Exceptions

Exceptions occur when an application experiences some unexpected problem at run time. This lesson discusses how to use the try catch finally block to anticipate potential problems and to attempt to shield the end user from those problems as much as possible. We also explore best practices when checking for exceptions.

Before

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ReadTextFileWhile
{
    class Program
    {
        static void Main(string[] args)
        {
            StreamReader myReader = new StreamReader("Values.txt");
            string line = "";

            while (line != null)
            {
                line = myReader.ReadLine();
                if (line != null)
                    Console.WriteLine(line);
            }

            myReader.Close();
            Console.ReadLine();

        }
    }
}


After

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ReadTextFileWhile
{
    class Program
    {
        static void Main(string[] args)
        {

            try
            {

                StreamReader myReader = new StreamReader("Values.txt");
                string line = "";

                while (line != null)
                {
                    line = myReader.ReadLine();
                    if (line != null)
                        Console.WriteLine(line);
                }

                myReader.Close();

            }
            catch (DirectoryNotFoundException e)
            {
                Console.WriteLine("Couldn't fine the file.  Are you sure the DIRECTORY exists?");
            }
            catch (FileNotFoundException e)
            {
                Console.WriteLine("Couldn't find the file.  Are you sure you're looking for the correct file?");
            }
            catch (Exception e)
            {
                Console.WriteLine("Something didn't quite work correctly: {0}", e.Message);
            }
            finally
            {
                // Perform any cleanup to roll back the data or close connections
                // to files, database, network, etc.
            }

            Console.ReadLine();

        }
    }
}

Source : MS Virtual Academy

20 December 2011

C# Lesson 20 : Enumerations and the switch Decision Statement

Here, we demonstrate the use of Enumerations because, in the .NET Framework Class Library, properties can often be set only to a predetermined subset of possible values. To illustrate this point, we create our own custom enumeration and then utilize it in a simple application that demonstrates a third Decision statement, the switch.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace UsingSwitch
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Type in a super hero's name to see his nickname:");
            string userValue = Console.ReadLine();

            switch(userValue.ToUpper())
            {
                case "BATMAN":
                    Console.WriteLine("Caped Crusader");
                    break;
                case "SUPERMAN":
                    Console.WriteLine("Man of Steel");
                    break;
                case "GREENLANTERN":
                    Console.WriteLine("Emerald Knight");
                    break;
                default:
                    Console.WriteLine("Does not compute");
                    break;
            }


            Console.ReadLine();

        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace UnderstandingEnumerations
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.ForegroundColor = ConsoleColor.DarkRed;
            //Console.WriteLine("Hello world!");

            Console.WriteLine("Type in a superhero's name to see his nickname: ");
            string userValue = Console.ReadLine();

            SuperHero myValue;

            if (Enum.TryParse<SuperHero>(userValue, true, out myValue))
            {
                switch (myValue)
                {
                    case SuperHero.Batman:
                        Console.WriteLine("Caped crusader");
                        break;
                    case SuperHero.Superman:
                        Console.WriteLine("Man of Steel");
                        break;
                    case SuperHero.GreenLantern:
                        Console.WriteLine("Emerald Knight");
                        break;
                    default:
                        break;
                }
            }
            else
            {
                Console.WriteLine("Does not compute");
            }

            Console.ReadLine();
        }
    }

    enum SuperHero
    {
        Batman,
        Superman,
        GreenLantern
    }

}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ComplexIfStatement
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Pick a number between 1 and 100:");
            string userValue = Console.ReadLine();

            int compareValue = int.Parse(userValue);

            if ((compareValue < 1) || (compareValue > 100))
                Console.WriteLine("The number you chose was out of bounds.");
            else if ((compareValue == 42) || (compareValue > 90))
                Console.WriteLine("You found one of the special numbers!");
            else
                Console.WriteLine("You didn't find one of the special numbers");

            Console.ReadLine();

        }
    }
}

19 December 2011

C# Lesson 19 : Understanding Scope and Utilizing Accessibility Modifiers

Explore the scope of variables within code blocks and how accessibility modifiers, such as Public, Private, and Protected, are used by the .NET Framework Class Library to expose or hide implementation of their given services to consumers of that given class. This is sometimes referred to as "encapsulation."

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace UnderstandingScope
{
    class Program
    {
       // private static string k = "";

        static void Main(string[] args)
        {
            /*
            string j = "";

            for (int i = 0; i < 10; i++)
            {
                j = i.ToString();
                k = i.ToString();
                Console.WriteLine(i);

                if (i == 9)
                {
                    string l = i.ToString();
                }
                //Console.WriteLine("l: " + l);
            }
            //Console.WriteLine(i);

            Console.WriteLine("Outsite of the for: " + j);
            //Console.WriteLine("k: " + k);
            helperMethod();
             */


            Car car = new Car();

            car.DoSomething();


            Console.ReadLine();
        }

        /*
        static void helperMethod()
        {
            Console.WriteLine("k from the helperMethod: " + k);
        }
         */

    }

    class Car
    {
        public void DoSomething()
        {
            Console.WriteLine(helperMethod());
        }

        private string helperMethod()
        {
            return "Hello world!";
        }

    }

}
Source : MS Virtual Academy

18 December 2011

C# Lesson 18 : Understanding Namespaces and Adding References to Assemblies

In this lesson, we explain how Namespaces allow us to disambiguate classes that may share the same name. And we explain how the .NET Framework Class Library is so large that including all its classes in every application you write is a waste of system resources. Certain project templates include references to the typical assemblies required by a given type of application, and we demonstrate this by referencing a custom assembly of Bob's own design.

using System;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tabor;

namespace NamespacesAndReferencingAssemblies
{
    class Program
    {
        static void Main(string[] args)
        {
            //System.IO.StreamReader myStreamReader = new System.IO.StreamReader();

            //StreamReader myStreamReader = new StreamReader();


            Bob bob = new Bob();

            string html = bob.Lookup("http://www.learnvisualstudio.net");

            Console.WriteLine(html);
            Console.ReadLine();


        }
    }
}
Source : MS Virtual Academy

17 December 2011

C# Lesson 17 : Working with Classes and Inheritances in the .NET Framework Class Library

This lesson continues to teach concepts about classes (specifically, in this case, inheritance) by showing you how to utilize inheritance in your own custom classes. Learn about overriding virtual functionality, abstract base classes, and sealed classes. 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace UnderstandingInheritance
{
    class Program
    {
        static void Main(string[] args)
        {
            Car myCar = new Car();
            myCar.Make = "BMW";
            myCar.Model = "745li";
            myCar.Color = "Black";
            myCar.Year = 2005;
            //myCar.TowingCapacity = 1200;

            printVehicleDetails(myCar);


            Truck myTruck = new Truck();

            myTruck.Make = "Ford";
            myTruck.Model = "F950";
            myTruck.Year = 2006;
            myTruck.Color = "Black";
            myTruck.TowingCapacity = 1200;
            printVehicleDetails(myTruck);

            Console.ReadLine();
        }

        private static void printVehicleDetails(Vehicle vehicle)
        {
            Console.WriteLine("Here are the vehcile's details: {0}",
                vehicle.FormatMe());
        }

    }

    abstract class Vehicle
    {
        public string Make { get; set; }
        public string Model { get; set; }
        public int Year { get; set; }
        public string Color { get; set; }

        public abstract string FormatMe();
    }

    class Car : Vehicle
    {
        public override string FormatMe()
        {
            return String.Format("{0} - {1} - {2} - {3}",
                this.Make,
                this.Model,
                this.Color,
                this.Year);
        }
    }

    sealed class Truck : Vehicle
    {
        public int TowingCapacity { get; set; }

        public override string FormatMe()
        {
            return String.Format("{0} - {1} - {2} Towing units",
                this.Make,
                this.Model,
                this.TowingCapacity);
        }

    }

    /*
    class Semi : Truck
    {

    }
    */

}
Source : MS Virtual Academy

16 December 2011

C# Lesson 16 : More About Classes and Methods

This lesson digs into more details about classes—what exactly happens when you create a new instance of a class? What is a reference to an instance of a class? How does passing the reference to a method affect a class? We also review overloaded methods, static versus instance methods, and constructors.

 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ObjectLifetime
{
    class Program
    {
        static void Main(string[] args)
        {
            Car myCar = new Car();

            // set properties

            Car myOtherCar = myCar;

            Car myThirdCar = new Car("Ford", "Escape", 2005, "White");
          

            myOtherCar = null;
            myCar = null;





        }
    }

    class Car
    {
        public string Make { get; set; }
        public string Model { get; set; }
        public int Year { get; set; }
        public string Color { get; set; }
        public double OriginalPrice { get; set; }

        public Car()
        {
            // You could this from a configuration file, a database, etc.
            // I'll just hardcode in this instance.
            this.Make = "Nissan";
        }

        public Car(string make, string model, int year, string color)
        {
            Make = make;
            Model = model;
            Year = year;
            Color = color;
        }

        /*
        public Car(string someOtherInputParameter, string model, int year, string color)
        {
            Make = someOtherInputParameter;
            Model = model;
            Year = year;
            Color = color;
        }
         * */

        public static void MyMethod()
        {

        }

    }

}
Source : MS Virtual Academy

15 December 2011

C# Lesson 15 : Understanding and Creating Classes

Classes are integral to the .NET Framework, particularly the .NET Framework Class Library. Learn how classes are defined and new instances are created, how to define Properties, and how to both set values and get values for a given instance of the class. 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SimpleClasses
{
    class Program
    {
        static void Main(string[] args)
        {
            Car myNewCar = new Car();

            myNewCar.Make = "Oldsmobile";
            myNewCar.Model = "Cutlas Supreme";
            myNewCar.Year = 1986;
            myNewCar.Color = "Silver";

            Console.WriteLine("{0} - {1} - {2}",
                myNewCar.Make,
                myNewCar.Model,
                myNewCar.Color);

            //double marketValueOfCar = determineMarketValue(myNewCar);

            Console.WriteLine("Car's value: {0:C}", myNewCar.DetermineMarketValue());

            Console.ReadLine();

        }

        private static double determineMarketValue(Car _car)
        {
            double carValue = 100.0;
           
            // Somedat white come to go online and look up the car's value
            // and trieve its value into the carValue variable
            return carValue;
        }

    }

    class Car
    {
        public string Make { get; set; }
        public string Model { get; set; }
        public int Year { get; set; }
        public string Color { get; set; }

        public double DetermineMarketValue()
        {
            double carValue = 100.0;

            if (this.Year > 1990)
                carValue = 10000.0;
            else
                carValue = 2000.0;

            return carValue;
        }

    }


}
Source : MS Virtual Academy

14 December 2011

C# Lesson 14 : Working with DateTime

Like strings, dates and times are represented using special types and so deserve some attention. In this lesson, we learn how to work with Date and Time data, how to create new instances of DateTime, how to add time, and how to format the data for display. We also discuss the TimeSpan class.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DatesAndTimes
{
    class Program
    {
        static void Main(string[] args)
        {
            DateTime myValue = DateTime.Now;
            //Console.WriteLine(myValue.ToString());
            //Console.WriteLine(myValue.ToShortDateString());
            //Console.WriteLine(myValue.ToShortTimeString());
            //Console.WriteLine(myValue.ToLongDateString());
            //Console.WriteLine(myValue.ToLongTimeString());

            //Console.WriteLine(myValue.AddDays(3).ToLongDateString());
            //Console.WriteLine(myValue.AddHours(3).ToShortTimeString());

            //Console.WriteLine(myValue.AddDays(-3).ToShortDateString());

            //Console.WriteLine(myValue.Month.ToString());

            //DateTime myBirthday = new DateTime(1969, 12, 7);
            //Console.WriteLine(myBirthday.ToShortDateString());

            DateTime myBirthday = DateTime.Parse("12/7/1969");
            TimeSpan myAge = DateTime.Now.Subtract(myBirthday);
            Console.WriteLine(myAge.TotalDays);

            Console.ReadLine();
        }
    }
}
Source : MS Virtual Academy

13 December 2011

C# Lesson 13 : Working with Strings

Since oftentimes in our applications we'll want to work with string data, this lesson approaches a number of different string manipulations. We look at built-in String methods to manipulate the content inside of a literal string and at the StringBuilder class for concatenating many strings together in a memory and resource-friendly manner.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Strings
{
    class Program
    {
        static void Main(string[] args)
        {
            //string myString = "Go to your c:\\ drive";
            //string myString = "My \"so called\" life";
            //string myString = "What if I need \n a new line?";

            //string myString = string.Format("{0}!", "Bonzai");
            //string myString = string.Format("Make: {0} (Model: {1})", "BMW", "760li");

            //string myString = string.Format("{0:C}", 123.45);
            //string myString = string.Format("{0:N}", 123456789);
            //string myString = string.Format("{0:P}", .123);
            //string myString = string.Format("Phone number: {0:(###) ###-####}", 1234567890);

            /*
            string myString = "";

            for (int i = 0; i < 100; i++)
            {
                //myString = myString + "--" + i.ToString();
                myString += "--" + i.ToString();
            }
             * */

            /*
            StringBuilder myString = new StringBuilder();

            for (int i = 0; i < 100; i++)
            {
                myString.Append("--");
                myString.Append(i);
            }
            */

            string myString = " That summer we took threes across the board  ";

            //myString = myString.Substring(5, 14);
            //myString = myString.ToUpper();
            //myString = myString.Replace(" ", "--");

            myString = String.Format("Length before: {0} -- After: {1}",
                myString.Length, myString.Trim().Length);

            Console.WriteLine(myString);
            Console.ReadLine();
        }
    }
}
Source : MS Virtual Academy

12 December 2011

C# Lesson 12 : While Iterations and Reading Data from a Text File

Learn a new type of iteration statement (while) and how to utilize the StreamReader class to stream data from a file to the Console window. Additionally, we learn how to add new files to our project, how to set properties of our file using the Properties window, and how to add a using statement as a means of resolving a class name referenced in our code to the namespace in which it is defined.

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ReadTextFileWhile
{
    class Program
    {
        static void Main(string[] args)
        {
            StreamReader myReader = new StreamReader("Values.txt");
            string line = "";

            while (line != null)
            {
                line = myReader.ReadLine();
                if (line != null)
                    Console.WriteLine(line);
            }

            myReader.Close();
            Console.ReadLine();

        }
    }
}
Source : MS Virtual Academy

11 December 2011

C# Lesson 11 : Creating and Calling Simple Overloaded Helper Methods

Now, we begin wading into the topic of methods by creating a helper method to break out code we may need to use in multiple places within our code. We create and call our methods to retrieve a value, create and use input parameters, learn about string formatting, and create overloaded versions of our method.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HelperMethods
{
    class Program
    {
        static void Main(string[] args)
        {
            //string myValue = superSecretFormula("world");
            string myValue = superSecretFormula("sunshine");
            Console.WriteLine(myValue);
            Console.ReadLine();
        }

        private static string superSecretFormula()
        {
            // some cool stuff here
            return "Hello World!";
        }

        private static string superSecretFormula(string name)
        {
            return String.Format("Hello, {0}!", name);

        }

    }
}
Source : MS Virtual Academy