Archive for March 17th, 2008

How to Sort a Multi-Dimensional Array?

Monday, March 17th, 2008

The reason for handling multiple dimensions is simply that it happens many times those are the arrays we have and have to sort.

arEvents(0, 0) = 1
arEvents(1, 0) = “01-12-2004″
arEvents(2, 0) = “Event #1″
arEvents(0, 0) = 2
arEvents(1, 0) = “10-16-2004″
arEvents(2, 0) = “Event #2″
arEvents(0, 0) = 3
arEvents(1, 0) = “02-13-2004″
arEvents(2, 0) = “Event #3″

It could be sorted by simply handing it off to the arraySort() function, specifying which dimension to sort it by (in this case the date).
ArEvents = arraySort( arEvents, 1, true )

And then here’s the function that’s responsible for it all.

function arraySort( arToSort, sortBy, compareDates )
Dim c, d, e, smallestValue, smallestIndex, tempValue
For c = 0 To uBound( arToSort, 2 ) - 1
smallestValue = arToSort( sortBy, c )
smallestIndex = c

What’s happening here is that we’re going through the array one item at a time. With each item, we’ll use the sortBy parameter, find the current item, and set the smallest value and index placeholders to the current item. Then we take these items, or placeholders, and compare them to EACH item in the array and look for a smaller value.
For d = c + 1 To uBound( arToSort, 2 )
if not compareDates then

So if the compareDates flag has been set to false, the function will try to compare the values as strings using the inbuilt strComp() function of ASP. Now, don’t be too worried about numbers, they will be handled perfectly with this function as well. When we use the strComp() function, it will produce a -1 if the compared string (the first parameter) is smaller, a zero if they’re equal, and a 1 if it’s larger/greater. In this case, as we’re sorting depending on smaller values, we would then set the placeholders to this value and index, if we find that it is indeed smaller. Now you’re probably beginning to see where modifications could be made to sort in a descending order.

if strComp( arToSort( sortBy, d ), smallestValue ) < 0 Then
smallestValue = arToSort( sortBy, d )
smallestIndex = d
End if

So here we’ve got the code to handle dates, if the compareDates flag has been set to true. Of course we first check and ensure that we truly are dealing with dates. If not, we recurse, and come back through just comparing strings.

Posted by Mahesh ( Tryangled )

what is the jit? what is the type of jit and purpose of it?

Monday, March 17th, 2008

JIT IS JUST IN TIME COMPILER

Pre-JIT
Compiles entire code into native code at one stretch
Ecno-JIT
Compiles code part by part freeing when required
Normal JIT
Compiles only that part of code when called and places in cache.

Posted by Mahesh ( Tryangled )

How to ASP Changing, Date, Time, and Currency Format?

Monday, March 17th, 2008

To Change Date,Time and currency in international format using ASP.

If you can run a global.asa file on your server then place the following into your global.asa file to change the locale settings throughout your site: -

‘ When a session starts on the server the following code will be run
Sub Session_OnStart
‘Set the server locale
Session.LCID = 2057
End Sub

If you can not use a global.asa file, place following into the top of each ASP page you wish to change the locale settings on: -

<%
‘Set the server locale
Session.LCID = 2057
%>

The LCID number above, 2057, will set the locale settings on the server to United Kingdom English, to change the locale to your own country you will need to use the LCID Chart at the bottom of this page to find your own locale ID number and then replace 2057 with your own LCID number.

Please note that this will only change the format the dates, times, and currencies are shown in and will not move dates and times to another time zone. eg. mm/dd/yyyy to dd/mm/yyyy.

Posted by Mahesh ( Tryangled )

How do I select a specific item in a DropDownList?

Monday, March 17th, 2008

With a dropdown list - you can dynamically select items in the list with a sort of ‘built-in’ find routine.
To select a certain item, based on the Value of the item in the list:
DropDownList.SelectedIndex = DropDownList.Items.IndexOf(DropDownList.Items.FindByValue(YourValueHere))
To select a certain item, based on the Text of the item in the list:
DropDownList.SelectedIndex = DropDownList.Items.IndexOf(DropDownList.Items.FindByText(”YourTextHere”))
OR - you can do it this way:
DropDownList.Items.FindByText(”TextYouAreLookingFor”).Selected = true
or, using the value of the item
DropDownList.Items.FindByValue(”ValueYouAreLookingFor”).Selected = true

Posted by Mahesh ( Tryangled )

How can I limit a textbox to ONLY numeric characters?

Monday, March 17th, 2008

If you haven’t heard of the built in ASP.Net Validator controls, it’s time to learn. There are several, but, for this case, you would use a Regular Expression Validator. The Regular Expression for making sure only numeric data is inserted into the textbox is:

^([0-9]*|\d*\d{1}?\d*)$

You’d use it in a Regular Expression Validator, in conjunction with an ASP.Net Textbox, like this:

<asp:TextBox id=”txtNumber” Runat=”server” />
<asp:RegularExpressionValidator ID=”vldNumber”         ControlToValidate=”txtNumber” Display=”Dynamic”     ErrorMessage=”Not a number” ValidationExpression=”(^([0-9]*|\d*\d{1}?\d*)$)” Runat=”server”>
</asp:RegularExpressionValidator>

Posted by Mahesh ( Tryangled )

How to get started using Remote Debugging?

Monday, March 17th, 2008

Getting remote ASP.NET sourcecode debugging to work between a server and a client using Visual Studio.NET can sometime give you headaches.
Here’s a few ides on how to get that to work:
On the server enable COM internet services and Distributed COM. You do that by doing the following:

1. Open the control panel
2. Open Administrative Tools
3. Doubleclick on the Component Services to open the Component Services Microsoft             Management Console (MMC).
4. DoubleClcik on Component Services
5. DoubleClcik on “Computers”
6. Right Click on the “My Computer” and select properties
7. Click on the Default Properties tab
8. Make sure both the Enable Distributed COM and Enable COM Internet Services are             checked
9. Press Apply and restart your computer

For computers without a domain server, you should make sure that both the server and the local client has the same username and password in the user-database. If you use the user “Administrator” on the client, make sure that is available on the server and that they have the same password.

Make sure the user on the server is a member of the debugger group.

Set full disk/file access for this user to the \WINNT\Microsoft.NET and to the path where the files you try to debug is located.

Do not reference the server from the client using IP Addresses, use the server name instead , like “LocalServer”. IP Addresses seems to be less trusted.

Make sure ASP.NET debugging is enabled in your .NET project properties.

Posted by Mahesh ( Tryangled )

How to open an MS Excel application on the client?

Monday, March 17th, 2008

The example shows how to open an MS Office Excel application on the client. It can be useful when dealing with lots of documents in a proprietary format that the users want to view or edit but the ISP of the website may not allow to run the specific application on their server.

Normally clicking on a link such as <a href=”try.xls”>An Excel document[/b]</a> the browser will try to open and display the file in the application associated with the file type in the href attribute.

However, if you wish to manipulate this programatically or want to do more with the file’s content eg. editing or saving (will be shown in further examples) then you can open an application as in the examples below.

In this case JavaScript or VBScript can be embedded in the ASP page that will run on the client.

JavaScript example:

<script language=”javascript” type=”text/javascript”>
function runApp() {
var appExcel = new ActiveXObject(”Excel.Application”);
appExcel.Visible = true; }
</script>

Use the new ActiveXObject command to create a new application object then set its visibility property to true.

VBScript example:

<script language=”vbscript” type=”text/vbscript”>
Sub runApp()
Set appExcel = CreateObject(”Excel.Application”)
appExcel.Visible = True
End Sub
</script>

Use the CreateObject command to create a new application object then set its visibility property to true.

Posted by Mahesh ( Tryangled )

Active Server Pages (ASP) Access Database Errors

Monday, March 17th, 2008

1.Could not find file Error
Microsoft JET Database Engine (0×80004005)
Could not find file ‘C:\Inetpub\wwwroot\databaseName.mdb’.

This error is more or less what it says, the database file can not be found. This usually occurs if the path to the database is incorrect.
You need to check that the path to the database is correct (You must use the physical path on the server to the database and not a virtual path).

2. Could not use ‘(unknown)’; file already in use
Microsoft OLE DB Provider for ODBC Drivers error ‘80004005′
[Microsoft][ODBC Microsoft Access Driver] Could not use ‘(unknown)’; file already in use.

This is a bit of an odd error that I have never received myself but have been asked about on number of occasions. It usually means that either incorrect permissions are set on the server or the incorrect version of MDAC (Microsoft Data Access Components installed on the server or the version is not correctly installed). You need to ensure the ODBC version you have is 4 or greater.

Another reason for this error is that you have the database already open in MS Access or another program, if this is the case shut down the other program you have the Access database open in.

Posted by Mahesh ( Tryangled )

How to setting up the correct Permission on the IIS Server?

Monday, March 17th, 2008

If you are using an ASP application, or writing an ASP application, that requires that you write data to a database or a text file then you will need to check and if necessary change the permissions on the server so that you have write as well as read permissions on the directory, and database or text file, you wish to write too.

To check or change the permissions on the server go to Windows Explorer and do the following (for NT and Win 2K users only using NTFS file system, Win XP Pro users see note at bottom): -

1. Right click on the directory containing the database or text file.

2. Click on ‘Properties’.

3. Choose the ‘Security’ tab form the dialog box window.

4. Uncheck ‘Allow inheritable permissions from parent to propagate to this object’, from the bottom of the dialog box.

5. Next, click on the ‘Add’ button at the top left of the window.

7. Next click on the ‘Add’ button in the middle left of the dialog box. You should then see ‘MyComputer\IUSER_MyComputer’ appear in the box in the bottom half of the dialog box. Again where ‘MyComputer’ is will be the name of your computer.

9. Now click on the ‘OK’ button at the bottom right of the ‘Select Users or Groups’ dialog box.

10. You should now be back at the ‘Security Properties’ dialog box where the top box should now contain the ‘Internet Guest Account (MyComputer\IUSER_MyComputer)’.

11. Highlight the ‘Internet Guest Account (MyComputer\IUSER_MyComputer)’ by clicking on it in the top box.

12. Select ‘Read’ and ‘Write’ permissions for this account by checking the boxes at the bottom of the window (If you are not to worried about security you could check all the boxes to make sure that you have no problems with permissions).

13. Next repeat all the steps above on the database or text file itself, to make sure the database or text file also has the correct permissions.

Posted by Mahesh ( Tryangled )