Tuesday, November 22, 2005
This has come up several times over the years during my programming tasks when I have tried to automatically generate a filename based on some collection of data. It seems a good time to document this relatively simple question for my future reference as well as yours.
The keyboard characters that cannot be used in a Windows XP filename are:
Pipe (vertical bar)
\ Back slash
/ Forward slash
< Less Than
> Greater Than
? Question mark
Hope that helps!
Thursday, November 17, 2005
Note that it is a good investment of your time to go into the Visual Basic 6 source code, make sure that you have the "Option Explicit" statement as the first line of code in each form and module, and then make the needed changes to get a good compile with the correct functionality. This pre-conversion step can significantly reduce the manual changes needed to your code once it is Visual Basic.Net.
Since Visual Basic.Net is a strongly-typed language, any variables in the Visual Basic 6 that are not explicitly declared will be defined as type "Object" in the Visual Basic.Net code and will require type conversion statements to be written manually at locations where they are referenced. It is best to avoid this post-conversion effort by ensuring that the Visual Basic 6 source code has only explicitly defined variables.
Late-bound object references in Visual Basic 6 represent a similar problem. Late-bound references were typically used in Visual Basic 6 to interface to Microsoft Office products or other COM based interfaces in a non-version specific manner. Programs of this type will typically not covert well. For Microsoft Office interface applications, you may want to consider rewriting the software directly in Visual Basic.Net using Visual Studio Tools for Office (VSTO). Note that VSTO requires MS Office 2003. For non-office applications, you will want to consider rewriting the application using early-bound methods by directly referencing the DLL at compile time. If needed, Visual Basic.Net still supports late-bound COM object, but there will be a significant performance penalty.
I hope you find this helpful.
Friday, October 14, 2005
As a .NET user group member I wanted to share my experience of"migrating my MFC apps to .NET using C# and VB.NET" so that it will be beneficial for all our members. It might not be an ideal solution for all but I am hopeful it will add at least few new pointers in your knowledge base.
The problem was "How to migrate MFC applications to .NET in C# orVB.NET?" and there were no guidelines or samples. As we know MFC will besupported in Windows Vista (earlier codenamed longhorn) so we can keep MFC apps running for at least few years but question was how to enhanced and use with .NET managed assemblies, keep maintenance low, less compatibility issues, less interops, less performance hiccups and less complicated install program.
Above all new customers were asking on which technology our product wasbuilt? And if answer was "MFC" then we started loosing new business opportunity. Then what to do? What is the trend? Most of C++ programmershave already moved to C# and wish to convert their apps in C# or VB.NET but again there is lack of information on how to do it.
My first problem was ATL or MFC UI conversion to Windows Form resources and there was no help and that was the reason we never went ahead with even prototype test for migration. But thanks to Google where I found acompany called DudeLabs( http://www.dudelabs.com )which has a product"RC Converter" and it changed our migration policy because only in minutes we had our hundreds of dialogs, form views, all standard controls with their properties, menus, string resources and accelerators converted in Windows form resources and we chose our own class name,file name, namespace name and control names naming conventions. We used C# on Visual studio 2005 format but it also generates Visual studio 2003 format and supports C# and VB.NET both.
This quick conversion of our UI gave us ample time to focus on business layer and data layer rewrite.
Now thanks to Microsoft whose application block for SQL Data Access fixed our data layer rewrite in minutes because we were using MS SQLServer 2000. But even if you are using other databases please use SQLData Access application block code as sample and you will be done in hours or in worst case 2 or 3 days.
Business logic rewrite needs to be done manually and we knew that so we started rewriting it and let me tell you writing code in Visual Studio 2005 takes one third or less time as compared to MFC or ATL and then if you have any issues visit http://www.codeproject.com orhttp://www.GotDotNet.com and be assured you will find your solution there and if not the exact answer then at least you will find something to start with. I am really happy as we are near completion of our product migration from MFC to .NET managed world.
As .NET user group and our .NET community always helped me in my migration path I wanted to share it with you all so that it will make your migration at least a little bit easier.
What I learned was - It takes less time and money to migrate to .NET from MFC/ATL than we are estimating in present scenario.
But be careful as only migration to .NET will not increase you sales immediately because this migration first makes sure that your product will survive in future and then it increase your new sales opportunities and gives you flexibility to add new functional modules with less development time, ability to interact with managed world tools and components, enhances performance, keeps you on cutting edge technology, provides you click once deployment and has a very low maintenance cost.
So what you are waiting for?
Wish you good luck with your migration!
Wednesday, October 12, 2005
Monday, October 10, 2005
I finally found it. The web site http://www.sync2it.com/ allows you to create a free member account where a master copy of all your bookmarks are stored. You download a small utility for your system tray that allows you to upload your current bookmarks and then provides easy one-click access to your bookmarks at any time. Add or delete a bookmark? The other computers are automatically synchronized with the same change. It is as if all the bookmarks are coming from a single shared directory. Wonderful!
If you are on a computer that does not allow you to install software, like a library PC, you can access all your bookmarks as a web page by signing into your account on the Sync2It web site.
And best of all, this service is provided free of charge.
This service has made my internet browsing so much more productive - I just love it. Try it out, I am confident you will be impressed.
Thursday, October 06, 2005
I spoke with several people who mentioned that they make a point to read my blog entries. Thank you for reading! It is nice to know that I have an audience and it helps me stay motivated to continue to post the best information that I can.
Wednesday, October 05, 2005
In case you have a similar need in the future, the code is listed below for your use. I hope you find it helpful.
'Copy contents of a string Listbox to the clipboard
Dim strList(Me.lbStatus.Items.Count) As String
Dim strClip As String = String.Join(vbCrLf, strList)
'Returns the text within the first set of quotes found
Function GetTextWithinQuotes(ByVal strSource As String) As String
Const Quote As Char = Chr(34)
If strSource.IndexOf(Quote) = -1 Then Return String.Empty
Dim StartPos As Integer = strSource.IndexOf(Quote)
Dim EndPos As Integer = strSource.IndexOf(Quote, StartPos + 1)
If (EndPos - StartPos = 1) Then Return String.Empty
Return strSource.Substring(StartPos + 1, (EndPos - StartPos - 1))
Dim ErrorMsg as string = "I was unable to perform <>." & vbCrLf & "Please make sure to <>." & vbCrLf & "Suggestions go here." & vbCrLf & vbCrLf & "Detailed Error Information below:" & vbCrLf & vbCrLf & " Message: " & exp.Message & vbCrLf & _" Source: " & exp.Source & vbCrLf & vbCrLf & " Stack Trace:" & vbCrLf & exp.StackTrace
Tuesday, October 04, 2005
First I tried the obvious of just setting the visible property of the unwanted tabpages to false. This hid the contents of the tabpage, but the tabpage itself remained visible and in the row of tabs that could be selected by the user. If the tabpage had fully hidden itself as it should have (in my mind), I would have been all set. But instead I had a problem to solve.
To clarify, I have almost 40 tabpages total in the tabcontrol. There are four tabpages that always should be shown in a particular order (tabpages 2-5) and I wanted the first tabpage on the left to be different and selected depending on which item was selected in a tree control on the form.
In other words, I want all 40 tabs on the tabcontrol for ease of maintenance on the form, but to only show 5 of those tabpages at any time and to be able to dynamically change which tabpage from the non-display tabpages was to be shown at the first tabpage, depending on what is selected on a tree control on the form.
The first issue was that I could not insert a tabpage to a certain position. The .add method only adds the tabpage to the end of the existing tabpages collection.
The second issue was that any direct assignment to a tabpage always produced a blank tabpage, i.e., none of its child controls were visible and all attempts to get them to appear failed. That was disappointing as I could have just added a dummy tabpage as the first one and then repeatedly replaced with with the tabpage of current interest as the user moved around the tree control.
Utilimately I created a second non-visible tab control on the form named tcHidden, moved all the tabs over to it at Form_Load, then moved the tabpages between the two controls in the desired order as the user moved around in the tree control. It works well and it is fast enough that the users are happy with it.
The tabcontrol is one of those controls that seems to give me fits, probably because I always try to push it to its limits, so I wanted to post one of my workarounds in case someone else has a similar need. If you found this helpful, please post a comment and let me know. Thanks.
Note that I am using Visual Basic .Net 2003 and Framework v1.1
Monday, October 03, 2005
Compuware is pleased to announce that the Premier Application Development Event in the Midwest now features the unbeatable combination of in-depth Java and .NET learning, a distinct management track, leading visionaries AND amazing entertainment.
This year's program features such industry heavyweights as:
Rick Laplante, General Manager of Microsoft Enterprise Tools, Microsoft
Mike Milinkovich, Executive Director, Eclipse Foundation
Keith Landers, CTO -- Application Services, Americas, Hewlett Packard
Joe Dumars, President of Basketball Operations, Detroit Pistons
Renowned authors: Scott Ambler, Jon Kern, Stephen Teilhet, David Herst
And concludes with another one-of-a-kind after-hours experience kicked off in style with an exclusive performance by one of the premier comedy talents in America, Dennis Miller!
Time is running out to register for this exciting event!
Saturday, August 27, 2005
I wrote a new program several months ago in VB.Net. Now, I have to update a legacy Visual Basic 6 program and need some routines from that VB.Net program.
There has been a lot of attention on how to best convert from VB6 to VB.Net, but now I am facing the opposite situation. I have to believe that this will be more common as time goes on, as legacy code can take a long time to truly fade away.
I know I can use COM Interop to use the VB.Net code directly from VB6, but I don't want to require that the .Net Framework be installed for users of the VB6 application. The best solution is modify the code to work in VB6. It's going to be interesting, I'll keep you posted...
Monday, August 22, 2005
'Get the CD/DVD volume label
Dim VolumeLabel As String = _
Sunday, August 21, 2005
Dim TxtNames As String() = IO.Directory.GetFiles("c:\temp\*.txt")
and from the documentation it was not clear to me why I was getting the error.
Turns out that you must use the second overload version of the GetFiles method with two strings if you want to include a wildcard.
In the example above, the two possible correct versions of the GetFiles method include:
Dim TxtNames As String() = IO.Directory.GetFiles("c:\temp")
Dim TxtNames As String() = IO.Directory.GetFiles("c:\temp","*.txt")
The second statement provides the desired result of returning a string array of all filenames with a txt extension in the c:\temp folder. The first statement returns all files in the c:\temp folder which can be scanned with a loop for further processing.
Note that the single string overload verison of GetFiles can only accept a directory name.
I hope this helps clarify a point that managed to confuse me. As usual, it's obvious once you know the answer!
Saturday, August 20, 2005
All of the Xceed controls require a LicenseKey property be set with a valid license code in order to function. The example on their web site assume that you are using the component(s) on a form and show how to set the LicenseKey property just before the call to InitializeComponent(). I confirmed that this works fine on a form.
I want to write a wrapper class around the FTP control so that I can hide some of the complexity of its feature-rich interface and provide a more user-friendly interface, exposing only those capabilities that I need. Since there is no form, setting the LicenseKey needs to be slightly different and I could not find an example.
Below is what I found to work:
Public Class FTP_Example
Private FTP As Xceed.Ftp.AsyncFtpClient
Public Sub New(ByVal FTPSite As String)
Xceed.Ftp.Licenser.LicenseKey = "My License Key Goes Here"
FTP = New Xceed.Ftp.AsyncFtpClient
I hope you find this tip useful.
Xceed is a registered trademark of Xceed Software Inc. http://www.xceedsoft.com/
Friday, August 19, 2005
There was an error on the example for the CONTINUE statement which has been corrected.
The Internet web address for all the sites I mentioned at the GLUGnet meeting were added as the last slide of the presentation.
Thank you to GLUGnet for allowing me to give this presentation. I learned a lot by doing the research for the presentation and I really enjoyed the experience. GLUGnet is a great user group and I'm very proud to be a part of it.
If you find yourself in the East Lansing Michigan area on the third Thursday of the month, please feel free to join us for free food and drinks and an educational meeting. See the web site http://www.glugnet.org for more information.
Thursday, August 11, 2005
The first is the blog from the Visual Basic .Net IDE team. From their introduction, "This blog is hosted by the program managers, developers, and testers who work on the Visual Basic Integrated Development Environment (VB IDE). " This blog has an awesome FAQ and further tips on the cool new feature of Code Snippets. Other topics include code generation for overrides, a snippet editor, refactoring tool, new debugger features, and an awesome list of the 10 best new features in Visual Basic 2005. It can be found at http://blogs.msdn.com/vbide/default.aspx
The second is "Don't be Iffy" by Julie Lerman. This is a extensive informal blog by a self-employed programmer who clearly loves programming and Visual Basic.Net. Her personality really comes through on her blog. I think you will find it both informative and enjoyable. http://www.thedatafarm.com/blog/
Thursday, July 28, 2005
So what does that have to do with the new My object in Visual Basic 2005? It continues the tradition of what has always been best about working in BASIC. While other languages have traditionally been more powerful, BASIC has always excelled at getting useful applications completed quickly. As a business applications developer, my goal has consistently been to deliver a quality application that meets the needs of the users as rapidly as possible and then move on to the next needed solution.
The My object provides much simpler access to commonly needed objects in the .Net Framework Base Class Library. It also adds easy access to functionality that previously required use of the Win32 API. This provides a significant speed improvement in many common development tasks.
The My object has five major subclasses:
If you want to learn more specifics about the My object, see the July 2005 article in MSDN Magazine, available at http://msdn.microsoft.com/msdnmag/issues/05/07/My/default.aspx.
I mentioned earlier that prior versions of BASIC often traded power for productivity. With Visual Basic.Net 2005, this is no longer the case. The faithful BASIC developers can now have their cake an eat it too. This is an exciting time to be a developer!
Friday, July 22, 2005
I have found the easiest way is to use the IIF command. Depending on your coding preferences, you should find one of the two choices below will work well for you:
Dim MySQLBoolean as string = IIF(MyBoolean, "1", "0")
Dim MySQLBoolean as integer = IIF(MyBoolean, 1, 0)
Compared to an IF-THEN-ELSE approach, I like the IIF approach since it delivers the desired result in a single line of code.Readabilityy in code is very important, but with all other things being equal, one line of code is generally more readable than five lines of code.
Thursday, July 14, 2005
Say you have a collection of free email newsletters that you want to offer to your site visitors. If a visitor clicks on the link to select one or more newsletters, you may well present:
[Screen 1] a checklist of the newsletters to choose from with a Submit button, then
[Screen 2] a list of just the newsletters selected with a confirmation button, then
[Screen 3] a printer friendly listing of the selected newsletters along with information on how to change or cancel subscriptions and a nice thank you for subscribing to your site newsletters.
Prior to ASP.NET, you likely would have written these as three separate ASP pages; Screen 1 posts to Screen 2 which posts to Screen 3. Easy enough, but it certainly cluttered up the folders on your web server and tracking logic errors was more difficult across three separate source files.
Now with ASP.Net, all three screens can easily be coded into individual panel objects, all within the same .ASPX web page. The code-behind file makes the needed panel visible and sets the visibility of the other panels to false. The user still sees three different screens in sequence but coding is greatly simplified since it is all contained within a single .vb or .cs code-behind file.
I have used this technique in several web applications and it works great. The invisible panels are not included in the final page to the browser so the download times remain tight. I hope you find this tip very useful.
Wednesday, July 13, 2005
The advantage is that the code to add features or capabilities to these environments can be written fully in Visual Studio using standard C# or VB.Net code with full IntelliSense assistance and all the other advantages of the .Net framework. No need to learn VBA (Visual Basic for Applications) or macros to be productive.
The disadvantage is that VSTO only works with Office 2003 or later. This makes it unsuitable for widespread commercial applications at this time. A small disadvantage is that your assembly must accompany the document as it is moved around the network or emailed in order to maintain the functionality.
Conclusion: VSTO and the Visual Studio integration in SQL Server 2005 are key steps toward the programmer's nirvana of "learn one tool well and use it everywhere". Its impact will be even more positive as the majority of home and business users upgrade to Office 2003 or later.
Tuesday, July 12, 2005
Microsoft carried the construct of a Module forward from Visual Basic 6 into VB.Net (reluctantly as I understand it). A popular feature among VB6 programmers, it can be viewed as a global class available to all other forms and classes. VB6 programmers commonly used it to hold global variables and methods that would be needed by multiple forms. No instantiation needed, it was just there and global. Very convenient.
VB6 was used primarily to write single-user desktop windows applications. Yes, with the proper level of skill and prayer it could be used for more advanced purposes, but it truly shined as a way to quickly deliver high-quality desktop applications. In a single user environment, a shared global module is not a problem. Use of a module in a single user VB.Net application is still not a problem for the same reason.
Now consider the impact of a module in an ASP.Net application running on a IIS web server. Herein lies the power and the danger.
First the danger. Like before, a module is a class that automatically global to the entire application without requiring any instantiation. But now that single application is being used simultaneously by potentially hundreds or thousands of users. See the problem yet? Any variable declared at the module level is single-instance shared global among all users. If you casually define a module level variable of 'UserName' and base your security permissions on that, you will experience tremendous security issues as incoming users take on whatever security permissions were enabled by the last client that set the 'UserName' variable. Ouch!
Now the power. Modules are a great way to share single-instance methods for very efficient memory usage in VB.Net web applications. Only one copy of each module method is loaded in memory for all users of the application. As long as each of these modules are designed with shared usage in mind and do not depend on any static variables or try to maintain state across calls, this can be a very powerful and efficient design strategy.
Conclusion: In VB.Net web applications, use module level variables with great care, or not at all if possible. Use module methods with care to ensure that they can be safely shared.
I hope you find this information helpful. I wish I had known it earlier and saved myself some grief. Your comments are welcome.
Disclaimer: This post is based on some painful lessons learned from personal experience and not the result the detailed research on the topic. All of the statements in this post are correct to the best of my knowledge but please verify any use of this information with sufficient testing in your particular environment.
I have not been nearly as successful with WebForms. Whenever I placed a dataview control on a WebForm, it would honor the initial settings of the dataview, but then ignore any runtime changes to those settings. I confirmed that I was properly filling the dataset after each form post.
So how is it that essentially the same exact steps work fine in Windows, but fails in IIS? To get around it I would dynamically compose a new SQL query and load the dataset to match the required sort and filter. This required more coding into the WebForm than really should have been necessary.
I searched extensively for a resolution to this situation but did not find one. Finally, I learned that the trick is to refrain from using the design-time property settings for the dataview when used in a WebForm. Leave the needed properties of the dataview blank and set them only at run-time within code. In this way, it will honor each change in setting and provide the same flexibility to quickly and easily change the view of the data as seen in the datagrid.
Please post a comment to request sample code that illustrates this if you want to see some. I'll put together a good example if there is interest.
There may be external factors that will push you toward one choice over the other, such as standards in your workplace, a large legacy codebase of C++ or VB, or even the personal preference of your mentor. Since the .Net framework is shared by all .Net languages, it is essentially a toss-up. There are functional differences between the two languages, but they are minor. The good news is that the consistent .Net framework method names between both languages makes it relatively easy for a VB.Net programmer to read C# code, and for a C# programmer to read VB.Net code.
I prefer to work in VB.Net, simply because I have worked in Visual Basic for years and am very comfortable with that style of coding. That said, I can work in C# with only slightly more effort and I think you would find the same to be true. I have seen several surveys over the last year on this issue and developers are pretty evenly split among the two, with professional developers slightly in favor of C#, probably due to the strong presence of C++ code in commercial software applications.
If you have the freedom to make this choice yourself, then choose the language that you are most comfortable in and know that you are in good company with either choice. Learning to be productive in .Net application development is challenging enough, there is no need to complicate it with unnecessary worry about which language to work in.
Monday, July 11, 2005
The goal of this BLOG is to share my experiences as a professional application developer and as a board member for our local .Net developer user group.
I have been programming since 1978 and have watched application development evolve from very humble beginnings to the depth & breadth of what Microsoft's .Net environment has to offer today. There is intense joy and pride in delivering an elegant application to the user and knowing that it is among the best software available anywhere for that purpose. I felt that joy with my first program in 1978 and I still enjoy that feeling every time I deliver a new application. That feeling, at least in part, is what drives me to be the best programmer that I can be, and continue to strive to deliver an ever more exciting application next time.
I firmly believe that the .Net platform is the most productive application development platform available today. By taking advantage of its rich framework, I can create applications in a reasonable timeframe that I would never have even attempted before. It has expanded my horizons as a developer immensely. It is an exciting time in the application development world.
By sharing my experiences with .Net, both good and bad, I hope to help others become more productive and effective with .Net.
I will share my mistakes so that others can avoid them. I will share my questions when I am struggling, so we can learn together. I will share my successes so that others can add to their knowledge and skills. Like most developers, what I don't know about .Net far exceeds what I know. I expect to learn a lot from the feedback and comments of the readers of this blog and I truly look forward to the dialog.
Welcome to JBK.Net. I appreciate your company and companionship on the shared quest to become skilled and productive .Net developers.