Thursday, November 20, 2008

How to reset AutoNumber in Microsoft Access table?

After testing my own application, now it's time for deploying it. 
Well, there are many junk records being added in the table, and now it's time to reset everything.
The AutoNumber field value in Access does not automatically reset when you delete the rows in the table. Finally, I've found the solution here.

Steps:
1. Delete the AutoNumber field from the table.
2. Click Queries on the left pane, and double-click Create query in Design view on the right pane.
3. In the Show Table dialog box, select the table. Then click Add to add the table and Close the dialog box.
4. Double-click all the fields in the table to select the fields.
5. Select the required Sort order, if there's any.
6. Click Make-Table Query on the Query menu. Type the new table name in the Table Name text box and then click OK.
7. Click Run on the Query menu.
8. A dialog box appears with the text that follows: You are about to append # row(s) into a new table. Click Yes to insert the rows.
9. Click Close on the File menu. Click No to close the Make-Table Query window to discard saving the query.
10. Click Tables on the left pane. Right-click on the new table and then click Design view.
11. In the Design view for the table, add an AutoNumber field with the same field name that you deleted in step 1. Then save the table.
12. Close the Design view window.
13. Delete the original table, and rename new table name to the original table name.
Now the AutoNumber has started from 1.

For more information, please refer to Microsoft Help and Support.

Tuesday, November 18, 2008

To lock your computer

My colleague just sent us this email, regarding how to lock the computer.
I think it's quite useful if you are using the computer in the office, and always want to lock it when you are away.

The easiest shortcut: Press Windows logo key + L

Or, you can create a shortcut on your desktop.

1. Right-click the desktop.
2. Point to New, and then click Shortcut.
3. The Create Shortcut Wizard opens. 
In the text box, type the following:
rundll32.exe user32.dll,LockWorkStation
4. Click Next.
5. Enter a name for the shortcut. e.g. "Lock Workstation"
6. Click Finish.

You can also change the shortcut's icon. e.g. padlock icon in shell32.dll
To change the icon:
1. Right click the shortcut and then select Properties.
2. Click the Shortcut tab, and then click the Change Icon button.
3. In the Look for icons in this file text box, type: Shell32.dll
4. Click OK.
5. Select one of the icons from the list and then click OK.

This is the shortcut I've created on my desktop: 

Tuesday, November 11, 2008

StrConv function - to capitalize the first character in the sentence

Reference: Chennai IQ

I wanted to write a function to capitalize the first character of every word. For example, I want to change "cell address" to "Cell Address". Before I started the function, I was thinking perhaps there already has a easy way to do that. Luckily, I did a search in the Google and found this: StrConv

This is the function I've written:
Public Function CapitalizeFirstCharacter(ByVal Value As String) As String
    
    ' Make the whole string lower case, then only capitalize the first character
    CapitalizeFirstCharacter = StrConv(LCase$(Value), vbProperCase)

End Function

Syntax:
StrConv (String, conversion[, LCID])

String - required. String expression to be converted.
conversion - required. Integer. The sum of values specifying the type of conversion to perform.
LCID - optional. The LocaleID, if different than the system LocaleID. (default: system LocaleID)

conversion argument:
ConstantsValueDescription
vbUpperCase1Convert to uppercase
vbLowerCase2Convert to lowercase
vbProperCase3Convert the first letter of every word in string to uppercase

There are also vbWide, where values are 4, 8, 16, 32, 64, 128 to convert the string with specific usage. (Please refer to the reference page)

Monday, November 10, 2008

New line character in Excel cell

This is really simple, but I didn't know how to do it until just now. 
Everytime when I press the "Enter" key, I'll be brought to the next cell of the Excel.
Until just now, I found out actually there is a way to go to the next line in the same cell.



This is pretty simple, just press Alt & Enter key, that's it! :D

It's called Line Feed character.
In VB, it can be done by calling Chr(10) or vbLf.
e.g. 
"a) Sentence 1" & Chr(10) & "b) Sentence 2" or
"a) Sentence 1" & vbLf & "b) Sentence 2" or

Information extracted from AllExperts site.

Friday, July 25, 2008

Understanding the differences between Cache, Session and ViewState

URL: http://www.progtalk.com/ViewArticle.aspx?ArticleID=62

My colleague sent this article to us recently. After I've read it, I found it quite useful and easy to understand, just wanna share it out.

In the article, it introduces these 3 types of storage methods: Cache, Session, ViewState.

To be honest, I only used session before. :p
It's time for me to learn how to use the storage methods probably, to make the web application better.

These are the notes I've taken:
----------------------------------------

Cache
- memory.
- allow you to store difficult and complex constructed data which will can be reused.
- is available to be accessed from global/application level where one reference to memory is updated. Each request will use the same cache for different users.

Session
- a period of time that is shared between the web application and the user.
- Each user that is using the web application has their own session.
- The Session variables will be cleared by the application which can clear it, as well as through the timeout property in the web config file.
- Session variables will use different session variables for each different user.

ViewState
- hidden data that is kept by ASP.NET pages.
- track the changes to a web site during post backs.
- All server controls contain a view state.
[EnableViewState property - enable/disable if the control properties will be held in hidden fields.]
- Having a large ViewState will cause a page to download slowly from the users side.
- When a user clicks on a button and a post back occurs, all the view state information has to be posted back to the server which causes a slower request.
- ViewState should be limited to what is needed.
- Data can also be written into the ViewState.
- The ViewState only persists for the life cycle of the page.
- If the page redirects to another page, or even to itself, the ViewState will be reset.
- ViewState should be used to hold small amonts of data, which will be only used on the current page.

Wednesday, April 9, 2008

Show message box in ASP.NET

I've written a simple function which uses JavaScript.

private void ShowMessageBox(string Message)
{

Label lblMessageBox = new Label();

lblMessageBox.Text =

"<script language='javascript'>" + Environment.NewLine +
"window.alert('" + Message + "')</script>";

Page.Controls.Add(lblMessageBox);

}

To call out the message box, just write this:

ShowMessageBox("Hello world!");

The problem with this is that I can't customize the message box. I can only pass in the message as parameter, but not changing the title, the button text or image.
Message box

Wednesday, April 2, 2008

Add javascript dropdownlist in your blog

I was looking for a way to add a dropdownlist in my blog, finally I've found this. Happy It's simple and it's what I want.

I do not know why the above dropdownlist is not working, but when you copy these codes to your blog, it should be able to work.

Just copy the following codes, and add to your blog. In Blogger, Add these codes in HTML/Javascript element, then it works fine.

<!--BEGIN dropdownlist--><script language="JavaScript">
function selectOption(selObj){
window.open(selObj.options[selObj.selectedIndex].value);}</script>

<select style="background: #c6e2ff; color: #000000" onchange="selectOption(this)">
<option value="">- Please select -</option>
<option value="http://www.google.com">Google</option>
<option value="http://www.yahoo.com">Yahoo</option>
<option value="http://www.msn.com">MSN</option></select>
<!--END dropdownlist-->



 


I got this script from this blog. Thanks! Happy

Monday, March 24, 2008

Set security access to folder

I'm currently doing a small function, where I need to create folder dynamically, if the folder does not exist.

Creating folder is easy, but I also need to set the security access. Finally, I've found the way of doing this. Happy

I have created a simple class to perform this Directory-related tasks, named "Folder".

Firstly, we need to include System.IO (for Directory class) & System.Security.AccessControl (for FileSystemRights & AccessControlType enums).

public static bool Exists(string folderPath)
{
return Directory.Exists(folderPath);
}

public static void Create(string folderPath)
{
Directory.CreateDirectory(folderPath);
}

public static void Delete(string folderPath)
{
Directory.Delete(folderPath, true);
}

public static void AddSecurity(string folderPath,
string userAccount,
FileSystemRights fileSystemRights,
AccessControlType controlType)
{
DirectoryInfo folderInfo = new DirectoryInfo(folderPath);

DirectorySecurity folderSecurity = folderInfo.GetAccessControl();

folderSecurity.AddAccessRule(
new FileSystemAccessRule(userAccount, fileSystemRights, controlType));

folderInfo.SetAccessControl(folderSecurity);

}

public static void RemoveSecurity(string folderPath,
string userAccount,
FileSystemRights fileSystemRights,
AccessControlType controlType)
{
DirectoryInfo folderInfo = new DirectoryInfo(folderPath);

DirectorySecurity folderSecurity = folderInfo.GetAccessControl();

folderSecurity.RemoveAccessRule(
new FileSystemAccessRule(userAccount, fileSystemRights, controlType));

folderInfo.SetAccessControl(folderSecurity);

}

public static string[] GetListOfFileSystemRights()
{
return Enum.GetNames(typeof(FileSystemRights));
}

public static string[] GetListOfAccessControlTypes()
{
return Enum.GetNames(typeof(AccessControlType));
}



Function: If the folder does not exist, create it and set security access.




if (Folder.Exists(folderPath) == false)
{
Folder.Create(folderPath);
Folder.AddSecurity(folderPath,"MY\\CHONGLK", FileSystemRights.Modify,AccessControlType.Allow);
}



 


To remove the security access for certain rights, use the RemoveSecurity method:



Folder.RemoveSecurity(folderPath,"MY\\CHONGLK", FileSystemRights.Modify,AccessControlType.Allow);



The last two functions is to allow users to bind the list of enum values to the UI control.




//List all FileSystemRights values in dropdownlist
systemRightsDropDownList.DataSource = Folder.GetListOfFileSystemRights();
systemRightsDropDownList.DataBind();

//List all AccessControlTypes values in dropdownlist
controlTypeDropDownList.DataSource = Folder.GetListOfAccessControlTypes();
controlTypeDropDownList.DataBind();



It's quite simple, but I didn't know these methods before this. Tongue At least, I learnt something new.

Friday, March 21, 2008

List out all enum values

I just found out the way to list out all the enum values. It's indeed very simple!

For example, I want to list out all the enum values of FileAccess.

string[] enumList = Enum.GetNames(typeof(FileAccess));
DropDownList1.DataSource = enumList;
DropDownList1.DataBind();



I also found out how to convert the string representation value to the enum value too.



FileAccess fAccess = (FileAccess)Enum.Parse(typeof(FileAccess), DropDownList1.SelectedValue);



that's it. Isn't it simple?

MCPD: Learning Plan for Exam 70-536

URL: http://learning.microsoft.com/manager/LearningPlanV2.aspx?resourceId=%7ba3e18fcd-60ed-489b-94d6-4c30e1bf9542%7d&clang=en-US

You may also sign in to Micrsoft Learning to look for any learning resources, including the learning plan. You also also track your learning here.

In this learning plan, there are recommended learning resources, where you can follow them step by step until you reach the stage of registering for the exam.
I plan to follow this learning plan to start my learning process for Exam 70-536, then I'll see what extra resources I need when time goes by.

MCPD: Preparation Guide for Exam 70-536

URL: http://www.microsoft.com/learning/exams/70-536.mspx

This will be my first paper:
Exam 70-536 [Microsoft .NET Framework 2.0 - Application Development Foundation]

From the link above, you'll find these information:
- Exam news
- Exam topics covered
- Audience profile
- Credit toward certification
- Code languages
- Prepartion tools and resources
- Skills measured

I guess the most important is the skills measured section. You'll be told in detailed what knowledge are required in order to take the exam. You can use the long list to measure your knowledge.

I just jot down the keywords for exam topics covered in this paper:
1) system types & collections
2) service processes, threading, application domains
3) embedding configuration, diagnostic, management, and installation features
4) serialization & I/O
5) security
6) interoperability, reflection, mailing funcitonality
7) globalization, drawing and text manipulation

MCPD: Exam Question Types

Information extracted from: http://www.microsoft.com/learning/mcpexams/policies/innovations.mspx

I've found this site when I was looking for the information regarding MCPD.
There are several types of exam questions. It may be good if we get ourselves familiar with these types:

1. Hot area questions
This kind of question asks you to indicate the correct answer by selecting one or more elements within a graphic.

2. Active screen questions
This kind of question asks you to configure a dialog box by changing one or more elements.

3. Drag-and-drop quetsions
This kind of question asks you to drag source objects to appropriate targets within a work area.

4. Build list and reorder questions
This kind of question asks you to indicate the correct answer by building an answer list.
In a build list and reorder question, you need to build a list by dragging the appropriate source objects to the answer list and then placing them in the correct order based on criteria defined in the question.

5. Create a tree questions
This kind of question asks you to create a tree structure.
You indicate the correct answer by dragging source nodes to the correct locations in the answer tree.
Nodes consist of text and a small icon.

6. Testlet exam format

7. Windows 2000 simulation questions
This kind of question asks you to indicate the correct answer by performing specific tasks such as configuring and installing network adapters or drivers, configuring and controlling access to files, and managing hardware devices. (This seems to be more applicable for System engineering exams)

You may download the MCP Exam Demos too, then you'll understand better what the aboved question types mean. It's quite fun to run through the exam demo. ^_^

MCP Test Demo
There is an "Instructions" button to tell you what type of question it is, and how you should respond. A "Calculator" button is provided too.

Wednesday, March 19, 2008

MCPD - Start the Journey

MCPD
I have been thinking of taking this certification - MCPD (Microsoft Certified Professional Developer) for quite long. Well, actually I have been thinking since MCSD (Microsoft Certified Solutions Developer), then it changed to MCAD (Microsoft Certified Application Developer). Finally, there came a new generation again.
Finally, I've made a move - we've bought several books yesterday.
Perhaps this time, I'm really going to pursue this cert, because the company is sponsoring. haha~~

My boss has been asking us to look for external courses, and I think pursuing MCPD is a good idea. We've calculated the price of the books we are going to purchase, altogether 7 books, for 3 papers, cost us RM1600. It'll be a burden for me to spend this amount of money just on the books only. As the courses are too expensive, say RM2400 for 3 day course, that is RM800 for a day, RM100 for an hour. We've decided to study by ourselves, and we'll also see if there are any useful or interesting courses, then we can subscribe for them too. Perhaps we'll go for those topic-oriented courses, instead of going for the certication ones.

I wish I can spend one hour per day to study on this. Perhaps reading the books, doing some research online, taking some sample tests. See how it goes.

The papers I'm required to take are as follow:
1) Exam 70-536: Microsoft .NET Framework 2.0 - Application Development Foundation
2) Exam 70-528: Microsoft .NET Framework 2.0 - Web-Based Client Development
3) Exam 70-547: Designing and Developing Web Applications by using Microsoft .NET Framework


My first paper will be Application Development Foundation. I need to go and check out any resources for this MCPD, and hope to know anyone who's also taking or already taken this cert. ^_^

More to find out soon...... I gotta keep myself motivated. haha~~

Reference:
* MCPD Official website

Monday, February 18, 2008

Set GridView Header Font Style in CSS

I have defined my GridView header style in CSS. Because I've set my GridView to be sortable, so the header texts will be links, and it'll follow the style of Links as defined.

I'd like to change the header text color to fit to header row color, and finally I've found the solution.

Define the CSS like this:

tr.OrangeGridViewHeader, 
tr.OrangeGridViewHeader a:visited,
tr.OrangeGridViewHeader a:link
{
background-color:#feaa66;
font-family:Verdana;
font-weight: bold;
color:#000;
text-decoration:none;
}

tr.OrangeGridViewHeader a:hover
{
background-color:#feaa66;
font-family:Verdana;
font-weight: bold;
color:#000;
text-decoration:underline;
}



 


Then set the HeaderStyle's CssClass to OrangeGridViewHeader. It's done! Happy

Tuesday, January 8, 2008

Formatting link style using CSS

If you do not define the link style, by default, the link will always be underlined.

We can use CSS to format the style.

There are 4 selectors for links:

a:link defines the style for normal unvisited links.
a:visited defines the style for visited links.
a:active defines the style for active links.
A link becomes active once you click on it.
a:hover defines the style for hovered links.
A link is hovered when the mouse moves over it.

These are some of the styles I use:

Solid underlined link
No underlined link
Dotted underlined link

 

I want my links to be underlined when they are at normal state, visited state and also active stated, but no underlined when mouse over it:

a:link, a:visited, a:active
{
color: #2666a6;
text-decoration:underline;
}

a:hover
{
color:#2666a6;
text-decoration: none;
}

If you want to have the dotted underlined links, you may declare it like this.


As there's no text-decoration as dotted underlined, so we make use of the bottom border.


a:link, a:visited, a:active
{
color: #2666a6;
text-decoration:none;
border-bottom:dotted 1px #2666a6;
}

a:hover
{
color:#2666a6;
text-decoration: none;
border-bottom:none;
}

Have fun!! Happy

 

References:

* EchoEcho.Com - Tutorial - CSS Links