Tuesday, 19 January 2016

.Net - Visual Studio 2015 Update 1 installation known issues

Below are the common issues that I faced when installing Visual Studio Community.

1. Microsoft .NET Framework 4.6.1 Developer Pack – Incorrect Function
If the "Incorrect function" error occurs, you have to restart your computer.
Workaround:
To work around this issue, restart your computer before you install the Visual Studio 2015 Update 1 package again.
2.  Visual Studio installer gets stuck
If the installer does nothing for a long time its probably stuck . Check if there is any CPU activity . 
In that case, terminate the installer process from task manager and restart the machine.
The installer will start again itself and will continue running. That worked for me.

3. System crash error
Make sure your laptop is on charging mode during the entire setup process. If you plugged the charging off,  you'll probably get the system crash error on typical windows blue screen.

Hope that help :).. please share and follow if you like it.

Monday, 11 January 2016

JavaScript - Best way to traverse an array in JavaScript


There are several ways to traverse through an array in JavaScript. The idea is to access the array elements by an index variable and keep incrementing it until the array length.

But what if some array elements have undefined values , what if the number of array elements having valid values are less than the total length of the array. Such cases are handled by explicit checks on element values and array length.

One of the better way is to use the for .. in statement. It will skip all the undefined values and you don't have to keep track of the valid index values or the array length. Below is the code,


<?xml version="1.0" encoding="utf-8" ?>
<html>
<head>
<title> display all heading types page </title>
<script type="text/javascript">
<!--
var arr1 = [5,,7,8];
for ( var element in arr1)
{
document.writeln(arr1[element]);
}


// -->
</script>
</head>

</html> 

Variable element will have only the valid index values ie the indexes at which array elements have definite values. Thus index value 1 will be skipped as there is no value at arr1[1]. The above code will print 5 7 8 . 


I hope it helps :)

Sunday, 10 January 2016

JavaScript - generate random integers between 2 values


To generate random values, JavaScript provides Math.random() method. This method generates values in the range 0.0 and 1.0, 1.0 excluded. We can use this function according to our requirements.

Here , if I give an example of a six sided dice. we would need a random number between 1 to 6 , both included.

The formula is Math.floor( lower +  Math.random() * upper ).  lower is the starting value and is called shifting value. upper is the maximum value and is called scaling value. Here is the complete code.

<?xml version="1.0" encoding="utf-8" ?>
<html>
<head>
<title> Generate Random Numbers </title>
<script type="text/javascript">
<!--

function getRandom()
{
var ran = Math.floor( 1 + Math.random() * 6);
window.alert(" you got " + ran);
}

// -->
</script>
</head>
<body>
<input type="button" value="next number"                                          onclick="getRandom()" />
</body>
</html> 

Note : If you omit the floor function, it will give you float values and also values between 6 and 7, which is not the requirement. However, if you require float values you can skip floor function and check if the value is > 6 then make it back to 6 before it is displayed.


I hope it was useful  :) 

Thursday, 7 January 2016

HTML/CSS - drop down menu using anchor ( a ) element and display attribute


Below code creates a simple drop down menu using the anchor ( <a> ) element and display property in CSS.

XHTML code :

<?xml version="1.0" encoding="utf-8" ?>
<html>
<head>
<title> use display property </title>
<link type="text/css" rel="stylesheet" href="display.css" />
</head>
<body>
<div id="mainmenu"><a class="mainitem" href="#">Menu</a>
<a class="subitem" href="#">Food</a>
<a class="subitem" href="#">Beverages</a>
<a class="subitem" href="#">desserts</a>
</div>
</body>
</html>

display.css

.subitem{
display:none;
}

#mainmenu
{
width:5em;
}
#mainmenu:hover a.subitem{
display:block;
}

#mainmenu a.subitem{
display:none;
}


display:block will display the anchors as one block.


Hope that helps :). Share if you like it.