Tag Archives: Microsoft Visual Studio Express 2013

C#: Day 4

Yesterday, I finished the 24 episode, 7+ hour, Channel 9, C# Fundamentals: Development for Absolute Beginners. While I could have been done by Day 3, or having done an extra episode or two each day, I chose to do it in a total of four. That allowed me to blog about it since Day 1, write the actual code myself, do the adequate note taking and commenting, go back and review what I had written, and do a little programming of my own. I think that was a good pace. Next is the 35 episode, 11+ hour, Channel 9, Windows Phone 8 Development for Absolute Beginners. Having completed this series, I should be prepared enough (I certainly am excited enough).

Finally, lesson 18 through 24, were especially rewarding and captivating (not that the previous seventeen weren’t). My admiration of the IDE has certainly increased as it is very helpful having automatic indentation when writing code around previous code and then with Enumerations and what Bob Tabor refers to as IDE magic: It truly is magical having an entire code block inserted for you that you otherwise would have typed yourself. Microsoft Visual Studio Express 2013 is an exceptional Integrated Development Environment.

Although I don’t go into detail of what is covered in the series from lesson to lesson, Exceptions was a heartfelt topic as I have been thorough with it ever since programming the ARexx language and through the Assembly language as well as ActionScript. Really, I think it should be Etiquette (deviquette?). Events were very familiar too of course, being what Bob refers to as the drive of a Graphical User Interface (GUI) application, which is close to what a few Doors were, with their Text-based User Interface (TUI), and also what ActionScript often is for, interactivity.

Concluding, below is the source code I wrote off the top of my head, summarizing C# Fundamentals: Development for Absolute Beginners.

I initially thought of Collections, Objects, ClassesMethods and LINQ, although, to obviate the beginner syndrome, chose the straightforward approach of the Framework Class Library (FCL), specifically the Base Class Library (BCL) and fundamental Statements, Expressions, Operators, Operands, StringsArrays, EventsStatic Classes and Static Class Members, Methods and Properties. Undoubtedly, there is a preferable approach to the logic I did and possibility to refactor the code I wrote, nonetheless, it does what it is intended to do.

I had an encounter with the “Index was outside the bounds of the array” error of which I set a breakpoint for debugging. It was satisfying to step over each statement, through each iteration and the branching, observing the Locals and Error List window and to pin variables and their value to the source (Debugging was something I used to like while programming the Assembly language too). A subsequent Bing of the error message and I knew what to look for.

This is a Windows Presentation Foundation (WPF) application (Native Windows Application), with a window of which you have a textbox to type in, a button to click and a textbox of which will output how long it took to type and the character total. The intent is to type a text without an ensuing space after a punctuation and a lowercase subsequent initial letter. When you click the button, it will insert a space after each punctuation and uppercase the subsequent initial letter into a capital letter. I contemplated whether to decipher acronyms and abbreviations too.

Screenshots of the WPF Application.

The C# and XAML WPF Application before and after a click of the Fix button.

The auto generated XAML in the IDE from dragging Controls from the Toolbox as well as from the use of the Properties Window was remarkable.

XAML

<Window x:Name="QuickNote" x:Class="QuickNote.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="QuickNote © Spiritus et Technologiae" Height="350" Width="525">
    <Grid>
        <TextBox x:Name="Notes" Height="255" Margin="10,10,10,0" TextWrapping="Wrap" Text="start typing here.click fix afterwards." VerticalAlignment="Top" ToolTip="Don't think of a space after punctuation or a subsequent capital letter. You do have to separate each word with a space and a sentance with punctuation though."/>
        <Button x:Name="Fix" Content="Fix" HorizontalAlignment="Left" Margin="220,280,0,0" VerticalAlignment="Top" Width="75" Click="Button_Click" ToolTip="Add a space at the end of each sentance and capitalize each initial letter."/>
        <TextBox x:Name="ElapsedTime" HorizontalAlignment="Left" Height="23" Margin="348,279,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="151"/>
    </Grid>
</Window>

C#

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 QuickNote     // © Spiritus et Technologiae
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        DateTime startTime = DateTime.Now;                          // Start the timer when the application launches

        public MainWindow()
        {
            InitializeComponent();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            //string textInput = Notes.Text;                        // Get the note into variable "textInput" of data type "string"

            char[] charArray = Notes.Text.ToCharArray();            // An array with the characters of the input
            string arrayChar = "";                                  // Declaration statement
            string nextChar = "";
            Notes.Text = "";
            int i = 0;                                              // A pointer for the next character in the array
            bool y = true;                                          // A flag, if true then uppercase character

            foreach (char Char in charArray)                        // Iteration statement
            {
                if (i == charArray.Length - 1)                      // If there aren't any characters after the current character
                {                                                   // then break, preventing "Index was outside the bounds of the array"
                    break;
                }
                else
                {
                    i++;                                            // Increment the pointer each loop through
                    nextChar = charArray[i].ToString();             // Get next character into variable "nextChar", explicitly convert to
                                                                    // string, increment pointer to point to next character consecutively
                    arrayChar = Char.ToString();                    // Get the current character into the variable "arrayChar"

                    if (arrayChar == ".")                           // Following code is self-explanatory:
                    {
                        if (nextChar == " " || nextChar == ".")     // Decision statement
                        {
                            Notes.Text = Notes.Text + ".";
                            y = false;
                        }
                        else
                        {
                            Notes.Text = Notes.Text + ". ";         // Concatination
                            y = true;
                        }
                    }
                    else
                    {
                        if (y == true)
                        {
                            Notes.Text = Notes.Text + arrayChar.ToUpper();
                            y = false;
                        }
                        else
                        {
                            Notes.Text = Notes.Text + arrayChar;    // Expression statement
                        }
                    }
                }
            }

            Notes.Text = Notes.Text + nextChar;                     // The last character

            //string addSpaces = textInput.Replace(".", ". ");      // Replace punctuation with a punctuation and a space in the string
                                                                    // "textInput" to a new string "addSpaces"
            //Notes.Text = addSpaces;                               // Output the note with added spaces to the "Notes" textbox

            TimeSpan totalTime = DateTime.Now.Subtract(startTime);  // Get total time since "Fix" was last clicked or application launched

            ElapsedTime.Text = String.Format(
                "{0} s. and {1} char(s).",                          // Format and explicitly convert timer and counter and output it
                                                                    // to the textbox "ElapsedTime"
                Math.Round(totalTime.TotalSeconds).ToString(),      // Chaining
                Notes.Text.Length.ToString());

            startTime = DateTime.Now;                               // Reset the timer when "Fix" is clicked
        }
    }
}

Get the executable program in a zip archive here. In addition, get the Channel 9 Windows 8 app here, like the Microsoft Visual Studio Facebook page here and get Visual Studio Update 1 here.

Advertisements

C#: Day 3

Yesterday, finishing lesson 13 through 17, a big piece of the puzzle is where it should be. Though I did pause, rewind and replay as well as use Notepad extensively while also commenting the code excessively. Later, a Eureka moment had everything become easier to grasp. Now, the terminology is becoming part of my vocabulary and the syntax is becoming increasingly natural. I love the fluidity of the Microsoft Visual Studio Express 2013 IDE with its Code Snippets and its IntelliSense, which when you get used to them, will have you writing code efficiently. I like Visual C#.

While progressing through the series, there is less and less familiarities with my previous knowledge of the Amiga ARexx and Assembly language programming. The Amiga Workbench .library files are now essentially Assemblies in .dll files with the .NET Framework, which is a library of Classes that you reference. In a sense (but not exactly), the keyword is now ‘Using’ Instead of ‘Include’. There, you have Namespaces with Classes and their Members, the Methods and Properties. The concept of References are familiar too and now Memory Allocation is done by the .NET Framework Runtime.

So, Microsoft .NET and the Common Language Runtime (CLR) have been introduced and I am happy, as there is great benefit from it. I did like being as close to the hardware as the Assembly language had me be, it being a low-level programming language, with the Data registers, Address registers, Stack pointers and Program counter of the Motorola 68000 architecture. The thought processes were close to the behavior of the hardware, while now, its high-level programming languages that are instead akin to natural language. It does have its advantages of course, although I still prefer the former.

Familiarity was closest to my previous knowledge of ActionScript right from the beginning. I recognize Properties, Data types, Statements, Arguments et cetera from ActionScript, as well as the Syntax being somewhat similar. ActionScript 3.0 is an Object Oriented Programming (OOB) language as is C#.

Thus far, I am not able to do any programming of significance with what I have. Rather, I am still getting the know-how to be able to. We’ll see where I’m at after Day 4.

This is code I wrote while I was learning ActionScript 3.0 with lynda.com Flash CS3 for Designers. It is easy to comprehend it having gone through this series and vice versa:

// Output
// trace("Hello World");
/*
// Cat object, claw attribute equals sharp
Cat.claw = "sharp";
// Listen to the event of woman shout and then make cat do
Woman.addEventListener(Event.Shout, makecatdo);
// Function make cat do
function = makecatdo() {
	// Cat object, jump method
	Cat.jump();
}
*/
// A variable is a container for information, : and then type of variable (strict type)
var h:String = "Hello World";
trace(h);
var weather:String = "It's cold";
// A function is used to control when we want to do certain things
function traceit(e:Event):void {
	// String concatenation
	trace(weather + " in December");
}
// CamelCase myArcadeButton, listen to an event, mouse click, traceit or textit
myArcadeButton.addEventListener(MouseEvent.CLICK, textits)
// Set text property of myText
function textits(e:Event) {
//	outText.text = "My dynamic text or trace button";
	// Set input text equal to outText
	outText.text = inText.text;
}
// Seamless Roll Over and Roll Out
function rollover(e:Event) {
	// In and out labels should be the frame after stop action frame to get smooth transitions
	myBtn.gotoAndPlay("in");
}
myBtn.addEventListener(MouseEvent.MOUSE_OVER, rollover);
function rollout(e:Event) {
	myBtn.gotoAndPlay("out");
}
myBtn.addEventListener(MouseEvent.MOUSE_OUT, rollout);
// Set masker as myImage mask, use cash as bitmap on both to get shape soften fill edges (alpha)
myImage.mask = themask;
// Mask to behave as a button so that we can add a mouse event to it
themask.buttonMode = true;
themask.addEventListener(MouseEvent.MOUSE_DOWN, drag);
function drag(e:Event) {
	// Enable drag functionality
	themask.startDrag();
}
themask.addEventListener(MouseEvent.MOUSE_UP, nodrag);
function nodrag(e:Event) {
	// Disable drag functionality
	themask.stopDrag();
}
// So that it doesn't continue draging if mouse up outside mask
themask.addEventListener(MouseEvent.MOUSE_OUT, nodrag);
// UILoader component function to change source (load image)
function loadit(e:Event) {
	myLoader.source = "C:/image.jpg";
}
loaditBtn.addEventListener(MouseEvent.CLICK, loadit);
// Create object textLoader with all the properties and methods of the URLLoader class
var loader:URLLoader = new URLLoader();
// Create object requester
var requester:URLRequest = new URLRequest("C:/text.txt");
// Load the requester
loader.load(requester);
// When an event, loader.load(), is done, show text
loader.addEventListener(Event.COMPLETE, showtext);
// The show text function
function showtext(e:Event) {
	// myText text is going to be the data that the loader has loaded from requester
	// Can also be dynText.htmlText so that it can parse html tags
	dynText.text = (loader.data);
	// Properties
	dynText.background = true;
	dynText.backgroundColor = 0x000000;
	dynText.border = true;
	// Hexadecimal color starts with 0x instead of html #
	dynText.borderColor = 0xff6600;
}
// Clear loaded image
clearitBtn.addEventListener(MouseEvent.CLICK, clearit);
function clearit(e:Event) {
		myLoader.source = null;
}
/* An instance of the array class, not a new empty array, but a predefined array
   Array data is defined withing brackets, separated by commas
   Arrays are storage for multiple variables, entries are numbers starting from 0 as the first */
var myArray:Array = ["C:/image0.jpg","C:/image1.jpg","C:/image2.jpg","C:/image3.jpg","C:/image4.jpg","C:/image5.jpg","C:/image6.jpg","C:/image7.jpg"];
// The caption array for the images description (desc)
var descArray:Array = ["First image","Second image","Third image","Fourth image","Fifth image","Sixth image","Seventh image","Eighth image"];
// Gallery
tnBtn1.addEventListener(MouseEvent.CLICK, img1);
function img1(e:Event) {
	// Load first image from first variable in array, access entries in array within brackets
	galleryloader.source = myArray[0];
	caption.text = descArray[0];
}
tnBtn2.addEventListener(MouseEvent.CLICK, img2);
function img2(e:Event) {
	galleryloader.source = myArray[1];
	caption.text = descArray[1];
}
tnBtn3.addEventListener(MouseEvent.CLICK, img3);
function img3(e:Event) {
	galleryloader.source = myArray[2];
	caption.text = descArray[2];
}
tnBtn4.addEventListener(MouseEvent.CLICK, img4);
function img4(e:Event) {
	galleryloader.source = myArray[3];
	caption.text = descArray[3];
}
tnBtn5.addEventListener(MouseEvent.CLICK, img5);
function img5(e:Event) {
	galleryloader.source = myArray[4];
	caption.text = descArray[4];
}
tnBtn6.addEventListener(MouseEvent.CLICK, img6);
function img6(e:Event) {
	galleryloader.source = myArray[5];
	caption.text = descArray[5];
}
tnBtn7.addEventListener(MouseEvent.CLICK, img7);
function img7(e:Event) {
	galleryloader.source = myArray[6];
	caption.text = descArray[6];
}
tnBtn8.addEventListener(MouseEvent.CLICK, img8);
function img8(e:Event) {
	galleryloader.source = myArray[7];
	caption.text = descArray[7];
}
// Music loop on off toggle
myMusic.myStop.addEventListener(MouseEvent.CLICK, stopmusic);
function stopmusic(e:Event) {
	myMusic.gotoAndStop(1);
	trace("Stop");
	SoundMixer.stopAll();
/* ActionScript 2.0
	stopAllSounds();
*/
}
myMusic.myPlay.addEventListener(MouseEvent.CLICK, playmusic);
function playmusic(e:Event) {
	trace("Play");
	myMusic.gotoAndPlay(2);
}
/* Variables */
// Whole number, integer, positive or negative
var score:int = 15;
/*
// Whole number, integer, positive
var score:uint = 15;
// Whole number, integer, positive, negative and decimal
var score:Number = 15;
*/
/* Functions */
// Create function addNumbers with parameters num1, num2 with datatypes Number (Strict typing) and the function will also return a number :Number
function addNumbers(num1:Number, num2:Number):Number {
	// Return the sum of num1 and num2
	return num1 + num2;
}
// Run the above function (and trace result)
trace(addNumbers(5,15));
/* Events */
// Function will recieve value information to parameter "event" with datatype MouseEvent, return void (event handler function)
function buttonClicked(event:MouseEvent):void {
	trace("Button Clicked");
}
/* Event Listeners */
// Connect object my_btn with an event, in this case, a mouse event of click, and further connect it to an event handler function, buttonClicked above
// my_btn.addEventListener(MouseEvent.CLICK, buttonClicked);
/* Arrays */
// Create variable my_ary and make it an array datatype
// Square brackets, shorthand notation, can have multiple dataypes, separate with commas
var my_ary:Array = [5, "David", true];
// Each item in an array has an index number which starts at 0 for the first item
trace(my_ary[1]);
/* Dynamic text */
// Create an instance of the URLLoader class, first part of creating a dynamic text loader, the object that will hold the external text once loaded
var textLoader:URLLoader = new URLLoader();
// Create URL request, second part of creating a dynamic text loader
var textReq:URLRequest = new URLRequest("as3.html");
// External CSS
var cssLoader:URLLoader = new URLLoader();
var cssReq:URLRequest = new URLRequest("as3.css");
// Make an object with the StyleSheet class
var style:StyleSheet = new StyleSheet();
// Define tag a style, object datatype and class is a dynamic class we can create custom properties on any instance of the object class (object shorthand notation {}) setStyle method of the StyleSheet class, the style of a is in an object with dynamic property color, colon to specify value, which is a string
// style.setStyle("a", {color:"#CC0000"});
// Load external text
textLoader.load(textReq);
// Listen to when text is finished loading
textLoader.addEventListener(Event.COMPLETE, textLoaded);
// Function for the event when text had finished loading
function textLoaded(event:Event):void {
	// End instance names with _txt and _btn for code hints, text property .htmlText, the data that is loaded in from the external text .data, .text for ascii
//	external_txt.htmlText = textLoader.data;
	// Apply internal stylesheet
//	external_txt.styleSheet = style;
	// External style sheet
	cssLoader.load(cssReq);
	cssLoader.addEventListener(Event.COMPLETE, cssLoaded);
}
function cssLoaded(event:Event):void {
	// Read the text as CSS
	style.parseCSS(cssLoader.data);
	external_txt.htmlText = textLoader.data;
	external_txt.styleSheet = style;
}

C#: Day 1

Cultural relic Commodore 64 home computer.

LOAD “$”,8,1

64 kB of RAM. Commodore 1530, SID, Commodore 1541, TAC-2, Floppy, Decrunchinget cetera. Introduction When we got our Commodore 64 I was so intrigued by the command-line interpreter, Commodore DOS, and fascinated by what my brother later did with BASIC, I had to try it for myself but only got a little further than Hello World. Later, I and my brother were introduced to the Demoscene as well, which sparked an interest for pixel art and coding that grew with subsequent computer platforms. I didn’t get far on the C64 and it wasn’t until after we got our Amiga 500 and then the Amiga 1200 that I really took to programming and pixel art (I love you Photoshop but you will never be my Deluxe Paint). During the A500 I developed an interest in the Amiga Workbench operating system. On the A1200 I developed further interest in hardware and software. I upgraded the A1200 from 14 MHz to 28 MHz, from 2 MB to an additional 4 MB RAM and a 40 MB HDD, next was a Motorola 68040 central processing unit at 33 Megahertz, 8 Megabyte of RAM, 540 MB Hard Disk Drive and had a 28.8k V.FAST Modem. Later, my brother talked me into breaking the bank on the Blizzard 1260 Accelerator with the Motorola 68060 CPU clocked at 50 MHz and with 16 MB Fast Memory. Sigh, the 39 MIPS in Workbench 3.0 (and Tornado) made it worthwhile. By then I had 1.1 GB HDD, more bauds and bits with a 57.6k Modem and a 6x CD-ROM. On it, I ran a Bulletin Board System, The Lock-Up BBS. Doors were the Apps of the time, for Bulletin Board Systems, which were the Internet equivalent of the time, sort of. As a Sysop, I was not satisfied with the available Doors so I quickly learned the ARexx language. I had a series of Doors when I jumped to the Assembly programming language and continued programming Doors. Optimizing the code became a passion. I even did CPU specific executables. I preferred customization and as a result my Doors were highly configurable. A few of my aliases were BigBang, Fusion and Dave. I had just begun coding a Workbench application at the time of the Commodore Amiga demise. When I got my first PC, with an AMD K6, I was turned off to programming on it at the time and quit (it wasn’t that easy breaking up with my Amiga and her Motorola 68000 family). Although, it was a good high-end PC at the time. Later though, I learned HTML and CSS. A while ago I was on and off ActionScript too but wasn’t convinced.

The Commodore Amiga 1200 personal computer.

Cultural relic A1200.

AGA, DOpus, X-COPY, D-COPYCloser by CNCD, ProTracker, OctaMED, Imagine, LightWave 3D, Joystick, Datic (Alfa Data) Chrystal Trackballet cetera. C Sharp Long overdue, I am finally going to be programming again. I chose C# (Visual C#) to go with the development of Windows 8 and in particular Windows Phone 8 apps and I will document the process here on my blog. Today I got around to begin the Channel 9, C# Fundamentals: Development for Absolute Beginners. I have no knowledge of any C programming language prior. I have finished lesson 1 through 5 and so far almost everything is very familiar due to my previous knowledge. I like the free Microsoft Visual Studio Express 2013 too (I’ll always miss you ASM-One). The low level Assembly programming language put me off to high level programming languages up until recently (I prefer the Close to Metal approach) but now I have a newfound interest. I’ll summarize and go into detail for my second day. Clearly, I got lost in nostalgia for this first post. My Initial experience is positive though!

Screenshots of various BBS Doors and the Amiga Workbench.

The Lock-Up BBS

Screenshot collage of a few of my Doors, my BBS, a glimpse of my Workbench, and ANSI.