[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Upgrading Prog. from VB6 to VB.net

Posted on 2004-04-05
11
Medium Priority
?
645 Views
Last Modified: 2007-12-19
Hi,

I am upgrading some code from VB6 to vb.net , cant seem to figure out how to get it to do the same as it did previosly using the try catch and finally, and with the same errors as the exception.

Public Function Send(ByVal objMessage As CMessage) As CResponse

On Error GoTo Handler
            
      ' Declare HTTP object, so that we can send the XML over HTTP to the server
        Dim objHTTP As MSXML2.XMLHTTP30
        objHTTP = New MSXML2.XMLHTTP30

   

        Dim objResponse As CResponse
        objResponse = New CResponse


        ' Initialise the HTTP request to use the POST method and be Async
        objHTTP.open("POST", mstrURL, False, mstrUsername, mstrPassword)
        Dim strXYZ As String
        'objHTTP.Send strXYZ
        If (objMessage.TransmissionFormat = CMessage.MessageTransmissionFormat.FORMAT_HTML) Then
            objHTTP.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
        Else
            objHTTP.setRequestHeader("Content-Type", "text/xml")
        End If

        objHTTP.send(objMessage.GetMessageForTransmission) ' send our XML doc to the gateway

        ' Assign the status code, status text and the return data to the function
        objResponse.HTTPStatus = CStr(objHTTP.status)
        objResponse.HTTPStatusText = objHTTP.statusText

        objResponse.ResponseText(objHTTP.responseText) = objMessage.TransmissionFormat
        'objResponse.XML = objHTTP.responseXML



        Send = objResponse

        ' Set scope of objects to nothing
        'UPGRADE_NOTE: Object objHTTP may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="vbup1029"'
        objHTTP = Nothing
        Exit Function

Handler:
        Dim lErrNumber As Integer
        Dim strErrSource As String
        Dim strErrDesc As String

        lErrNumber = Err.Number
        strErrDesc = Err.Description
        strErrSource = Err.Source

        On Error GoTo Handler2

        objResponse.State = CSubmissionProcessor.SubmissionState.SS_ERROR


        Select Case lErrNumber
            Case -2146697211 ' This denotes the message could not be sent
                objResponse.StateText = "The message could not be sent.  This may mean that the Gateway server is currently offline or that the URL is incorrect."
                Send = objResponse

            Case -2146697208 ' internal MSXML3 Automation error
                ' This error sometimes occurs when the server certificate cannot be trusted
                Send = UntrustedCertificateResend(objMessage)

            Case Else
                objResponse.StateText = lErrNumber & ": " & strErrDesc
                Err.Raise(lErrNumber, strErrSource, strErrDesc)
        End Select
        Exit Function

Handler2:
        Err.Raise(Err.Number, Err.Source, Err.Description)
            
      End Function
0
Comment
Question by:sam5705
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
11 Comments
 
LVL 96

Assisted Solution

by:Bob Learned
Bob Learned earned 375 total points
ID: 10759535
Are you trying to figure out how to put in the Try...Catch block code here?

Bob
0
 

Author Comment

by:sam5705
ID: 10761816
It's not that so much, but trying to trap the same error messages using the catch part
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 375 total points
ID: 10765138
This looks like you are still using a COM library for XML/HTTP support.  Did you want to stick with this, or change to ASP.NET?  If you go with the COM XML library, then you won't be able to trap the error messages using any kind of special exceptions.

Bob
0
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 

Author Comment

by:sam5705
ID: 10767464
Hi,

what I'm trying to do is create a windows service using vb.net. That parts not to bad. I guess what I am really asking , is by upgrading the code from VB6 to Vb.Net can I still catch the same error messages. Ie under the catch part which type of exception do I catch. Has MSXML got error messages that  I can capture in the more structured way.Or if I capture all exceptions how do then ascertain which error number actually happened - I guess I'm a bit confused about exceptions.
Many Thanks
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 10767801
First of all, in .NET you have special exceptions:  System.Data.SqlClient.SqlException, System.IO.FileNotFoundException, System.ArithmeticException, System.DivideByZeroException, etc..  You will notice, if you look in the help file, that these classes all have the same base (System.Exception).  What each one does is take the standard exception as a base, and build on it special information about exceptions.  These classes are part of the .NET framework.  

MSXML is a COM library, and which doesn't fit into the exception handling that .NET has.  Unfortunately, the type of handling that you want may not be possible in the structured Try...Catch...End Try paradigm.  The Exception class does not support error numbers AFAIK.  

That is why I asked if you could go away from migrating this code, and actually starting with the XML/HTTP support that .NET has.  Then you could try to think about the structure exception handling.

Bob
0
 

Author Comment

by:sam5705
ID: 10767970
Thats great, I think thats why I was getting myself in  a bit of a twist!
If I did change to the .net paradigm what classes would I use to do the same thing, from a vb.net service environment?
Many Thanks
0
 
LVL 96

Assisted Solution

by:Bob Learned
Bob Learned earned 375 total points
ID: 10768022
I am just learning all of this with HTTP/XML.  I have a good handle on exceptions.  If you will be patient with me, I will try to give you as much information as I know.

Bob
0
 

Author Comment

by:sam5705
ID: 10768343
Thats great, I'll try and look some stuff up as well, although a lot of it seems targetted from an ASP .net view point, and less from a windows service point.
Thanks
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 10768395
I think what you will need will be the System.Web.HttpRequest class, with HttpRequest.HttpMethod = "POST".  Even though it is in the System.Web namespace, you can still use outside of the ASP.NET realm.

Bob
0
 
LVL 12

Expert Comment

by:farsight
ID: 10768429
I, too, recommend using .NET's support for retrieving HTML.

But, if you stick with those COM objects, you could probably use GetLastWin32Error() to get the error information you need for your catch block.  Search for some online articles on that for more details.  (I have no direct experience with this, just the theory from reading.)

--- quoted from the VS.NET 2003 object browser ---

Public Shared Function GetLastWin32Error() As Integer
     Member of: System.Runtime.InteropServices.Marshal

Summary:
 Returns the error code returned by the last unmanaged function called using platform invoke that has the System.Runtime.InteropServices.DllImportAttribute.SetLastError flag set.  

Return Values:
The last error code set by a call to the Win32 SetLastError API method.  
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question