Wednesday, December 21, 2005

ByVal or ByRef

When to you ByVal and when to use ByRef?
This is a very basic (fundamental) question that asked by newbies, and a simple answer would be ByVal simply duplicate the variable (create a new identical one) and give to the function you passed to, that means it is two different variable which whatever changes made in that function will not reflect in your original variable. And ByRef simple do the other way by passing a Reference of the original variable so effectively it is the same variable which changes made will be shown in the original variable.

But there cames the idea of Value Type and Reference Type, this article demonstrate the idea.

Now, while I'm looking into my weird problem with my DAL, which I made lots of ByRef for ReferenceType, I actually wanted to know whether there's any implication here, where it could be that everytime a call to a ByRef, it allocates a pointer on a pointer array (or some kind of table) and it happens that the pointer array strinks during garbage collection and some weird things happened?

If you have any idea, drop me a note please!

Wednesday, December 14, 2005

SkyPE 2.0 Beta is out!

SkyPE 2.0 beta with webcam support it out!

Since then my laptop IIS has been working and sometimes stops and can't startup and finally I've found the problem by looking at the netstat. SkyPE binds to my http port (80) and thus there goes my IIS, can't be up.

If you got similiar problem, you'll know why.. .just signout and exit your SkyPE and startup your IIS first.

Tuesday, December 06, 2005

Visual Studio Extensibility - nested file within a project

Trying to make my development life easier, I've made a Code Generator with CodeDOM.
But sooner after that, I've a problem in maintaining the generated codes, in the sense that, whenever, there's some new changes in the source schema, I've to recompile the thing all over again, and it takes... at least 2 digits of seconds.

Thus, my journey of VS Extensibility started...

The very first thing that wanted to find out about, which I didn't seems to see related post (googled) is this:

For my VB.NET project, usually there's .aspx and .aspx.vb which is nested together.
But I've a class which I generate for each form (a form binder), which I wanted to it to nest together under the .aspx file.
After some research and a few hours of searching the registry, I've got it!

Say, I wanted to put my generated code as, the bo extension stands for business object.

To achieve this, I can simply add a registry key here:

That's this key:

I'm not sure the GUID for all installation of VS2005 is the same or not, but you can do a search for it in your registry.

The particular project (GUID E24C65DC-7377-472B-9ABA-BC803B73C61A) is simply a webproj, and that's how it came about it.

The next thing that I wanted to do is to make it such that the compiler will compile my .bo file as if it is a .vb file, so to say, make it a Partial Class of the main aspx page class.

If you have any idea or suggestion, do let me know.


Saturday, December 03, 2005

New IDE Features in Visual Studio 2005

This article from c# corner does give a very nice summary of some of the new features in VS2005.

I was writing a AddIn for visual studio and it looks like that I doesn't need to write a shim for that any more!

Don't know what a shim is? check it out here.

Thursday, December 01, 2005

VistaDB 2.1 database for .NET has been released

VistaDB 2.1 database for .NET has been released
This 2.1 update includes over 60 improvements, including new support for .NET 2.0 and Visual Studio 2005. VistaDB is a small-footprint, embedded SQL database alternative to Jet/Access, MSDE and SQL Server Express 2005 that enables developers to build .NET 1.1 and .NET 2.0 applications. Features SQL-92 support, small 500KB embedded footprint, free 2-User VistaDB Server for remote TCP/IP data access, royalty free distribution for both embedded and server, Copy 'n Go! deployment, managed ADO.NET Provider, data management and data migration tools. Free trial is available for download.
- Learn more about VistaDB
- Repost this to your blog and receive a FREE copy of VistaDB 2.1!

Friday, September 23, 2005

CodeDOM Immediate IF

I've hard time using CodeDOM, and I think I'm half "expert" in CodeDOM after many weeks working on it. I've been searching around to do a IIF using CodeDOM, but no luck.

If anyone of you have the answer, let me know.

Friday, September 16, 2005

Shadows a VB Field with CodeDOM

Follow up on my post for help on sgdotnet, I'll post my findings here as well to share with all.

I've got myself the answer from the book "Applied Microsoft .NET framework programming", a good book to read on the foundamentals of .NET framework, at page 176, says:

CLR Term: Newslot
C# Term: new
VB Term: Shadows
Method should not override a virtual method defined by its base type; the method hides the inherited method. Applies only to virtual methods.

So to say, my code should look like this:

Dim spPreExecuteEvent As New CodeMemberEvent
spPreExecuteEvent.Attributes = MemberAttributes.Public Or MemberAttributes.[New]

However, after the CodeDom compile unit generate the code out, I still didn't find my Shadows keyword on the line. Basically, there's an event from the base class that I want this generated class to shadows on, and upon the generation, the codes appear with warning in visual studio saying that a shadows is recommended there.

Anyway, the code still works, but just doesn't look that nice, it isn't perfect!

Let me know if you have any light on this.


ps: it takes me one whole day to find this thing out, now I know how important search technology is, while Google is still the best, here comes the problem of how to search, what keyword to use, etc. If Google had indexed that book, I would have found it 20 hours ago!

Thursday, September 15, 2005

Microsoft Windows Workflow Foundation

Since the beginning of my company's project, we've in mind to build work flow into the system. We've review a few workflow system vendors and it just doesn't seems to suit us as it would require us much customization work and with limitation.

I believe the market for workflow applications is increasing and it does have a direct impact on the efficiency of a business. That would tells why Microsoft is coming into the stage now.

To be released together with WinFX, the Microsoft Windows Workflow Foundation is now available for preview as well as tryout.


Wednesday, September 14, 2005

Convert a string to an enumerated (enum) value

This problem had been prompting up now and then, and finally I got the solution, which I know definately there is one!

Credits to this site

public enum DataState as Integer
Active = 1
Deleted = 2
Archived = 3

It is very easy and good to use enum, as there's intellisense goes with it and nothing will go wrong. But, how about getting the value mapping back to it's enum so that you got a sure run and error free code?

To get back the enum from the value, this is how you'll go with it:

CType([Enum].Parse(GetType(DataState), "Deleted", True), DataState)

*Need to enclose Enum with "[]" to indicate that you are refering to a class instead of the reserved word "enum" which used to declare an enumeration.


SQL Server 2005 SMO Optimization

While digging the Books Online trying to see what is going on as my SMO program is super slow, Dr.Google lead me to this site.

There's some optimization that you can do to tell the SMO class to retrieve some initial properties of a instance of a SMO class. For convinient, this is a cut-n-paste from the site.

Server svr = new Server();

Database db = svr.Databases["AdventureWorks"];
svr.SetDefaultInitFields(typeof(Table), "CreateDate");
foreach (Table t in db.Tables)
Console.WriteLine(t.Schema + "." + t.Name + " " + t.CreateDate);

By adding this line:
svr.SetDefaultInitFields(typeof(Table), "CreateDate");

It tells the SQL SMO class to retrieve only the specified property (or collection of properties), so that you won't be bloated with lots of SQL statement firing which really slow down the SMO apps.

Well, after all, as the application that I'm doing had to read each table and its columns for its datatypes, thru the Profiler, I can actually see that there's 1 SQL statement being fired for each field in the database, so to say, if I've 120 tables which each tables have more than 8 fields in average, I've to wait for 120*80=960 SQL statements to be fired to get the schema of my database using SMO, that I tell you that took me more than 30 minutes!!

So how? I gave up SMO for this particular app.

What I did finally is to create a Virtual SMO Objects, that means, I create those object but didn't commit it to the database (without firing the .Create()). And using the TSQL querying the system tables, I retrieve all my schema at one go in 1 SQL for each table and fill up the SMO objects. And subsequently, send the SMO objects to my SMO apps. Cool! it works really fast by then.


Monday, September 12, 2005

Generics In-depth

While going thru my code generator for my DAL, I'm looking into optimizing my codes using generics and inheritance so that I can emit a light weight business object with only public variables and associate it with a generic class to make up my DAL.

And while I think generics is just as simple as a "on-the-fly" declaration of type, I'm totally wrong! there's generic method, sub, etc... voila!

And this is the site on, it is really good! a short and nice summary with code samples of the indepth of generics!


Monday, September 05, 2005

Most common mistake?

Well well, I encountered this before and last friday I made it again!

The mistake is in the for-to-next loop, I've made a loop to loop thru the array with index.

For i as Integer = MyArray.Length to 0
... do something here with MyArray(i) ...

can you see the mistake?

if you can't, you'll probably spend sometime wondering about what's happending and only until you set breakpoints and debug it, you'll found that default the compiler takes it as "Step 1"!

So the fix is as such:
For i as Integer = MyArray.Length to 0 Step -1
... do something here with MyArray(i) ...


Thursday, September 01, 2005

VS2005 Beta 2 -> RTM

Major Changes for Visual Web Developer 2005 and ASP.NET 2.0 from Whidbey Beta 2 to RTM

MSDN Subscription rocket high price... Creative vs Apple

Humor: MSDN Subscription Pricing - Decisions, Decisions
the discussion:

Creative Claims Apple iPod Uses Its Newly Patented Technology

Wednesday, August 10, 2005

Zipping in .NET

Looking for compression in .NET for ZIP?

The SharpZipLib should be the one:


Thursday, August 04, 2005

Using the Windows Media Player Control in a Web Page

Sometimes you may want to add some video on to your webpage, just like how some presentation was done.

And if this interest you, visit:
Using the Windows Media Player Control in a Web Page

Monday, August 01, 2005

AJAX AutoCompleteTextBox

It is yet another day, which I've wanted so much to build such a control. And I was trying hard for the weekends and past one week on drilling on how to make extensive use of the AJAX together with the AutoCompleteTexBox that I've got from CodeProject sometimes back which merely a client side javascripts.

And looking into reducing my effort, the first thing in the morning today, is to, again, ask Dr.Google whether somebody had already invented the wheel which I probably can ride one. And voila, I've got this from CodeProject:

AJAX WAS Here - Part 3 : Auto Complete TextBox

Well, while this control is useful, it is not generic enough for my purpose. Thus, I've to get going on and build mine now!


Thursday, July 28, 2005

Developing MSN plugins

While thinking of what features to put on to Stickies.NET 2005, the idea of sending Stickies over MSN Messenger came to mind and I think it would be great.

So the first thing I've tried to figure out is, getting the SDK for Messenger. And after a few hours of findings, I figured out that all the forums and articles are talking about a class called "MessengerAPI", which I tried to get advice from Dr.Google with "MessengerAPI download", I've no luck.

And after going thru some frustration, I've got some light from one of the forum post, which uses RCW to the unmanaged messenger API. What a big mistake I've made/overlooked! That's probably because I'm not a VB6 programmer ever.

And finally I've managed to get it working to hook on some events of the MSN Messenger. However, out of all the events, there isn't an event that will raise when message text was received and sent. I guess that probably to prevent all sorts of MSN bots to flood the network.

So, my research went on and I've explore to another new arena that I wasn't familiar with before and that's the unmanged APIs. Apparently, you have to deal with unmanged Win32 API, in sending messages to the Window (and to its TextBox Control). It was painful as I've to do more reading on this to get it working, and so far my program doesn't work, which I guess I've got the wrong control ID for the textbox and button.

There are some the useful bookmarks that I've been reading over the night, until 1am!

COM Interop: Messenger Auto-Responder

DotMSN - .NET Messenger libraray :: Tweaks for Windows XP, Windows Server 2003 and Windows Vista


Wednesday, July 27, 2005


That's cool!

After meeting up with Shunjie and ZhongQiang this evening, I've got something from discussion, and that's the!

The efforts that I've invested in the past 1 week had almost going to drain as what I'm trying to come up with is an object model on the client-side javascript. Which I've been creating abstract "classes" on the client-side javascript and further devising the XMLSerialization functions for objects. And this took me few days to code and debug my javascript and regular expressions...

After all, if I ever success, that would be the And voila! it is there, schwarz had did all the cool stuff for us!

Here is some of the links that I've started off:

The JSON, javascript object notation:

Instead of using XML serialization, there's already this JSON thing which gives better performance than XML serialization. And had used that for serialization.

Isn't that cool? Well, the hope for my project to deliver ontime is getting brighter.. Thanks God!


Monday, July 25, 2005

jsTimer on the way...

I've spent about 2 days, which total up to a few hours to create a javascript based timer.

There's some simple function which enable user to start and stop the timer and also record each lap timings.

I was about to release and publish it (well, it is a trivial script after all), but got no time to go thru and write some license and disclaimers on GPL.


Saturday, July 23, 2005

Microsoft Access SQL Query Bug

I'm getting crazy, found that the TOP # in the Microsoft Access Database is having a bug!

While I'm trying to do this for one access database, it gives me 18 records!!

SELECT TOP 10 Right([FromYear],4) AS FromYear, Right([ToYear],4) AS ToYear, 'spm' + mid([Reference No],1,4) + '-' + mid([Reference No],5,2) + '-' + mid([Reference No],7,2) + '-' + mid([Reference No],9,3) + '.jpg' AS PicRefNo, [Reference No] AS AccessionNo, [Item] FROM tblStamps WHERE 1=1 AND [Description] LIKE '%king%' AND [Reference No] NOT IN (SELECT TOP 10 [Reference No] FROM tblStamps WHERE 1=1 AND [Description] LIKE '%king%' ORDER BY FromYear, ToYear ) ORDER BY FromYear, ToYear

I believe it is the ORDER BY which confused up the TOP, and both of them can't be used together (not compatible).


Friday, July 22, 2005

Office 2000 PIAs??

We've a problem in office today, while I was encouraging them to use office interop, it turned up that the package that ship w/o PIAs works on Office 2000, XP, 2003 and the one the w/o PIAs, works only on Office 2003.

Subsequently, I've consulted Dr.Google and he refer me to Mr.MSDN:

Quote from the address:

Using the Office XP PIAs and the Office 2003 PIAs

PIAs are version specific, so you should use the same version of the PIAs as the application version. For example, if you want to migrate your Microsoft Office XP managed code solution to Microsoft Office 2003, you should recompile the Office XP managed code solution with Office 2003 PIAs.

You should also have two different setup packages—one for Office XP and another for Office 2003—if you intend for the same solution to work in both Office XP and Office 2003. Deployment of PIAs for Office XP is very different from that for Office 2003. For further information about these differences, see the ReadMe file included in the Office XP PIAs download.

Super Angry [8o|] Wonder if anyone have similiar experience with building apps that writes to office documents?
Just wonder if there's Office 2000 interop or shall I conclude that working w/o interop will yield the best compability?


Releasing of unmanaged code (COM) from managed code (.NET) calls

While most of the complicated components are still implemented in unmanged code (it will take some long time for us to have a entire managed environment though), we uses Runtime Callable Wrapper (RCW) to wrap up COM objects to be callable from managed code.

However, these has to be used carefully, as the garbage collection won't automatically clear and release the memory used by the COM objects. This problem arise when my colleague asking me about how to solve it, as she observed that there's many EXCEL.EXE running in the taskbar after she run her program which creates excel spreadsheet. While I've read about it, but have never get a chance to use it, thanks again to Dr.Google which always faithfully give me the answers within seconds.

Releasing of unmanaged code (COM) from managed code (.NET) calls:;en-us;317109

Below are quoted from the site for easy reference:

To make sure that the Office application quits, make sure that your automation code meets the following criteria:
• Declare each object as a new variable. For example, change the following line of code

oBook = oExcel.Workbooks.Add()

to the following:

dim oBooks as Excel.Workbooks
oBooks = oExcel.Workbooks
oBook = oBooks.Add()

• Use System.Runtime.InteropServices.Marshal.ReleaseComObject when you have finished using an object. This decrements the reference count of the RCW.
• To release the reference to the variable, set the variable equal to Nothing or Null.
• Use the Quit method of the Office application object to tell the server to shut down.

Client-side XML

Wow!... finally I got the keyword and found this crazy API:

Sarissa to the Rescue


I've been cracking my head for 2 days to came up with a XML parse with regular expression. Which I've came up with it, but it is limited and have rooms to improve.


Wednesday, July 20, 2005

Regular Expressions


4GuysFromRolla - Regular Expressions

Greg Reinacker's Weblog
Nested Constructs in Regular Expressions (using .NET)

Using a Regular Expression to Match HTML


Dela's Ramblings
Regular Expression Library Builder

XML Validation and Parsing with Regular Expression

Anyone have any idea on regular expression to validate XML and parse it?
I've been trying very hard today to build a XML parser myself using javascript, and just didn't manage to figure out how to do about it using regular expression.

Along the way, I've found some cool tools for regular expression:

For references on regular expression:


Tuesday, July 19, 2005

Writing Object Oriented Javascript Part 1

Discover this article from CodeProject:

ASP.NET and Visual Studio 7.0 are making important contributions to the improvement of the web development experience. Unfortunately, there is also a tendency created among developers to limit their interaction with JavaScript. Clearly JavaScript is valuable for adding client-side functionality to web pages. However ASP.NET programming models suggest that developers produce page layout while emitting client-side JavaScript from ASP.NET controls. As a consequence, this model tends to limit JavaScript to procedural adjuncts. This is rather unfortunate because it severely limits the power of an object-oriented scripting language that developers can use to write rich and reusable client-side components....

Very good article! I didn't know that javascript is indeed that powerful...


VS 2005 Beta 2 Bug

Reported one more bug today:

Cross page posting will not work for DropDownList and further more as you investigate on, you'll discover that the cross post back actually process the previous page, which is not desired.

XML Serialization in .NET

Tired of writing XML Document and tags? and even more tired when you have to code exactly the reverse thing when reading back from XML document?

The solution is to make use of the XML Serialization in .NET!

This example shall give you an overall idea of the XML serialization function of .NET.

--> No more codes for XML Writing
--> No more codes for XML Reading
--> 1000% higher productivity in writing codes

The codes sample is a prototype example for my company, which will be used as a file format eventually for data exchange.

Imports System.Xml.Serialization
Public Class PSF_XMLSerializer_PrototypeForm
Private Sub PSF_XMLSerializer_PrototypeForm_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim newPSF As New PortStatusFile
newPSF.FileVersion = "123"
newPSF.RevisionDate = "111"
newPSF.TS.Vessel_Code = "ABC"
newPSF.TS.Vessel_Oper = "XCL"
newPSF.CS.SMD.Add(New SMDetails("One"))
newPSF.CS.SMD.Add(New SMDetails("Two"))
newPSF.CS.SMD.Add(New SMDetails("Three"))

Dim xmlsel As New XmlSerializer(GetType(PortStatusFile))
Dim xmlWriter As New System.IO.StreamWriter("C:\test.txt")
xmlsel.Serialize(xmlWriter, newPSF)
Dim xmlReader As New System.IO.StreamReader("C:\test.txt")
Dim anotherPSF As PortStatusFile = CType(xmlsel.Deserialize(xmlReader), PortStatusFile)
anotherPSF.RevisionDate = "9999"
anotherPSF.TS.Line = "SEA"

Dim xmlW2 As New System.IO.StreamWriter("C:\test2.txt")
xmlsel.Serialize(xmlW2, anotherPSF)
End Sub
End Class

<XmlRootAttribute("PSF", Namespace:="Seacon.eBiz", IsNullable:=False)> _
Public Class PortStatusFile
<XmlAttributeAttribute("version")> _
Public FileVersion As String
<XmlAttributeAttribute("Rev_Date")> _
Public RevisionDate As String
<XmlAttributeAttribute("SID")> _
Public SID As String
<XmlAttributeAttribute("format_datetime")> _
Private DateTimeFormat As String
Public TS As TerminalDetails
Public CS As CargoDetails
Public Sub New()
Me.TS = New TerminalDetails
Me.CS = New CargoDetails
End Sub
End Class
<XmlRoot("TDR", IsNullable:=False)> _
Public Class TerminalDetails
Public Vessel_Code As String
Public Vessel_Name As String
Public Vessel_Oper As String
Public Voyage As String
Public Leg As String
Public Line As String
Public Port_Code As String
End Class

<XmlRoot("SM", IsNullable:=False)> _
Public Class CargoDetails

'Multiple SMD
<XmlArrayItem(ElementName:="SMD_ITEM", _
IsNullable:=True, _
Type:=GetType(SMDetails)), _
XmlArray(ElementName:="SMD")> _
Public SMD As ArrayList
Public Sub New()
Me.SMD = New ArrayList
End Sub
End Class
<XmlRoot("SMD", IsNullable:=False)> _
Public Class SMDetails
Public Cntr_Num As String
Public Sub New()
End Sub
Public Sub New(ByVal cntrNum As String)
Me.Cntr_Num = cntrNum
End Sub
End Class

If you wanted to add stylesheet to your serialized object, check this out:

New MCP Program

Happen to see this from, new MCP program:

Tuesday, July 05, 2005

Microsoft Windows Desktop Search

This is really cool...

I've downloaded and installed the MS Desktop Search a few days ago, and indexed my inbox and my documents folder. Wow.. it is as good as google's one with more customizable settings -- you can specify which folders you want to index!

Further more, it supports various file types by Add-ins, which means the parsing of propriety file types is possible as long as the vendor developer the specific Add-in for the file type. Very cool isn't it?

Today, it had really helped me tremendously!! I was searching for a excel file which I've created about few months back. I was searching for a worksheet inside the excel, but I don't know which excel file!!... after an hour, I gave up. So, with my last hope, I enable indexing on my data drive and woalla~ after 30mins of indexing, I search with the keyword and instantly that's my file!!

cool? try it out yourselves!


Thursday, June 02, 2005

VS 2005 Beta 2 Bug

I hate it when there's bug...

Just reported a bug on VS 2005 Beta somedays back:
VS IDE missed the WebResourceAttribute signature with PerformSubstitution


Saturday, May 28, 2005

Developing Software

This blog is devoted to post some of my experience and findings on developing software pieces.

Friday, May 27, 2005

Migrationg from VS Beta 1 to Beta 2

Today, we've migrated all developers' VS from Beta 1 to Beta 2!

If you are concern on what changes are needed, it can be get from

I've made some regular expression to do some of the common replacement for ASP.NET:

Partial Class {([A-Za-z_]+)}\n([:b\n]+)~(Inherits){[^:b\n]}
Replace with: Partial Class \1 \n Inherits System.Web.UI.Page\n \2

Replace with: CodeFile=

Replace with: Inherits=

These are to be executed using Quick Replace in VS IDE.
(Do not use "Replace in Files", apparently, there are some bugs with regular expression substitution)