Wednesday, December 21, 2005
ByVal or 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 asp.net 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!
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
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 ABC.aspx.bo, the bo extension stands for business object.
To achieve this, I can simply add a registry key here:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\8.0\Projects\{E24C65DC-7377-472B-9ABA-BC803B73C61A}\RelatedFiles\.aspx
That's this key:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\8.0\Projects\E24C65DC-7377-472B-9ABA-BC803B73C61A\RelatedFiles\.aspx\.bo
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.
Cheers!
Saturday, December 03, 2005
New IDE Features in Visual Studio 2005
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
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
If anyone of you have the answer, let me know.
Friday, September 16, 2005
Shadows a VB Field with CodeDOM
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
Description:
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.
regards,
choongseng
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
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.
regards,
choongseng
Wednesday, September 14, 2005
Convert a string to an enumerated (enum) value
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.
regards,
choongseng
SQL Server 2005 SMO Optimization
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.
regards,
choongseng
Monday, September 12, 2005
Generics In-depth
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 15seconds.com, it is really good! a short and nice summary with code samples of the indepth of generics!
regards,
choongseng
Monday, September 05, 2005
Most common mistake?
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) ...
Next
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) ...
Next
regards,
choongseng
Thursday, September 01, 2005
VS2005 Beta 2 -> RTM
http://msdn.microsoft.com/asp.net/beta2/beta2rtmchanges/default.aspx
MSDN Subscription rocket high price... Creative vs Apple
http://www.theserverside.net/cartoons/TalesFromTheServerSide.tss
the discussion: http://www.theserverside.net/discussions/thread.tss?thread_id=36145
Creative Claims Apple iPod Uses Its Newly Patented Technology
http://www.internetweek.com/showArticle.jhtml?articleId=170101940
Wednesday, August 10, 2005
Zipping in .NET
The SharpZipLib should be the one:
http://www.icsharpcode.net/OpenSource/SharpZipLib/Default.aspx
regards,
choongseng
Thursday, August 04, 2005
Using the Windows Media Player Control in a Web Page
And if this interest you, visit:
Using the Windows Media Player Control in a Web Page
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmplay10/mmp_sdk/usingtheplayercontrolinawebpage.asp
Monday, August 01, 2005
AJAX AutoCompleteTextBox
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
http://www.codeproject.com/aspnet/AJAXWasHere-Part3.asp
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!
regards,
choongseng
Thursday, July 28, 2005
Developing MSN plugins
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
http://www.devhood.com/tutorials/tutorial_details.aspx?tutorial_id=213
DotMSN - .NET Messenger libraray
http://www.xihsolutions.net/dotmsn/
sanx.org :: Tweaks for Windows XP, Windows Server 2003 and Windows Vista
http://www.sanx.org/tipShow.asp?index=276
regards,
choongseng
Wednesday, July 27, 2005
AJAX!
After meeting up with Shunjie and ZhongQiang this evening, I've got something from discussion, and that's the AJAX.net!
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 AJAX.net. 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:
http://ajax.schwarz-interactive.de/csharpsample/default.aspx
The JSON, javascript object notation:
http://www.crockford.com/JSON/
Instead of using XML serialization, there's already this JSON thing which gives better performance than XML serialization. And AJAX.net had used that for serialization.
Isn't that cool? Well, the hope for my project to deliver ontime is getting brighter.. Thanks God!
regards,
choongseng
Monday, July 25, 2005
jsTimer on the way...
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.
regards,
choongseng
Saturday, July 23, 2005
Microsoft Access SQL Query 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).
regards,
choongseng
Friday, July 22, 2005
Office 2000 PIAs??
Subsequently, I've consulted Dr.Google and he refer me to Mr.MSDN:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dno2k3ta/html/OfficePrimaryInteropAssembliesFAQ.asp
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.
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?
regards,
choongseng
Releasing of unmanaged code (COM) from managed code (.NET) calls
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:
http://support.microsoft.com/default.aspx?scid=kb;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
Sarissa to the Rescue
http://www.xml.com/pub/a/2005/02/23/sarissa.html
sarissa
http://sarissa.sourceforge.net/doc/
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.
regards,
choongseng
Wednesday, July 20, 2005
Regular Expressions
http://www.regexp.com/
http://www.regular-expression.info/
4GuysFromRolla - Regular Expressions
http://www.4guysfromrolla.com/webtech/RegularExpressions.shtml
Greg Reinacker's Weblog
Nested Constructs in Regular Expressions (using .NET)
http://www.rassoc.com/gregr/weblog/archive.aspx?post=590
Using a Regular Expression to Match HTML
http://haacked.com/archive/2004/10/25/1471.aspx
Tools:
Dela's Ramblings
Regular Expression Library Builder
http://briandela.com/blog/archive/2005/06/03/284.aspx
XML Validation and Parsing with Regular Expression
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:
http://www.weitz.de/regex-coach/
For references on regular expression:
http://www.regular-expression.info/
regards,
choongseng
Tuesday, July 19, 2005
Writing Object Oriented Javascript Part 1
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....
http://www.codeproject.com/aspnet/JsOOP1.asp
Very good article! I didn't know that javascript is indeed that powerful...
regards,
choongseng
VS 2005 Beta 2 Bug
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.
http://lab.msdn.microsoft.com/productfeedback/viewfeedback.aspx?feedbackid=da563451-b319-4984-a0fe-fe4dbdd68675
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
--> 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)
xmlWriter.Close()
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:
http://www.tkachenko.com/blog/archives/000246.html
New MCP Program
http://www.mcpmag.com/news/article.asp?EditorialsID=821
Tuesday, July 05, 2005
Microsoft Windows Desktop Search
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!
regards,
choongseng
Thursday, June 02, 2005
VS 2005 Beta 2 Bug
Just reported a bug on VS 2005 Beta somedays back:
VS IDE missed the WebResourceAttribute signature with PerformSubstitution
http://lab.msdn.microsoft.com/productfeedback/viewfeedback.aspx?feedbackid=bfbb9af7-6357-49dc-9ae5-83fcf3f4cf7e
regards,
choongseng
Saturday, May 28, 2005
Developing Software
Friday, May 27, 2005
Migrationg from VS Beta 1 to Beta 2
If you are concern on what changes are needed, it can be get from http://www.asp.net/whidbey
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
CompileWith=
Replace with: CodeFile=
ClassName=
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)
regards,
choongseng