Welcome!

Welcome to the VBDotNet Blog.

A Miscellaneous Collection of Tips, Tricks and Examples for Visual Basic .Net.

This blog covers a miscellany of Visual Basic .Net topics.  The topics have been selected based on actual experience of problems encountered by Visual Basic .Net beginner and intermediate programmers.

Select a Category and topic from the list below, or make a selection using the tabs above.

FORMS

1. Pulling Results from a Dialog form A very common problem with forms is getting the result of a dialog form.  Dialogs are used to ask a question or to get a response.  If it’s a simple question with a Yes/No or OK answer, then the standard dialog form is quick and easy to create, and simple to use.  But if the user must enter some value or select from an option, getting the information from the form requires extra code.

2. Passing Data to a New Form For a Windows Forms application, creating a new form is as easy as Project / Add Windows Form / Windows Form.  But what if you need to set this form up with some data that exists in the main form?   How do you populate the controls and variables in the new form with the existing values from the main form?

3. Where did I come from? Passing values between forms is one of the trickiest bits of a multi form application for new VB .Net programmers, but that’s partly because there are so many ways to handle it.  When a form needs to know where it came from, there is a property of the form that can provide just that information, if it’s set up properly.

4. Pushing Results Back to the Main Form Even if you identify the form that opened a subsidiary form, it’s not always easy to update controls on the form with new values.  This snippet shows how it is done.

5. Messaging Between Forms Messaging between forms is the most robust way of passing data back and forth between forms. It allows you to create forms that can be re-used with a minimum of issues about how you connect data on different forms.


CONTROLS

1. Linked Control Properties Have you ever wanted a control property, such as text on a label, to automatically update whenever a similar property on another control changes?  With VB.Net you can do it the hard way – in code – or you can do it the easy way, in the designer.

2. Control Arrays Programmers familiar with Visual Basic 6 are dismayed to find that the .Net designer doesn’t allow them to create arrays of controls – how can they get by without them?  Well, VB .Net does support control arrays, and they are just as easy to use as they were in VB6.

3. Subclassing / Inheritance Enhancing existing controls with new features and functions is easy with .Net.

4. Drag and Drop Providing your users with Drag and Drop options will make your applications more user friendly.


CUSTOM CONTROLS

1. Method Attributes Adding attributes to your custom control methods provides full integration with Visual Studio features.


RESOURCES

1. Access Resource by Name Using the name of the resource is an effective way of getting to your resources, but the procedure to use is not obvious.  Tis example shows how it’s done.


SERIAL PORT

1. Simple Data Receiving The serial port can be used for simple text receiving with just a few lines of code.  This example shows how to implement a simple GPS data receiver.

2. Receiving Text with a Delegate The serial port has some special requirements in .Net.  This snippet shows how to implement a serial input text receiving routine using a delegate to enable updating of GUI objects.

3. Binary Data Receiving binary data at the serial port is slightly different than receving text, because you must treat it as an array of bytes.  This example shows how to do that, together with a simple way to display the data without a cross-thread call.


FILES AND FOLDERS

1. File Locations Using the standard folders provided by the .Net framework can eliminate user access issues.

2. Reading / Writing text files .Net makes it easy to read and write text files.  All the hard work is done in the background, and the necessary processes are exposed as methods in the My.Computer.FileSystem namespace.

3. Random Access Visual Basic .Net allows random access to files using the StreamReader class.  The file pointer can be set as required, and data can be read or written as a stream of bytes or as a nominated variable type.


METHODS

1. ByVal / ByRef Understanding the implications of passing parameters by value or by reference is important in ensuring proper use of methods.

2. Using Static Variables Static variables can solve many problems that otherwise look difficult, or may require a global variable.

3. Shared Variables and Methods Shared variables or methods provide easy access to processes and values without the need to create an instance of the class.


GRAPHICS

1. Graphics Methodology There are many ways to handle graphics tasks in VB .Net, but it’s not always obvious which approach is best for a particular task. Some different approaches are discussed here.

2. Color Picker The GetPixel function returns the color of a pixel.  This example shows how to use this function by getting the color of the pixel at the current cursor position – a Color Picker function.  It also shows how to examine the image as painted on the screen.


EXAMPLES

1. Graphics – Scrolling List The Scrolling List example shows how to draw formatted text to a bitmap and then scroll that bitmap vertically in a panel, a pixel at a time.

2. Graphics – Screen Updating A clock is used to show how to draw the image background separately from the image components that need to be updated periodically.  This process reduces the load on the system when the display is updated frequently.

3. User Input, Structures, Lists The Grade Point Average example demonstrates the use of a simple structure for data management, user input validation, lists and listboxes, and a simple calculation.

4. Binary File Display An example that reads the contents of a file and displays the contents in a formatted text box as hexadecimal and text.

5. Simple Text Printing An example that shows how to create a component to simplify the printing process for any application that needs to print plain text.

6. Recursive Folder Search Recursion is a simple and effective technique for searching in a heirarchy.  This example shows how to access the folder heirarchy to list all files and folders.  It can be used as a pattern for any similar recursive procedure.

7. Command-line Arguments VB .Net provides easy access to the command that was used to start an application.

8. Data Entry / Store / Retrieve  A requirement that appears time and again is for a simple application that accepts data input by the user, saves it, and allows the saved data to be retrieved the next time the program starts.  This simple example is a template for that task.



TRAPS!

1. Object References Do you know what your variables are really referring to?

2. ByVal and ByRef Using ByVal and ByRef properly is a critical part of managing your variables.

3. Strings Are A Reference Type It doesn’t always seem so, but the String type really is a reference type.

4. Option Strict Setting Option Strict to On in your projects can save a lot of time and trouble in tracking down strange errors.

5. DoEvents Not really a trap, but a method that is subject to a lot of misunderstanding, and which requires caution in its use.

  1. #1 by Shawn Berg on October 21, 2012 - 5:52 am

    Many thanks for your assistance with my issue getting all rows to export to Excel. I have bookmarked your blog and will be referencing it often as I continue learning…

  2. #2 by Tyson Ackland on November 3, 2012 - 9:46 pm

    Acamar, I wanted to ask another question on the MSDN forum re PictureBoxes but as I’ve marked my original Q answered I think it’s not letting me continue that thread. You mentioned it is best to draw directly to the form because PictureBoxes react differently. Is the same true for Panels? I was hoping to use a Panel for the animation area so that I have space at the top of my form for a menu bar.

    • #3 by vbdotnetblogg on November 4, 2012 - 12:38 am

      Please post all questions in the forums so that everyone can participate. Start a new thread for a new question.

  3. #4 by idumu Brave on December 3, 2012 - 2:32 am

    Acamar, I have been following your responses to questions on the MSDN forum and down to your site activities. I want to appreciate your effort. your answers have been of help to me.

  4. #5 by manuel on February 8, 2013 - 5:03 am

    Mr Acamar, you are a genius. I use your solution posted at “http://social.msdn.microsoft.com/Forums/en-US/vblanguage/thread/0b74d5f6-5338-4df9-b3a9-4d506299074a” and modified to solve a whole day problem sorting dates in a listbox. thank you so much for your time and effort. If you want i can send you the little piece of code that i think it will help a lot of newbies like me.

    • #6 by vbdotnetblogg on February 9, 2013 - 7:12 am

      Thank you for your comment. You can post your code, with a note about why you think it contributes something to the community, at the thread where you found my example.

  5. #7 by tidza on January 13, 2016 - 8:49 pm

    is there a way to contact you

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: