/Home /Archive /Syndicate /Blog /Support /About /Contact  
All Visual Basic Feeds in one place!





Channel: David McCarter

Entity Framework samples have not been released in VB.NET! Check out the blog link below. Full Blog Entry: http://blogs.msdn.com/vbteam/archive/2009/06/18/vb-entity-framework-samples-now-available-lisa-feigenbaum.aspx


I hope everyone in Arizona and southern California is planning to attend this years Desert Code Camp on 6/13 and SoCal Code Camp in San Diego on 6/27 - 6/28. It's always a great time and lots of free training! I will also be selling a limited number of my latest book " David McCarter's .NET Coding Standards " at my sessions for $12, cheaper than the web site (no tax and shipping), please bring exact change or check. I will be presenting the following sessions and I hope you will atten ... [ read more ]


If you need to serialize and deserialize your objects and persist them to disk, the the code below is an easy way to accomplish this. The GetObjectTypes function correctly detects types so that the serializer will do it's job correctly. Without this you could run into problems (as I did). VB     ''' <summary>     ''' Deserializes from XML file.     ''' </summary>     ''' <type ... [ read more ]


If you are stuck using VB6 and .NET check out the site below. http://msdn.microsoft.com/en-ca/vbrun/ms788241.aspx


If you live in the San Diego area, dotNetDave (a.k.a. David McCarter) will be teaching a 6 week Fundamentals of the .NET Framework course at the University of California, San Diego Extension beginning on Wednesday 4/1/2008 from 5:30pm to 9:15pm. For more information and to enroll, please click here .


As most of you might know (I hope) it is unwise to call methods on a Control from a non-UI thread. This can cause all sorts of issues. Actually, I think in most cases .NET will throw and Exception. If you need to set a property on a Control this is how you would properly do it. VB.NET   Delegate Sub SetPropertyValueDelegate( ByVal obj As Object , ByVal val As Object , ByVal index As Object ())       Public Sub SetControlPropert ... [ read more ]


Learn about the future of VB.NET! http://code.msdn.microsoft.com/vbfuture Here is some of what is new: * sub lambdas, and multiline sub/function lambdas * sub lambdas, and multiline sub/function lambdas * AsParallel. (well, this was a plinq feature rather than a VB feature, but cool as heck) * DLR interop: invoke DLR methods from VB; create dynamic objects from VB; pass .net objects to DLR code; pass DLR objects to VB code. Note: unfortunately, this feature wasn’t rea ... [ read more ]


If you came to my talk at the OC .NET User group meeting today, below is a link to the presentation. Enjoy! Why You Need .NET Coding Standards (2008) Why You Need .NET Coding Standards-2008.pdf (941.06 KB) Link to my book: http://www.cafepress.com/geekmusicart.165478704


If you are interested in using LINQ to read Xml instead of the older way of the XmlDocument and SelectNodes, the code below is a pretty good example. The code takes in the ISO standard file for country names and codes (see sample below) and turn it into a list of Country objects for use in an application including ComboBoxes. <? xml version = " 1.0 " encoding = " ISO-8859-1 " standalone = " yes " ?> < ISO_3166-1_List_en xml:lang = " en " > ... [ read more ]


If you are coming to the San Diego .NET Developers Group meeting tonight I hope you will be their early for my talk titled " What’s New In VS 2008 SP1 ". Lots of new additions to this SP, not just bug fixes. Below is a link to the presentation. VS2008Sp1.pdf (715.88 KB)
If you live in the San Diego area, dotNetDave (a.k.a. David McCarter) will be teaching a 6 week Fundamentals of the .NET Framework course at the University of California, San Diego Extension beginning on Thursday 9/24/2008 from 5:30pm to 9:15pm. For more information and to enroll, please click here .


I hope everyone in California is planning to attend this years Central Coast Code Camp up in San Luis Obispo on 9/27 - 6/28. It's always a great time and lots of free training! I will also be selling a limited number of my latest book " David McCarter's .NET Coding Standards " at my sessions for $11, cheaper than the web site (no tax and shipping), please bring exact change. I will be presenting the following sessions and I hope you will attend. dotNetDave's .NET Utility Assemb ... [ read more ]


Do you want to retrieve all the Exceptions, including the inner Exceptions when an Exception is thrown for logging purposes? Since they are not enumerable, I wrote a block of recursive code below that will do the trick.     1   Function RetrieveAllExceptions( ByVal ex As Exception) As ObjectModel.ReadOnlyCollection( Of Exception)     2     Dim exceptions As New Generic.List( Of Exception)    ... [ read more ]


The link below takes you to the Microsoft Express products like Visual Basic Express 2008 and SQL Server Express 2008. http://www.microsoft.com/express/


Getting command line parameters or seeing if they are present is not as easy as you would think. I whipped up some code to make this flexible and easy.    Private Const ParameterPrefix As Char = "/"c            Private Function GetCommandLineArgument(ByVal parameter As String) As String       Dim paramValue = String.Empty       For Each tempValue As String In System.Environment ... [ read more ]


Here is some easy, generic code to serialize your objects to and from JSON: Public Shared Function JsonEncode(ByVal input As Object) As String Dim serilizer = New DataContractJsonSerializer(input.GetType) Using ms = New MemoryStream() serilizer.WriteObject(ms, input) Return Encoding.Default.GetString(ms.ToArray()) End Using End Function Public Shared Function JsonDecode(Of T)(ByVal input As String) As T Using ms = New MemoryStream(Encoding.Unicode.GetBytes(in ... [ read more ]


I recently started a new job that uses C#. I have been trying for two frickin hours to get Trace Listeners working in an application here with no luck at all. So to test that I have the web.config setup correctly, I added the following: var log = new Microsoft.VisualBasic.Logging.Log(); log.WriteEntry("VB Log"); Bam, it works! Dang I LOVE VB.NET! Now I'm going to go ask my boss if I can use the VisualBasic.Logging class in our C# application ;-) David McCarter


I hope everyone in southern California is planning to attend this years SoCal Code Camp up at University California San Diego on 6/28 - 6/29. It's always a great time and lots of free training! I will also be selling a limited number of my latest book " David McCarter's .NET Coding Standards " at my sessions for $11, cheaper than the web site (no tax and shipping), please bring exact change. I will be presenting the following sessions and I hope you will attend. dotNetDave's .N ... [ read more ]


If you live in the San Diego area, dotNetDave (a.k.a. David McCarter) will be teaching a 6 week Fundamentals of the .NET Framework course at the University of California, San Diego Extension beginning on Thursday 5/14/2008 from 5:30pm to 10:00pm. For more information and to enroll, please click here .


Today I released the first public version of my dotNetTips.com Utility assembly. This is an open source .NET 2.0 utility assembly that contains useful common code that anyone can use in just about any project. Helper classes include Active Directory, Validation, IIS, File IO, Security, Computer Info, Web, XML and more. Other classes include a better TextBox and ComboBox, sending e-mail, encryption and more. To download go to: http://www.codeplex.com/dotNetTipsUtility


I hope everyone in southern California is planning to attend this years SoCal Code Camp up at Cal State Fullerton on 1/26 -1/27. It's always a great time and lots of free training! My fav southern California band Killola will be playing again at the Geek dinner so make sure you arrive early on Saturday to grab one of the limited number of tickets available. I will be doing the following sessions and I hope you will attend. dotNetDave's .NET Utility Assembly (My First CodeP ... [ read more ]


Often, it's a good idea to make sure the user trying to access the file has permissions to it before performing an operation like read, write or delete. Below is code that makes this pretty easy.   Sub DemandFileReadPermission( ByVal fileName As String )     If System.IO.File.Exists(fileName) Then       Dim filePermission As New System.Security.Permissions.FileIOPermission(System.Security.Permissions.FileIOPermissionAcc ... [ read more ]


If you live in the San Diego area, dotNetDave (a.k.a. David McCarter) will be teaching a 6 week Building Rich & Interactive Web Applications with ASP.NET AJAX course at the University of California, San Diego Extension beginning on Thursday 2/21/2008 from 5:30pm to 10:00pm. For more information and to enroll, please click here .


If you need to convert a Bitmap to an Byte array, here is how you do it.   Public Shared Function ConvertToByteArray( ByVal value As Bitmap) As Byte ()       Dim bitmapBytes As Byte ()         Using stream As New System.IO.MemoryStream           value.Save(stream, value.RawFormat)         bitmapBytes = stream.ToArray         ... [ read more ]


There are many times when I need to convert an array to a delimited string. Here is an easy way to do it using generics in .NET 2.0.   Public Shared Function ConvertArrayToString( Of arrayType As {IEnumerable})( ByVal array As arrayType(), ByVal separator As Char ) As String         If Not IsValidArray(array) Then         Throw New ArgumentNullException( "array" )       End I ... [ read more ]


.NET still does not expose the drive serial number via the framework. For that you will need to use WMI. Here is the code. Shared Function GetDriveSerialNumber( ByVal drive As String ) As String     Dim driveSerial As String = String .Empty       'No matter what is sent in, get just the drive letter     Dim driveFixed As String = System.IO.Path.GetPathRoot(drive)     driveFixed = Replace(driveFi ... [ read more ]
Here is some simple code to validate that an array is valid. Before trying to use an array, you should always validate it with this code first.   Public Shared Function IsValidArray( ByVal array As Array) As Boolean       Dim valid As Boolean = False         If array Is Nothing Then         Throw New ArgumentNullException( "array" )       End If   ... [ read more ]


When data binding to a DropDownList control in ASP.NET, there are in many cases when you want the first selection of the control to be blank or say something like "<please select value>". In part one of this tip (back in 2003), I wrote that you could just add an empty row to the DataSet. In VS 2005 and the new way of data binding that I usually do to web services, this is more difficult. So here is another solution just using code in your ASP.NET code.  Protected Sub DropDownLi ... [ read more ]


Visual Basic Beer? Well not really, but we can only hope. Don't look for this in your local store unless you are in Australia.


If you need to convert RTF to text, here is a simple way of doing it:     Public Shared Function ConvertRtfToText(ByVal input As String) As String       Dim returnValue As String = String.Empty       Using converter As New System.Windows.Forms.RichTextBox()         converter.Rtf = input         returnValue = converter.Text     &nb ... [ read more ]


The second edition of this book (formerly VSDN Tips & Tricks .NET Coding Standards), is a consolidation of many of the .NET coding standards available today in one easy to read and understand book. It will guide any level of programmer or development department to greater productivity by providing the tools needed to write consistent, maintainable code. The core of the book focuses on naming standards, how to order elements in classes, declaring methods, properties and much, m ... [ read more ]


Line and Shape controls, PrintForm component, and Printer Compatibility Library Microsoft Visual Basic 2005 Power Packs 2.0 includes a new set of Line and Shape controls and updated versions of the two previously released Visual Basic 2005 Power Packs, the PrintForm Component and the Printer Compatibility Library. All three are now included in a single assembly making them even easier to use and redistribute with your application.   http://www.microsoft.com/downloads/details.aspx ... [ read more ]


San Luis Obispo will be holding a code camp on September 22nd, 2007. I will be attending and presenting. For more info go to: http://www.centralcoastcodecamp.com/ Articles/News: http://www.sanluisobispo.com/business/story/134783.html > > Code Camp on KCOY My sessions will be: Building Rich & Interactive Web Applications with ASP.NET AJAX Presentation: AjaxSession091807.zip (875.6 KB) Code Example: AjaxExample.zip (703.12 KB) Why You Need .NET ... [ read more ]
Phoenix will be holding another code camp on September 15th, 2007. I will be attending and presenting. For more info go to: http://desertcodecamp.com/ My sessions will be: Building Rich & Interactive Web Applications with ASP.NET AJAX Presentation: AjaxSession.zip (1023.53 KB) Code Example: AjaxExample.zip (703.12 KB) Why You Need .NET Coding Standards Presentation: StandardsSession.zip (1.6 MB)  


I came up with some generic methods to do the job: Public Shared Function DeserializeXMLToObject(ByVal input As String, ByVal type As System.Type) As Object   Dim result As Object = Nothing   Dim serializer As New XmlSerializer(type)   Try     result = serializer.Deserialize(New XmlTextReader(New StringReader(input)))   Catch ex As Exception     Debug.WriteLine(ex.Message)   End Try     Return result End Function ... [ read more ]


To download go to: http://go.microsoft.com/?linkid=5559918  


Great article on generating docs for your VB.NET Application: http://msdn2.microsoft.com/en-us/library/Aa289191(VS.71).aspx


The Power Pack controls consist of: BlendPanel. This provides a background for a form where the color fades from one shade to another. UtilityToolbar. This is a toolbar whose look and feel is similar to the Internet Explorer toolbar. ImageButton. This is a button that displays a graphic over a transparent background. NotificationWindow. This displays text and graphics in a pop-up window (commonly known as "toast"). TaskPane. This is a container that provides collapsible fram ... [ read more ]


http://msdn.microsoft.com/vbasic/atthemovies/


http://msdn.microsoft.com/vbasic/vbrkit/default.aspx


Just use the code below. I'm sure you will want to replace the hard-coded values with parameters from a method. Dim mailProcess As New Process() Dim processInfo As New System.Diagnostics.ProcessStartInfo()   processInfo.FileName = " mailto:someone@someone.com ?" _                             & " cc=someoneelse@someone.com &" _   &n ... [ read more ]


It’s was told to me that this can never be shown to the client and further more the number can never be rounded (anyone ever see Office Space… sound familiar?). So I went searching on how to do this in .NET. After many, many hours of searching and testing, I could not find any way in .NET to do this. Every function I found would always round the number! I found myself wishing for just a way to flip a switch to tell .NET to stop doing that. So I finally gave up and came up with a short func ... [ read more ]


The function below returns the appliction path for an appliction in the Compact Framework. Shared Function GetAppPath() As String Dim mstrPath As String mstrPath = _    System.IO.Path.GetDirectoryName    (System.Reflection.Assembly.GetExecutingAssembly().GetModules    (0).FullyQualifiedName) If Right(mstrPath, 1) <> "\" Then mstrPath += "\" End If Return mstrPath End Function Tip Submitted By: David McCarter & Marquis Howard ... [ read more ]
So I created the nifty little Function below: Private Function GetWebFormValue(ByRef WebForm As System.Collections.Specialized.NameValueCollection, _                                    ByVal ControlName As String) As String   Try     Return WebForm(ControlName).ToString   Catch   &nb ... [ read more ]
Below are some converted VB6 methods that do common database connection tasked. The first one (CheckSQLConnection) checks to make sure that a connection can be made to the database. This could be used at the beginning of your application or web application to make sure that the database is up. If it's not, doubt if there is much need in continuing. The next method (CloseSQLConnection), closes a SQLConnection object if it is open. NEVER assume that the connection was successfully opened du ... [ read more ]
Okay, I need to give you some history of .NET... at first, by default, Options Strict was turned on. This is a good thing! It makes for better bug free code. Many of us have been waiting for this for a long time. But, some of the big-wigs in the VB world started crying?!?!  Why... because they said that this would hamper their efforts to migrate VB6 code to VB.NET. Ha! Migrating code is a pipe dream and should be avoided at all costs. For some STUPID reason Microsoft actually listened to ... [ read more ]
When setting a string object to an empty string, I did a test and I found that doing this: Dim ContentFieldName As String = String.Empty Is slightly faster than doing this: Dim ContentFieldName As String = "" Your results my vary    Tip Submitted By: David McCarter
Regular Expressions in .NET By Darren Neimke
Using VB6, it took a lot of code to read values from the Registration Database. Well, not anymore with with VB.NET! Take a look at the code below.   Imports Microsoft.Win32 Function GetDBConnect() As String Dim pobjRegKey As RegistryKey Dim pstrValue As String  pobjRegKey = _  Registry.LocalMachine.OpenSubKey("SYSTEM\CurrentControlSet\Services\MyService\Parameters", False)  If Not IsNothing(pobjRegKey) Then    pstrValue = pobjRegKey.GetValue("DBCon ... [ read more ]


http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcn7/html/vaconVBNamingRules.asp


© 2005 Serge Baranovsky. All rights reserved.
All feed content is property of original publisher. Designated trademarks and brands are the property of their respective owners.

This site is maintained by SubMain(), a division of vbCity.com, LLC