google search

Wednesday, September 10, 2008

DotNet Framework 3.5 Beta 1 is released

Hi All,

The Microsoft .NET Framework 3.5 Beta 1 is a preview release of the latest version of the .NET Framework. The .NET Framework 3.5 which is cent percent backward compatible, adds many new exciting features in several major technology areas;  

For more detail about the features being introduced in .NET Framework 3.5 and Visual Studio code name “Orcas”, click herehttp://msdn2.microsoft.com/en-us/vstudio/aa700830.aspx

Monday, September 8, 2008

Managing Browser History and Back Button Support in ASP.NET AJAX

ASP.NET Futures (July 2007): Managing Browser History and Back Button Support in ASP.NET AJAX

This section provides information about the following features::

  • History and book marking. You can manage history points in your application, which lets users click the browser's Back and Forward buttons to navigate logically through your application instead of browsing to other pages.
  • The History server control. This control lets you manage application history and use the Navigate event in the server and client.
  • The client Sys.Application object. This object lets you set history points. It also calls the pageNavigate function.

ASP.NET Futures (July 2007) release The following changes and additions have been introduced:

  • History is now supported for the Apple Safari browser.
  • Any state that is provided through the server is encoded and can be encrypted.
  • You can define titles for individual history entries to be able to specify the page title used in the browser's history list.
  • You can use history support entirely in the client, without the need for a server control.

History Management with Server Controls:

Server-based history management is provided by the History Web server control. This control enables you to handle server events as you normally do in postback scenarios and to set a history point on the control. At the history point you define an object or data (that is, state) that will be used to recreate your page when a navigation event is raised. When you create history points, the page's URL is appended with the serialized and encrypted data that is required to recreate the state of the page. This also creates an entry in the browser's history stack.

When users click the browser's Back button, the browser navigates through previously-viewed URLs, which will include URLs that contain history-point data. A Navigate event is raised for the History control; the event data includes the data appended to the URL. This enables you to handle the event and recreate the page state as required in your application.

The following example uses the UpdatePanel control for asynchronous postbacks. The History control is used to add history points during the Click event handler of the buttons that trigger the asynchronous postbacks. As a result, when you click the browser's Back button, you do not leave the Web page, but instead navigate through the previous UpdatePanel postbacks.

Enabling Permalinks to Page State

You can enable users to set a permalink to a specific state of the page. This means that they can bookmark a particular point in your application and then set the page with that state as a favorite or email the permalink URL so that the specific page state can be recreated.

To enable users to create a permalink, you can get the current state by using the Sys.Application.get_history().get_stateString() in client script, and History.getStateString() in server code. The following example shows how to create a permalink for a specific state through client-side JavaScript code.

Managing the Title of a History Entry

Typically, entries in the browser's history stack are identified by the title of the page for that entry. (To see an example of this, use the browser's recent-pages drop-down list to view the titles.) By default, when you create history entries in your application as described previously, the page's title is used to identify a history-state entry. However, you can provide meaningful titles for individual history entries. The following sample shows how to perform this task. In the client, add a title parameter when you call the Sys.Application.get_history().addHistoryPoint( ) method. In server code, you can add a title when you call the History.AddHistoryPoint( ) method.

Sunday, September 7, 2008

ASP.NET in the .NET Framework 3.5 Service Pack 1 release includes numerous bug fixes

ASP.NET in the .NET Framework 3.5 Service Pack 1 release includes numerous bug fixes. In addition, it includes features for the following:

·          Enabling high-productivity data scenarios by using ASP.NET Dynamic Data.

·          Supporting the browser navigation in ASP.NET AJAX applications by using ASP.NET AJAX browser history.

·          Increasing the download speed for ASP.NET applications by using ASP.NET AJAX script combining.

 

New Futures:

1)      ASP.NET Dynamic Data

2)      ASP.NET AJAX browser History

3)      ASP.NET AJAX script combining

4)      ADO.NET Data Service

5)      ADO.NET Entity Framework

 

ASP.NET Dynamic Data:

ASP.NET Dynamic Data brings major usability and RAD development changes to the existing ASP.NET data controls. RAD development is significantly increased by the use of a rich scaffolding framework. After you add a LINQ to SQL or Entity Framework data model to a project, you can simply register it with Dynamic Data. The result is a fully functional Web site. Full CRUD (create, read, update, and delete) operations are supported. The site includes filtering by foreign keys and Boolean fields; foreign keys are automatically converted to their friendly names. Smart validation is automatically available, which provides validation based on database constraints for nullable fields, data type, and field length.

The DetailsView and GridView controls have been extended to display fields by using templates instead of by using hard-coded rules that are programmed in the controls. These templates are part of the project, and you can customize them to change their appearance or to specify which controls they use for rendering. This makes it very easy to make a change in one place in your site that specifies how to present dates for editing, as one example. FormView and ListView controls can implement similar behavior by using a DynamicControl object in their templates and by specifying which field in the row to display. Dynamic Data will then automatically build the UI for these controls based on the templates that you specify. 

Validation is significantly improved in the controls as well. The controls read metadata for a LINQ to SQL or Entity Framework data model and provide automatic validation based on the model. For example, if a column in the database is limited to 50 characters, and if a column is marked as not nullable, a RequiredFieldValidatorcontrol is automatically enabled for the column. (The controls also automatically support data-model-level validation.) You can apply other metadata to take further control over display and validation. 

The RTM version of Dynamic Data and Entity Framework have a naming mismatch that can cause some errors with some types of data relationships. A workaround is available which provides a fix for 1->0..1 and *->1 relationships which may generate error messages similar to "'System.Web.UI.WebControls.EntityDataSourceWrapper' does not contain a property with the name 'Orders.OrderID'". This fix replaces the default Entity Framwork Data Model provider for Dynamic Data with a new data model provider that works around these issues.

For More information Please click on following link:

http://www.asp.net/downloads/3.5-SP1/default.aspx

Wednesday, August 27, 2008

Variables can be declared at different levels

Declaring Local Variables
In the What is a Variable? section, we demonstrated declaring the myMessage variable using the
Dim reserved word.
Here is the example that we used:

Dim myMessage As String

The meaning of the 4 pieces of information:
Dim - This reserved word sets aside memory in the computer for the "myMessage" variable.
myMessage - This is the actual variable. You can name your variable whatever you want, as long as it is not a reserved word (see the Reserved Words section for more information).
As - This reserved word tells Visual Basic to create the variable of the data type that follows.
String - This reserved word is the specific data type to create the variable as.
--------------------------------------------------------------------------------
In our example, the Dim reserved word was used to declare a local variable. A local variable is a variable that is declared within a Sub Procedure, Function or Property. Because it local, the variable can only be used within the Sub Procedure, Function or Property that it is declared in.

Here's an example, where we declare the myMessage variable within the Button1_Click Sub Procedure, store the text "Hello World" in it, and display the text in a message box.

Note: You can create a Click Sub Procedure for a button by adding a button to your form, and double-clicking on it
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles Button1.Click

Dim myMessage As String
myMessage = "Hello World"
MsgBox(myMessage)
End Sub

Because the myMessage variable is local to the Button1_Click Sub Procedure, it cannot be accessed from outside of that Sub Procedure.
--------------------------------------------------------------------------------
Now, if we create second Button Click procedure, and try to use the myMessage variable from above, Visual Basic will produce the following error: Name 'myMessage' is not declared.

Before we can run the program, we must fix the error by either declaring the myMessage variable, or removing our line of code. Here is the corrected code:

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles Button2.Click
Dim myMessage As String
myMessage = "Hello World"
MsgBox(myMessage)
End Sub
--------------------------------------------------------------------------------
Declaring Member Variables

Member variables are variables that are declared at module level, instead of within a Sub Procedure, Function or Property.

By declaring variables at a module level, variables can be shared between Sub Procedures, Function and Properties, without having to be declared locally. Member variables have greater accessibility than local variables.

Here's the example from above, but this time, the myMessage variable is a member variable, declared at module level, instead of locally within either of the Sub Procedures.

Dim myMessage As String = "Hello World"
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles Button1.Click
MsgBox(myMessage)
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles Button2.Click
MsgBox(myMessage)
End Sub

Monday, August 25, 2008

How to check on client side the file size in an Input File object?





<HTML>

<Head>

<Script Language=JavaScript>



function getStats(fName){



nullIMG.src = fName;

fullName = fName;

shortName = fullName.match(/[^\/\\]+$/);


splitName = fullName.split(".");

fileType = splitName[1];

fileType = fileType.toLowerCase();

if (fileType == 'gif' || fileType == 'jpg' || fileType == 'jpeg')

{

checkIt = fileSize(fullName);

if (parseInt(checkIt) > 4000){alert('Max File Size is 4Kb');Form1.reset()}


else {

Form1.dispSize.value = checkIt;

Form1.dispName.value = shortName;

Form1.dispW.value = nullIMG.width;

Form1.dispH.value = nullIMG.height;

}

}

else {

alert("You must select an image file!");


Form1.reset();

}

}



divStr = "<Div Style='Position:Absolute;Top:-2000'><IMG Src=Null ID=nullIMG></Div>"

document.write(divStr)



</Script>


<Script Language=VBScript>



Function fileSize(fileSpec)

Dim isSize

Set fso = CreateObject("Scripting.FileSystemObject")

Set contentFile = fso.GetFile(fileSpec)

isSize = contentFile.Size

fileSize = isSize


Set contentFile = Nothing

Set fso = Nothing

End Function



</Script>

</Head>

<Body>

<Form name='Form1'>

Choose an image: <input type="file" name="isIMG" onChange="getStats(this.value)"><br>


File Name: <input name='dispName' size=20><br>

File Size: <input name='dispSize' size=10><br>

Width: <input name='dispW' size=5><br>

Height: <input name='dispH' size=5><br>

<input type=Reset><br>


<input type=submit value="Submit Form">

</Form>

</body>

</html>






How to check on client side the file size in an Input File object

<HTML>
<Head>
<Script Language=JavaScript>

function getStats(fName){

nullIMG.src = fName;
fullName = fName;
shortName = fullName.match(/[^\/\\]+$/);
splitName = fullName.split(".");
fileType = splitName[1];
fileType = fileType.toLowerCase();
if (fileType == 'gif' || fileType == 'jpg' || fileType == 'jpeg')
{
checkIt = fileSize(fullName);
if (parseInt(checkIt) > 4000){alert('Max File Size is 4Kb');Form1.reset()}
else {
Form1.dispSize.value = checkIt;
Form1.dispName.value = shortName;
Form1.dispW.value = nullIMG.width;
Form1.dispH.value = nullIMG.height;
}
}
else {
alert("You must select an image file!");
Form1.reset();
}
}

divStr = "<Div Style='Position:Absolute;Top:-2000'><IMG Src=Null ID=nullIMG></Div>"
document.write(divStr)

</Script>
<Script Language=VBScript>

Function fileSize(fileSpec)
Dim isSize
Set fso = CreateObject("Scripting.FileSystemObject")
Set contentFile = fso.GetFile(fileSpec)
isSize = contentFile.Size
fileSize = isSize
Set contentFile = Nothing
Set fso = Nothing
End Function

</Script>
</Head>
<Body>
<Form name='Form1'>
Choose an image: <input type="file" name="isIMG" onChange="getStats(this.value)"><br>
File Name: <input name='dispName' size=20><br>
File Size: <input name='dispSize' size=10><br>
Width: <input name='dispW' size=5><br>
Height: <input name='dispH' size=5><br>
<input type=Reset><br>
<input type=submit value="Submit Form">
</Form>
</body>
</html>"

Tuesday, August 12, 2008

Using Variables in Excel VBA Macro Code

VARIABLES

A Variable is used to store temporary information that is used for execution within the Procedure, Module or Workbook. Before we go into some detail of Variables, there are a few important rules that you must know about.

1) A Variable name must Start with a letter and not a number. Numbers can be included within the name, but not as the first character.
2) A Variable name can be no longer than 250 characters.
3) A Variable name cannot be the same as any one of Excel's key words. By this, I mean you cannot name a Variable with such names as Sheet, Worksheet etc.
4) All Variables must consist of one continuous string of characters only. You can separate words by either capitalising the first letter of each word, or by using the underscore characters if you prefer.

You can name variables with any valid name you wish. For Example you could name a variable "David" and then declare it as any one of the data types shown below. However, it is good practice to formalize some sort of naming convention. This way when reading back your code you can tell at a glance what data type the variable is. An example of this could be the system I use! If you were to declare a variable as a Boolean (shown in table below) I may use: bIsOpen I might then use this Boolean variable to check if a Workbook is open or not. The "b" stands for Boolean and the "IsOpen" will remind me that I am checking if something is open.

You may see code that uses letters only as variables, this is bad programming and should be avoided. Trying to read code that has loads of single letters only can (and usually does) cause grief.

Variables can be declared as any one of the following data types:

Byte data type
A data type used to hold positive integer numbers ranging from 0 to 255. Byte variables are stored as single, unsigned 8-bit (1-byte) numbers.

Boolean data type
A data type with only two possible values, True (-1) or False (0). Boolean variables are stored as 16-bit (2-byte) numbers.

Integer data type
A data type that holds integer variables stored as 2-byte whole numbers in the range -32,768 to 32,767. The Integer data type is also used to represent enumerated values. The percent sign (%) type-declaration character represents an Integer in Visual Basic.

Long data type
A 4-byte integer ranging in value from -2,147,483,648 to 2,147,483,647. The ampersand (&) type-declaration character represents a Long in Visual Basic.

Currency data type
A data type with a range of -922,337,203,685,477.5808 to 922,337,203,685,477.5807. Use this data type for calculations involving money and for fixed-point calculations where accuracy is particularly important. The at sign (@) type-declaration character represents Currency in Visual Basic.

Single data type
A data type that stores single-precision floating-point variables as 32-bit (2-byte) floating-point numbers, ranging in value from -3.402823E38 to -1.401298E-45 for negative values, and 1.401298E-45 to 3.402823E38 for positive values. The exclamation point (!) type-declaration character represents a Single in Visual Basic.

Double data type
A data type that holds double-precision floating-point numbers as 64-bit numbers in the range -1.79769313486232E308 to -4.94065645841247E-324 for negative values; 4.94065645841247E-324 to 1.79769313486232E308 for positive values. The number sign (#) type-declaration character represents the Double in Visual Basic.

Date data type
A data type used to store dates and times as a real number. Date variables are stored as 64-bit (8-byte) numbers. The value to the left of the decimal represents a date, and the value to the right of the decimal represents a time.

String data type
A data type consisting of a sequence of contiguous characters that represent the characters themselves rather than their numeric values. A String can include letters, numbers, spaces, and punctuation. The String data type can store fixed-length strings ranging in length from 0 to approximately 63K characters and dynamic strings ranging in length from 0 to approximately 2 billion characters. The dollar sign ($) type-declaration character represents a String in Visual Basic.

Object data type
A data type that represents any Object reference. Object variables are stored as 32-bit (4-byte) addresses that refer to objects. Variant data type A special data type that can contain numeric, string, or date data as well as the special values Empty and Null. The Variant data type has a numeric storage size of 16 bytes and can contain data up to the range of a Decimal, or a character storage size of 22 bytes (plus string length), and can store any character text. The VarType function defines how the data in a Variant is treated. All variables become Variant data types if not explicitly declared as some other data type.

Why we use variables

Excel will still allow us to run our code without using variables, it is not a must! But having said this it is very bad programming to not use variables. You could quite easily just assign a value, string or whatever each time you need it, but it would mean:

1) Your code would become hard to follow (even for yourself)
2) Excel would constantly need to look for the value elsewhere.
3) Editing your code would become awkward.

Let's use an example to highlight the above

Sub NoVariable()

Range("A1").Value = Range("B2").Value

Range("A2").Value = Range("B2").Value * 2

Range("A3").Value = Range("B2").Value * 4

Range("B2").Value = Range("B2").Value * 5

End Sub

In the above code, Excel would need to retrieve the value from cell B2 five times. It would also mean if we had many other procedures using the same value i.e B2, it would need to retrieve it's value even more times.

There is a lot of editing to be done if we were to change from wanting B2 value to say, B5 value. It is messy code.

Let's now use a variable to store the value of cell B2!

Sub WithVariable()

Dim iMyValue as Integer

iMyValue = Range("B2").Value

Range("A1").Value = iMyValue

Range("A2").Value = iMyValue * 2

Range("A3").Value = iMyValue * 4

Range("B2").Value = iMyValue * 5

End Sub

In the above code Excel only needs to retrieve the value of cell B2 once.
To edit our code we only need to change it in one place.
It is easier to read.

You might be thinking that there is no big difference in the above 2 examples, and to a point you would be correct. But what you must realize is, most VBA projects will consist of hundreds (if not thousands) of lines of code. They would also contain a lot more than one procedure. If you had 2 average size VBA projects, one using variables and one without, the one using variables would run far more efficiently!

Declaring Variables

To declare a variable we use the word "Dim" (short for Dimension) followed by our chosen variable name then the word "As" followed by the variable type. So a variable dimmed as a String could look like:

Dim sMyWord As String

You will notice that as soon as we type the word As, Excel will display a drop-down list of all variables.

The default value for any Numeric type Variable is zero.
The default value for any String type variable is "" (empty text).
The default value for an Object type Variable is Nothing. While the default value for an Object type Variable is Nothing, Excel will still reserve space in memory for it.

To assign a value to a Numeric or String type Variable, you simply use your Variable name, followed by the equals sign (=) and then the String or Numeric type. eg:

Sub ParseValue()

Dim sMyWord as String

Dim iMyNumber as Integer

sMyWord = Range("A1").Text

iMyNumber = Range("A1").Value

End Sub

To assign an Object to an Object type variable you must use the key word "Set". eg:

Sub SetObJect()

Dim rMyCell as Range

Set rMyCell = Range("A1")

End Sub

In the example immediately above, we have set the Object variable to the range A1. So when we have finished using the Object Variable "rMyCell" it is a good idea to Set it back to it's default value of Nothing. eg:

Sub SetObjectBack()

Dim rMyCell as Range

Set rMyCell = Range("A1")



Set rMyCell = Nothing

End Sub

This will mean Excel will not be reserving unnecessary memory.

In the first example above (Sub ParseValue()) we used 2 lines to declare our 2 variables ie
Dim sMyWord as String
Dim iMyNumber as Integer
We can, if we wish just use:
Dim sMyWord as String, iMyNumber as Integer
There is no big advantage to this, but you may find it easier.

Not Declaring Variables

There is a difference between using variables and correctly declaring them. You can if you wish not declare a variable and still use it to store a Value or Object. Unfortunately this comes at a price though! If you are using variables which have not been dimensioned Excel (by default) will store them as the Variant data type. This means that Excel will need to decide each time it (the variable) is assigned a value what data type is should be. The price for this is slower running of code! My advise is do it right and form the good habit early!

There is also another advantage to correctly declaring variables and that is Excel will constantly check to ensure you have spelt the variable name correctly. It does this by capitalizing the all lower case letters that are capitalized at the point it was dimensioned. Let's assume you you use:

Dim iMyNumber As Integer

At the top of your procedure. You then intend to use this variable in other parts of the procedure. Each time you type imynumber and then push the Space bar or Enter Excel will capitalize it for you i.e imynumber will become iMyNumber. This is a very simple and easy way to ensure you have used the correct spelling.

While we are on this subject, it is very good practice to type all code in lower case, because not only will Excel do this for variables but also for all Keywords!

There may be times when you will actually need to use a Variant data type as you cannot be certain what will be parsed to it, say from a cell. It might be text, it maybe a very low or high number etc. In these circumstances you can use:

Dim vUnKnown As Variant
Or, simply:
Dim vUnKnown

Both are quite valid! The reason we do not have to explicitly declare a Variant is because the default for a variable is a Variant.