• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 345
  • Last Modified:

convert vb.net to C#

I know little to nothing about C# and I need to convert the code below from vb.net to C#.

Imports VinPower

        Dim VP As VinPower.VP
        VP = New VinPower.VP("Data source=C:\WebSites\CharityDis\vp_demo.cdb;New=False;Compress=False;Synchronous=Off;UTF8Encoding=True;Version=3")

        Dim success As Boolean
        Dim data As String
        success = False

        success = VP.DecodeVIN("1FA0P74W0Y", False, False, False)
        Textbox7.text = success

        If success Then
            data = ""
            Textbox1.text = VP.get_ModelYear()
            Textbox2.text  = VP.get_Make()
            Textbox3.text = VP.get_Model()
            Textbox4.text  = VP.get_BodyType()
        Else
            data = "Vin Auto Fill failure" & " : " & VP.get_LastError()
        End If
0
larrystewart
Asked:
larrystewart
2 Solutions
 
PHDCommented:
using VinPower

VinPower.VP VP;
VP = VinPower.VP("Data source=C:\WebSites\CharityDis\vp_demo.cdb;New=False;Compress=False;Synchronous=Off;UTF8Encoding=True;Version=3");

Boolean success;
String data;
success = False;
success = VP.DecodeVIN("1FA0P74W0Y", False, False, False);
if (success)
{
   data = ""
            Textbox1.text = VP.get_ModelYear();
            Textbox2.text  = VP.get_Make();
            Textbox3.text = VP.get_Model();
            Textbox4.text  = VP.get_BodyType();

}
else
{
data = "Vin Auto Fill failure" + " : " + VP.get_LastError();
}
0
 
PHDCommented:
I forgot the ; in "using VinPower" at the beginning

each line of code have ";" at the end.
c# is case sensitive.
declaration is like this : String data;
block are encapsulated with { }

You also have to put the statement in the right place ...

Hope this help
0
 
lorelogicCommented:
This should work for you:

using VinPower;

        VinPower.VP VP;
        VP = new VinPower.VP("Data source=C:\WebSites\CharityDis\vp_demo.cdb;New=False;Compress=False;Synchronous=Off;UTF8Encoding=True;Version=3");

        Boolean success;
        String data;
        success = false;

        success = VP.DecodeVIN(("1FA0P74W0Y", False, False, False);
        TextBox7.Text = success;

        if (success)
            {
                data = string.Empty;
            Textbox1.text = VP.get_ModelYear();
                  Textbox2.text  = VP.get_Make();
                  Textbox3.text = VP.get_Model();
                  Textbox4.text  = VP.get_BodyType();

            }
            else
                data = "Vin Auto Fill failure" & " : " & VP.get_LastError();
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
larrystewartAuthor Commented:
Thanks for your response. I am getting the following error, if you can help great, if not I will accept you solution and move on.

Error      6      'VinPower.VP' is a 'type', which is not valid in the given context
0
 
lorelogicCommented:
The Instance variable VP might be getting mixed up with the class variable VinPower.VP. Try using a different name for the instance variable such as :

using VinPower;

        VinPower.VP VPTest;
        VPTest = new VinPower.VP("Data source=C:\WebSites\CharityDis\vp_demo.cdb;New=False;Compress=False;Synchronous=Off;UTF8Encoding=True;Version=3");

Boolean success;
        String data;
        success = false;

        success = VPTest.DecodeVIN(("1FA0P74W0Y", False, False, False);

etc........
0
 
drichardsCommented:
Also, the string used in the VP constructor needs either an '@' in front (@"Data Source=C:\WebSites...") or the '\' characters need to be doubled up ("Data Source=C:\\WebSites\\...") and '&' is not a string concatenation operator - PHD correctly uses '+'.

0

Featured Post

Microsoft Certification Exam 74-409

VeeamĀ® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now