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





Channel: Deborah Kurata

A common requirement in most applications is to validate the data entered by the user. This is such a common requirement, that it makes sense to build a reusable Validation class. This post details the beginnings of a .NET Validation class. The class was originally designed to validate business object properties. But it could also be used to directly validate fields in your user interface if you are not yet using business objects. In C#: using System; using System.Collections.Ge ... [ read more ]


Being a physics major in college, I am familiar with the Heisenberg Uncertainty Principle which basically states that in quantum physics, some properties (like position and momentum) cannot both be known to any precision. Though not technically accurate, the Heisenberg Uncertainty Principle is often simplified to what is called the observer effect . This refers to the fact that the act of observing something can change its behavior. This is very often true in programming, especially wh ... [ read more ]
My prior post demonstrated how to bind to a list of month names. Once the user picks the desired month, you may want to provide a list of valid dates to pick a date in that month. For example: 1-30 for September and 1-31 for July. You can accomplish this using a switch statement (Select Case in VB), but that hard-codes the dates, does not handle leap year, and does not support localization. Another option is to use the culture specific calendar as shown below. The code is first shown ... [ read more ]
Visual Studio comes with DateTimePicker and MonthCalendar controls that provide a standard looking calendar for the user to pick a date. But there are times when these controls don’t provide the features you need. For example, say you want to ask the user for the month and year that their credit card expires. Or you want to ask for a birth date and don’t want the user to have to scroll back to 1932. Or better yet, don’t need to know the year (not that I refuse to admit my birth year <G> ... [ read more ]


The Enum keyword allows you to define a standard set of named constants for use in your application. Sometimes you may want to present this same list of  values to your user. You can display the set of Enum values in a ComboBox or ListBox using data binding. And even better, if you use the DescriptionAttribute in the Enum, you can display a more user-friendly set of values. For example, a Customer business object may have a CustomerType defined with a specific set of options for corp ... [ read more ]
Most business applications have business objects such as customer, order, or invoice. Often, the data access layer (DAL) provides the data and your code needs to use that data to manually populate a business object. This post describes how to manually populate a business object from a DataTable. It uses the Customer class defined here . The code is first shown in both VB and C#. It is then described in detail below. In C#: public static List<Customer> Retrieve() { ... [ read more ]
This post details how to use the DataTable Visualizer. The DataTable Visualizer is a debugging tool that allows you to see and edit the contents of a DataTable while you are debugging. NOTE: There is also a DataSet Visualizer that works the same way for DataSets instead of DataTables. To use the DataTable Visualizer: Set a break point on any line of code after you have a DataTable populated.   Run your application until it stops at the break point.   ... [ read more ]


This post provides an implementation of a method that accesses a DataReader from a SQL Server database using a SQL statement. Your application can then use the DataReader to read the data from your database or bind directly to an ASP.NET control such as a grid. If you are not familiar with a DataReader, it is basically like a hose with a nozzle . When you open the connection to the database, it is like turning on the spigot connecting the hose to the water source. The water is flowing, bu ... [ read more ]
This post provides an implementation of a method that accesses a DataReader using a stored procedure in a SQL Server database. Your application can then use the DataReader to read the data from your database or bind directly to an ASP.NET control such as a grid. If you are not familiar with a DataReader, it is basically like a hose with a nozzle . When you open the connection to the database, it is like turning on the spigot connecting the hose to the water source. The water is flowing, b ... [ read more ]
We had the pleasure of having Beth Massi present at our local .NET developer’s group, EastBay.NET , last night in Livermore, CA (East of San Francisco). Her excellent talk was on VB 10, C# 4, and Visual Studio 2010. She showed off all of the new language features that are coming in the next release of Visual Studio with energy and great humor. I have not enjoyed a technical talk this much in a long time! Beth covered the new features in VB 10 such as: No more line continuation ... [ read more ]


In a prior post here , I created an XML file using VB 9 (Visual Basic 2008/.NET Framework 3.5). This post demonstrates how to read that file and reconstitute the list of customers. This code reads the XML into an XElement: Dim customerXml As XElement = XElement.Load("customers.xml") This code processes the XML and rebuilds the list of customers: ' Repopulate the business objects Dim customerList as New List(Of Customer) For Each c As XElement In custom ... [ read more ]
A stored procedure is a set of structured query language (SQL) statements that provide a particular operation on the data (or structure) of a database and are stored within the database. For example, a retrieval stored procedure contains a Select statement to select a set of data from one or more tables in a database and return the results. CREATE PROCEDURE dbo.CustomerRetrieveAll AS     SELECT            Cust ... [ read more ]


This post provides an implementation of a method that retrieves a DataTable from a SQL Server database using a SQL Statement. Your application can then use the DataTable to populate your business objects or to bind directly to a UI control such as a Combo Box or Grid (such as the DataGridView). The code is first shown in both VB and C#. It is then described in detail below. In C#: public static DataTable ExecuteDataTable(string sqlStatement,        & ... [ read more ]
This post provides an implementation of a method that retrieves a DataTable from a SQL Server database using a stored procedure. Your application can then use the DataTable to populate your business objects or to bind directly to a UI control such as a Combo Box or Grid (such as the DataGridView). NOTE: This post assumes you already have a stored procedure defined to select the required data from your database. For more information on stored procedures, see this link . The code is first s ... [ read more ]
One of the common ways to access data in a .NET application is to use the drag and drop TableAdapter tools or the new Entity Framework tools. But what if you want to write your data access code yourself? There are many ways to access data in an application without using the drag and drop tools: Retrieve a DataTable using a stored procedure ( example ) Retrieve a DataTable using a SQL string ( example ) Access a DataReader using a stored procedure ( example ) Access a ... [ read more ]


This entry details the implementation of the DateRange class from this example in C#: public class DateRange {     public DateTime StartDate { get; set; }     public DateTime EndDate { get; set; }     // Constructor     public DateRange(DateTime startdate, DateTime enddate)     {         this.StartDate = startdate;     ... [ read more ]
This entry details the implementation of the ZodiacSigns class from this example in C#: public class ZodiacSigns : List<ZodiacSign> { } Constructor The following is the constructor defined in the ZodiacSigns class: public ZodiacSigns() {     InitializeCollection(); } This constructor ensures that the collection of zodiac signs is initialized when an instance of this class is created. Methods The following are the method ... [ read more ]
This entry details the implementation of the ZodiacSign class from this example in C#: public class ZodiacSign {     // Properties     public string Name { get; set; }     public List<DateRange> DateRanges { get; set; }     // Constructor     public ZodiacSign(string name, List<DateRange> dateranges)     {      & ... [ read more ]
Here is the story defining the simple use case for this application: The user picks a date between 2/19/1996 and 2/5/2019. The system displays the appropriate Chinese zodiac sign (Monkey, Dog, Rat, etc) Seems simple enough. So how to implement this … Defining the Classes The first step in using OOP with a simple situation is the same as with any application … define the "nouns”. These are the first nouns I came up with: Zodiac sign Date range T ... [ read more ]
This entry describes the Peg class from this example in further detail: Public Class Peg End Class Properties The properties of the class are as follows: Private _Column As Integer ''' <summary> ''' Gets the column of this peg. ''' </summary> ''' <value></value> ''' <returns></returns> ''' <remarks></remarks> ... [ read more ]
This entry describes the MasterMind class from this example in further detail: Public Class MasterMind End Class Properties The properties of the class are as follows: Private _Answer As List(Of Color) ''' <summary> ''' Gets the answer. ''' </summary> ''' <value></value> ''' <returns></returns> ''' <remarks></remarks&g ... [ read more ]
Someone on the MSDN forums recently asked how to apply object-oriented programming (OOP) principles to a basic game. So I thought it would be an interesting project to develop a very simple sample game using OOP. I selected MasterMind because it is a relatively simple game. If you are not familiar with the game, you can find a description and picture here . Defining the Classes The first step in using OOP with a game is the same as with any application … define the "nouns”. The ... [ read more ]


You have probably heard that the next version of VB will no longer require line continuation characters in most situations. This is very good news for those of us that do not like typing underscore characters. But in the mean time, what do we do if we have a long string, like a SQL string: Dim mySelect As String = "Select CustomerId, " & _                        ... [ read more ]
Looping through a list to append strings is often more challenging than it should be. For example… In C#: string emailAddresses=string.Empty; foreach (Customer c in custList) {     emailAddresses += c.EmailAddress + ";"; } In VB: Dim emailAddresses As String = String.Empty For Each c As Customer In custList     emailAddresses &= c.EmailAddress & ";" Next Both of these examples po ... [ read more ]
At the MVP Summit this year, Beth Massi interviewed me for the “I’m a VB” series . Alan Cooper introduced me to VB back around 1992 (VB 2.0), so it was fun to talk about my favorite things in VB. Any thoughts on the interview? I’d love to hear them!... [For the complete article see the Orignal Post link below] ...
Defining a list of integers in your code involves lots of tedious typing. In VB, you can’t do this: 'Dim numberList As new List(Of Integer) = {1, 2, 3, 4, 5, 6, 7, 8, 9} So you have to either add numbers to the list manually, or create an array, which still involves lots of tedious typing: Dim numberList() As Integer = {1, 2, 3, 4, 5, 6, 7, 8, 9} With .NET 3.5, you can instead use the Range method of the Enumerable class that is part of the System.Linq namespace. In ... [ read more ]
There may be situations when you want to display a form by its form name. For example, say that you retain your menu options in a database so they can be customized. You want to associated a menu option with the display of a particular form. So you store the form name in the table. But then you need a way to show that form at runtime. For this, you need reflection. In VB: Dim formName as string = "CustomerForm" Dim assemblyName As String = My.Application.Info.AssemblyNam ... [ read more ]
I ran across the OfType feature a few months ago and find it to be very useful. OfType is one of the many extension methods on IEnumerable that was provided with .NET 3.5. If you ever need to search through a list for a particular type of object, then this feature is for you. The most common scenario for this feature is in working with the user interface. Say you want to hook up a particular event handler to every Button on your form. Or you want to go through your form and clear every TextBo ... [ read more ]
Often times applications require lists of things: lists of customers, lists of experiments, lists of accounts and so on. The generic lists provided in .NET 2.0 made working with these lists easy. And the list initializers in C# and the object initializers in VB make lists easier still. As an example, here is a first draft of a simple Customer class. In C#:   public class Customer {     public int CustomerId { get; set; }     pub ... [ read more ]
One of my favorite features in VB 9 (Visual Studio 2008) is XML Literals. This example demonstrates how insanely easy it is to build an XML file using VB. This code builds xml from a list of customers. Dim customerXml As XElement = _ <customers>    <%= From c In custList _        Select <customer>                  <LastName&g ... [ read more ]
One of my favorite features in .NET 3.5 is lambda expressions. This example demonstrates how to use lambda expressions: To compare items in two lists and find which items in one list are not in the other. For example: {1, 2, 3}, {2, 3, 4}. {1} is only in the first list. To display the contents of the resulting set. First, define two lists: List<int> list1 = new List<int>() { 1, 6, 8 }; List<int> list2 = new List<int>() { 2, 6 }; The follo ... [ read more ]


So many things to think about, so little time. Deciding to be a developer with .NET is deciding to be a life-learner. There is no one manageable set of things to learn and then you are done. Rather, you spend every day learning new, better, more efficient ways to accomplish your task. I love to code. I love to learn. So I finally decided to start blogging about these things I am learning and share the things I know with others. Enjoy!... [For the complete article see the Orignal Po ... [ read more ]


© 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