Tags: | Posted by blockwood on 4/20/2010 5:01 AM | Comments (0)

This I am working onsite and client and a couple of great questions came up.  Here are my solutions to those:

1. How do you read an Excel 2007 spreadsheet into a VB.NET Windows Form DataGridView

BindingXlsxToDataGrid.zip (139.86 kb)

2. How do I trap the keystroke events on a windows form?

You will need to override the ProccessCmdKey method in the base class.

Answers_KeyPress.zip (65.67 kb)

3. What is the best way to convert a VB6 app to a VB.NET application?

Unfortunately there is no miracle cure, wizard or helper that will get the job done for you.  Although Microsoft did release this book free. Download it here.

4. Is it possible to work with USB devices from .NET?

Some USB devices not only add themselves as a HID Device (see your Windows Device Manager) but ALSO add themselves as a COM Device (see you Windows Device Manager) a little further down the list under Ports. Note that not all USB device do this.  Therefor as long as you set the correct Baud rate for the USB device you are using, it is just a matter of implementing the same as communicating on a COM port.  Download an example from Microsoft here.

Use the namespace System.IO.Ports and create a SerialPort object.  Using this port you can define the port, baud and parity.

Example:

5. How can the buttons, textboxes etc resize with my form?

This can be accomplished by using the docking system.  Here is an article: http://www.devx.com/dotnet/Article/6964

6. How do I create a sql server database?

If you are using the SQL version installed with Visual Studio 2008 you will need to download the SQL Server Management Studio Express 2005. Download here.

Once you download the appropriate (x86 or x64) version install and open the SQL Server Management studio.

Right click on the Database folder in the left hand pane:

 

 

That's it! You are now ready to connect to the database.  To create new tables, expand the newly created database folders and right mouse click the Tables folder > Insert Table.  

7.  Can you provide me a solution that shows a simple Event?

Of course! :-) FileTransferExample.zip (68.11 kb)

8. I would like to include Crystal Reports into my application, how do I do that?

Well I personally have not worked much with Crystal Reports so I'll I would do is copy and paste someone elses article.  So here is the link: Crystal Reports.

 

9.  When working with exceptions when would I create my own?  Can you show me the example?

WorkingWithExceptions.zip (69.41 kb)

10.  I want to call into non-.NET (unmanaged) code either a vb6 app or some system dll, how do I do that?

COM differs from the .NET Framework object model in several important ways:

  • Clients of COM objects must manage the lifetime of those objects; the common language runtime manages the lifetime of objects in its environment.
  • Clients of COM objects discover whether a service is available by requesting an interface that provides that service and getting back an interface pointer, or not. Clients of .NET objects can obtain a description of an object's functionality using reflection.
  • NET objects reside in memory managed by the .NET Framework execution environment. The execution environment can move objects around in memory for performance reasons and update all references to the objects it moves. Unmanaged clients, having obtained a pointer to an object, rely on the object to remain at the same location. These clients have no mechanism for dealing with an object whose location is not fixed.

To overcome these differences, the runtime provides wrapper classes to make both managed and unmanaged clients think they are calling objects within their respective environment. Whenever your managed client calls a method on a COM object, the runtime creates a runtime callable wrapper (RCW). RCWs abstract the differences between managed and unmanaged reference mechanisms, among other things. The runtime also creates a COM callable wrapper (CCW) to reverse the process, enabling a COM client to seamlessly call a method on a .NET object. As the following illustration shows, the perspective of the calling code determines which wrapper class the runtime creates.

COM wrapper overview

In most cases, the standard RCW or CCW generated by the runtime provides adequate marshaling for calls that cross the boundary between COM and the .NET Framework. Using custom attributes, you can optionally adjust the way the runtime represents managed and unmanaged code. 

Check out this site: http://www.pinvoke.net/ 

Check out this site (Calling VB6 from .NET): http://www.vb-helper.com/howto_net_use_vb6_dll.html

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags: | Posted by blockwood on 4/9/2010 2:22 AM | Comments (0)

g'day everyone.

These are some course files that we worked on.  what I would like to call experiments! ie not in the book, thus not named very well so I apologize for that.

Here they all are in one zip file:

ProgInVB.zip (1,000.94 kb)

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5