|
|
|
A SearchVB Member asks, "I am busy developing a Web application using
Member Josh Parks submits this week's featured code. "Allows you to
DESIGNING A VB.NET APPLICATION This week's featured article shows not only how to implement a Web
Windows & .NET Magazine
Using Automation (ActiveX/COM) Objects in ASP.NET
Building a Fully Functional DataGrid
Recalculating Column Values in DataGrid
NET Anatomy: Creating Templated DataGrid Controls Using Visual Studio
Data Binding Custom Classes
How To Fix Web Services Going Though Firewalls
Opening Child Windows Using Server Side Controls
Threading Part 4
Building a Master/Detail DataGrid for Database Inserts
How to Change the IP Address of the Local Machine Using VB .NET
How To Highlight a DataGrid Row
How To Generate PDF Files Dynamically Using ASP.NET
Microsoft Jaggled by Cap Gemini Ernst & Young Framework!
Quiksoft Offers Free .Net E-Mail Component
ASP.NET Validation Controls Samples For Beginners
NEW .NET SOURCE CODE - FlashLight - Flash Server Control v1.0
.NET
- Choosing Among File I/O Options in Visual Basic .NET
Windows
Office
Voices
HOW TO: Enable Replication Agents for Logging to Output Files in SQL Server
(Q312292)
HOW TO: Set Up and Troubleshoot a Linked Server to Oracle in SQL Server
(Q280106)
INF: How To Transfer Logins and Passwords Between SQL Servers (Q246133)
MICROSOFT GULF COAST MSDN SEMINARS
The .NET platform makes it easy to use XSLT to transform XML into a variety of structures. Here's how to use managed classes in the .NET base class library to transform XML into HTML. [Read More]
5
Page Template Tips
When
Web Services Don't Make Sense
Test
Web Services Without Writing a Client
Provide
Rich Functionality With Server Controls
Build
a Forum Using ADO.NET
by Francesco Balena (fbalena@vb2themax.com) Excerpt from Chapter 16 of "Programming Microsoft Visual Basic .NET" (Microsoft Press) The ThreadException of the Application event lets you leverage a very powerful feature of the Windows Forms package, so it deserves a section of its own. To understand why this feature is so important, let's review what happens when an unhandled error occurs inside an event routine. In normal circumstances, the exception would be passed to the caller code, but an event procedure has no caller, so errors of this kind terminate the application. Visual Basic 6 developers are well aware of this issue, and in fact are inclined to liberally furnish all event procedures with On Error statements. This technique is ugly and tends to decrease performance, but it's the only one that ensures a sufficient level of robustness. The Application.ThreadException event fires whenever an unhandled exception is thrown on the current thread, so you can easily write a global error handler that protects all your forms from any unhandled errors. Your global handler can ignore the error, log it to a file, display a message box that asks the end user whether he or she wants to abort the application, send an e-mail to the tech support group, and any other action you deem desirable. To implement this feature correctly, you must use a Sub Main procedure as the startup object of your application and you must mark it with the STAThread attribute to set the threading model of the application to Single Thread Apartment (STA) mode. After you set up the ThreadException event, you can start the main form by using an Application.Run method, as shown in the following code: Module MainModule
<STAThread()> _
Sub Main()
' Install the event handler.
AddHandler Application.ThreadException, _
AddressOf Application_ThreadException
' Run the startup form.
Application.Run(New ApplicationForm())
End Sub
' This is the global error handler.
Sub Application_ThreadException(ByVal sender As Object, _
ByVal e As System.Threading.ThreadExceptionEventArgs)
Try
' Prepare an informative message.
Dim msg As String = _
String.Format _
("An error has occurred:{0}{0}{1}{0}{0}{2}", _
ControlChars.Cr, e.Exception.Message, _
e.Exception.StackTrace)
' Display it, asking whether the application _
should terminate.
Dim result As DialogResult = _
MessageBox.Show(msg, "Application Error", _
MessageBoxButtons.AbortRetryIgnore, _
MessageBoxIcon.Error)
' End the application if the end user said so.
If result = DialogResult.Abort Then
Application.Exit()
End If
Catch
' If the message box couldn't be displayed _
(presumably because
' the Exception object wasn't available, _
try with a simpler
' one, and then close the application anyway.
'
Try
MessageBox.Show _
("The application will be terminated", _
"Fatal Error", _
MessageBoxButtons.OK, MessageBoxIcon.Error)
Finally
Application.Exit()
End Try
End Try
End Sub
End Module
The global error handler serves all the unhandled exceptions of your
application, including the most critical ones. For this reason, the code inside
the handler should account for exceptional conditions--for example, the case
when the e.Exception object isn't available or when it isn't possible to display
a message box. (In the latter case, you might want to log the error to the
system log or to a bug report file.)An important note: this feature clashes with Visual Studio debugger, and global error handlers don't work well when the application runs inside Visual Studio. To see it in action, you should run the program using the Start Without Debugging command in the Debug menu (which corresponds to the Ctrl-F5 key), or run it from Windows Explorer or the command prompt.
Last issue's VB.NET Watcher column contained a routine that dumps the stack contents when an exception is throw; you just pass an Exception object to it and the routine prints name and other information about the call stack in the moment when the exception was thrown. Eddie Butt of London Life Insurance improved the routine to display the name of parameters passed to each routine (but not their value, which can't be obtained through reflection). Here's the improved version: ' The following routine requires the following Imports statements
' Imports System
' Imports System.Reflection
' A reusable routine that displays error information
Sub DisplayExceptionInfo(ByVal e As Exception)
' Display the error message.
Console.WriteLine(e.Message)
Dim st As New StackTrace(e, True)
Dim i As Integer
For i = 0 To st.FrameCount - 1
' Get the i-th stack frame.
Dim sf As StackFrame = st.GetFrame(i)
' Get the corresponding method for that stack frame.
Dim mi As MemberInfo = sf.GetMethod
' Get the namespace where that method is defined.
Dim res As String = mi.DeclaringType.Namespace & "."
' Append the type name.
res &= mi.DeclaringType.Name & "."
' Append the name of the method.
res &= mi.Name
Dim objParameters() As ParameterInfo = _
sf.GetMethod.GetParameters()
Dim objParameter As ParameterInfo
Dim strParameterString As String = ""
strParameterString &= "("
For Each objParameter In objParameters
'Only add commas if there are more than one parameter
' (default length of 0 plus the opening parenthesis = 1).
If strParameterString.Length <> 1 Then
strParameterString &= ", "
End If
strParameterString &= objParameter.Name & " As " & _
objParameter.ParameterType.Name
Next
strParameterString &= ")"
res &= strParameterString
' Append information about the position in source file
' (but only if Debug information is available).
If sf.GetFileName <> "" Then
res &= " (" & sf.GetFileName & ", Line " & _
sf.GetFileLineNumber & ", Col " & _
sf.GetFileColumnNumber
End If
' Append information about offset in MSIL code, if available.
If sf.GetILOffset <> StackFrame.OFFSET_UNKNOWN Then
res &= ", IL offset " & sf.GetILOffset.ToString
End If
' Append information about offset in native code.
res &= ", native offset " & sf.GetNativeOffset & ")"
Console.WriteLine(res)
Next
End Sub
by A. Russell Jones Although .NET's Windows Forms ListBox control has extended capabilities, it can be problematic when attempting some of the simplest things. This article demonstrates how the use of delegates can help you achieve near-total control. (from the .NET Zone)
by Stan Schultes Extend a VB Collection object by building a collection class around it to manage the display configuration of columns in a data grid. Then, load and store column display settings from an application INI using code you can add to your own apps.
Knowledge Base Articles to Get
Started with VB.NET
Usually in your application you use two different types of lookup queries; the first one is for retrieving a page of records (or all records) to populate a pick list, the other one is to retrieve a single record, i.e. for decoding a code description while a user is typing it in a textbox. So, if your queries are dynamically configured and are stored in a DB, you must duplicate the list of query statements. So you'll use it in the first situation, a query such as: SELECT * FROM PUBLISHERSIn the other situation you'll use a query like: SELECT * FROM PUBLISHERS WHERE COUNTRY = ?But you can use just one query structured in dual mode: SELECT * FROM PUBLISHERS WHERE (COUNTRY = ? OR 1 = ?)When you want to populate a pick list you'll pass to the second parameter simply a 1 and all records will be retrieved. When you want to decode a single value, you must pass the code to the first parameter and a 0 to the second one. So, if all your queries use always one parameter to decode value, you can write a standard (dual) lookup routine like this: Dim lConn As ADODB.Connection Dim lCmd As ADODB.Command Dim lRs As ADODB.Recordset Dim lParAllRecords as Long Dim lParSingleRecord as Long Set lConn = New ADODB.Connection lConn.Open "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=PUBS;Data Source=(local)" lConn.CursorLocation = adUseClient Set lCmd = New ADODB.Command Set lCmd.ActiveConnection = lConn lCmd.CommandText = txtStatement.Text 'if you want all records: lParAllRecords = 1 lParSingleRecord = 0 'not important in the first use 'if you want a single record: lParAllRecords = 0 lParSingleRecord = "Germany" 'the correct value to retrieve one record lCmd.Parameters(0).Value = lParSingleRecord lCmd.Parameters(1).Value = lParAllRecords Set lRs = lCmd.Execute
By Roger Johansson You can extract RGB values out of a 32-bit color value by using the integer division and the MOD operators, but there is a much more effective way, based on the LSet. You can convert from a Long to RGB bytes and vice versa with the following code: Private Type RGBWrapper Red As Byte Green As Byte Blue As Byte Alpha As Byte End Type Private Type LONGWrapper Value As Long End Type Private Sub Form_Load() Dim Color As LONGWrapper Dim Colors As RGBWrapper Color.Value = RGB(255, 123, 55) LSet Colors = Color 'do the actual conversion MsgBox Colors.Red MsgBox Colors.Green MsgBox Colors.Blue End Sub
|
|
Send mail to vblg@xocomp.net
with questions or comments about this web site. Copyright © 1998-2003 XOCOMP, llc Last modified: 05/07/2002 |