Can someone translate this to vb.net?

  • Thread starter Thread starter raz230
  • Start date Start date
R

raz230

I'm sorry for posting this here-

I have to integrate an parcel tracking with Canada Post into one of my
applications. The web service they use is made with SAP and is not
the usual WSDL type of service I am used to. I cannot just add a web
reference to my project and get going.

Canada Post provides a sample in Java and C# - and I do not know
either.

If it's not too hard, is anyone able to translate this into VB.net?

static void Main(string[] args)
{
try
{
WebReference.ZWBRAND_REQUESTEDPINS_LN[] requestPins = new
WebReference.ZWBRAND_REQUESTEDPINS_LN[1];

requestPins[0]= new WebReference.ZWBRAND_REQUESTEDPINS_LN();

WebReference.ZDC_GET_HISTORYService tandtService = new
WebReference.ZDC_GET_HISTORYService();

NetworkCredential UserInfo= new NetworkCredential("MY USER ID", "MY
PASSWORD");

tandtService.Credentials=UserInfo;

//Populate Pin information
requestPins[0].PIN="CH000862116CA";
requestPins[0].FSA="";

//Set-up call and execute service
WebReference.ZWBRAND_CPCRESPONSE tandtResponse =
tandtService.ZDC_GET_HISTORY("N", requestPins, "1", "JKL", "Y");
//Get a handle on response pin information
WebReference.ZWBRAND_PINS_LN[] responsePins =
tandtResponse.PINS;
}
catch (Exception ex)
{
Console.WriteLine(ex.StackTrace);
}
}

Huge thanks and sorry if this is asking alot- I just have no clue
about C#...

Raz
 
raz230 said:
[...]
Can someone translate this to vb.net?

There are various translators that can automatically convert from C# to
VB.Net and viceversa. For example, the one at
http://www.developerfusion.co.uk/utilities/convertcsharptovb.aspx provides
this translation for your code fragment:


Shared Sub Main(ByVal args As String())
Try
Dim requestPins(1) As WebReference.ZWBRAND_REQUESTEDPINS_LN
requestPins(0) = New WebReference.ZWBRAND_REQUESTEDPINS_LN
Dim tandtService As WebReference.ZDC_GET_HISTORYService = New
WebReference.ZDC_GET_HISTORYService
Dim UserInfo As NetworkCredential = New NetworkCredential("MY USER ID",
"MY PASSWORD")
tandtService.Credentials = UserInfo
requestPins(0).PIN = "CH000862116CA"
requestPins(0).FSA = ""
Dim tandtResponse As WebReference.ZWBRAND_CPCRESPONSE =
tandtService.ZDC_GET_HISTORY("N", requestPins, "1", "JKL", "Y")
Dim responsePins As WebReference.ZWBRAND_PINS_LN() = tandtResponse.PINS
Catch ex As Exception
Console.WriteLine(ex.StackTrace)
End Try
End Sub
 
The other conversion will not work - array declarations use the upper bound
in VB, while C# uses length (these are always 1-off).

(the following is produced by Instant VB):
Shared Sub Main(ByVal args As String())
Try
Dim requestPins As WebReference.ZWBRAND_REQUESTEDPINS_LN() = New
WebReference.ZWBRAND_REQUESTEDPINS_LN(0){}

requestPins(0)= New WebReference.ZWBRAND_REQUESTEDPINS_LN()

Dim tandtService As WebReference.ZDC_GET_HISTORYService = New
WebReference.ZDC_GET_HISTORYService()

Dim UserInfo As NetworkCredential= New NetworkCredential("MY USER ID", "MY
PASSWORD")

tandtService.Credentials=UserInfo

'Populate Pin information
requestPins(0).PIN="CH000862116CA"
requestPins(0).FSA=""

'Set-up call and execute service
Dim tandtResponse As WebReference.ZWBRAND_CPCRESPONSE =
tandtService.ZDC_GET_HISTORY("N", requestPins, "1", "JKL", "Y")
'Get a handle on response pin information
Dim responsePins As WebReference.ZWBRAND_PINS_LN() = tandtResponse.PINS
Catch ex As Exception
Console.WriteLine(ex.StackTrace)
End Try
End Sub

--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
C++ to C# Converter: converts C++ to C#
Instant C++: converts C# or VB to C++/CLI
 
[...]
Can someone translate this to vb.net?

There are various translators that can automatically convert from C# to
VB.Net and viceversa. For example, the one athttp://www.developerfusion.co.uk/utilities/convertcsharptovb.aspxprovides
this translation for your code fragment:

Shared Sub Main(ByVal args As String())
Try
Dim requestPins(1) As WebReference.ZWBRAND_REQUESTEDPINS_LN
requestPins(0) = New WebReference.ZWBRAND_REQUESTEDPINS_LN
Dim tandtService As WebReference.ZDC_GET_HISTORYService = New
WebReference.ZDC_GET_HISTORYService
Dim UserInfo As NetworkCredential = New NetworkCredential("MY USER ID",
"MY PASSWORD")
tandtService.Credentials = UserInfo
requestPins(0).PIN = "CH000862116CA"
requestPins(0).FSA = ""
Dim tandtResponse As WebReference.ZWBRAND_CPCRESPONSE =
tandtService.ZDC_GET_HISTORY("N", requestPins, "1", "JKL", "Y")
Dim responsePins As WebReference.ZWBRAND_PINS_LN() = tandtResponse.PINS
Catch ex As Exception
Console.WriteLine(ex.StackTrace)
End Try
End Sub

Perfect - thanks very much!
 
Back
Top