locked
Convert vb to c# RRS feed

  • Question

  • I try to convert the following code to c# but then I could not figure it out what the "MAL" doing in the code itself. Can anobody show me how to convert this code to c#.

    If Dir(Inputfile) <> "" Then
    Kill(TextFile (1))
    Call Shell(My.Application.Info.DirectoryPath & "\MC300TSFConv.exe MAL" & InputFile & ""  & OutputFile, AppwinStyle.NormalFocus)
    if frmConfig.Check1.Checkstate = CheckState.Checked Then
    FileCopy (TextFIle(5) & arr , TextFile(7) & "archive_" & arr)
    end if
    end if

    Friday, March 29, 2013 8:29 AM

Answers

  • Hi Khushairy,

    It seems "MAL" is just a input parameter to MC300TSFConv.exe. Below is equivalent C# code for above

    if (!string.IsNullOrEmpty(FileSystem.Dir(Inputfile)))

    {

    FileSystem.Kill(TextFile(1));

    Interaction.Shell(My.Application.Info.DirectoryPath + "\\MC300TSFConv.exe MAL" + InputFile + "" + OutputFile, AppWinStyle.NormalFocus);

    if (frmConfig.Check1.Checkstate == CheckState.Checked)

    {

    FileSystem.FileCopy(TextFIle(5) + arr, TextFile(7) + "archive_" + arr);

    }

    }

    Now a days, it's very easy to convert code from VB.NET to C# and vice versa, as these are the very common programming languages. There are some online convertors availbale who does this job in blink of eyes. Below is one example.

    http://www.developerfusion.com/tools/convert/vb-to-csharp/

    Hope, this will help you out. Feel free to contact in case of query.


    If this post answers your question, please click Mark As Answer. If this post is helpful please click Mark as Helpful.

    • Proposed as answer by Tejas T Sunday, March 31, 2013 12:46 PM
    • Marked as answer by Jason Dot Wang Monday, April 8, 2013 8:38 AM
    Friday, March 29, 2013 8:45 AM
  • OMG Im so dumb. Got it solved in a few lines. Thank you for your co-operation. Below is the working code.

    string appDomain = AppDomain.CurrentDomain.BaseDirectory + "\\MC300TSFConv.exe";
    string InputFile = "C:\\input.std";
    string OutputFile = "C:\\output.std";
    Process.Start(appDomain, ("MAL" +" "+ InputFile +" "+ OutputFile)); 

    • Marked as answer by khushairy Monday, April 1, 2013 7:46 AM
    Monday, April 1, 2013 7:46 AM

All replies

  • if (Dir(Inputfile) != string.Empty) 
    {
        Kill(TextFile(1));
        
        Shell(My.Application.Info.DirectoryPath + "\MC300TSFConv.exe MAL" + InputFile + ""  + OutputFile, AppwinStyle.NormalFocus);
        
        if (frmConfig.Check1.Checkstate == CheckState.Checked)
        {
            FileCopy(TextFIle(5) + arr , TextFile(7) + "archive_" + arr);
        }
    }


    Regards,

    Eyal Shilony

    Friday, March 29, 2013 8:44 AM
  • Hi Khushairy,

    It seems "MAL" is just a input parameter to MC300TSFConv.exe. Below is equivalent C# code for above

    if (!string.IsNullOrEmpty(FileSystem.Dir(Inputfile)))

    {

    FileSystem.Kill(TextFile(1));

    Interaction.Shell(My.Application.Info.DirectoryPath + "\\MC300TSFConv.exe MAL" + InputFile + "" + OutputFile, AppWinStyle.NormalFocus);

    if (frmConfig.Check1.Checkstate == CheckState.Checked)

    {

    FileSystem.FileCopy(TextFIle(5) + arr, TextFile(7) + "archive_" + arr);

    }

    }

    Now a days, it's very easy to convert code from VB.NET to C# and vice versa, as these are the very common programming languages. There are some online convertors availbale who does this job in blink of eyes. Below is one example.

    http://www.developerfusion.com/tools/convert/vb-to-csharp/

    Hope, this will help you out. Feel free to contact in case of query.


    If this post answers your question, please click Mark As Answer. If this post is helpful please click Mark as Helpful.

    • Proposed as answer by Tejas T Sunday, March 31, 2013 12:46 PM
    • Marked as answer by Jason Dot Wang Monday, April 8, 2013 8:38 AM
    Friday, March 29, 2013 8:45 AM
  • Thanks guys,

    I am well aware of the converter existed out there. I tried few of them and a little modification is needed after the conversion. The problem for me here is that the "MAL" is stopping my application from running correctly.

    The compiler assumes that the "\\MC300BTSFConv.exe MAL" as a string here since im using the Process.Start to run the application instead of shell. Can anobody show me how to use the Process.Start correctly with the "MAL" as input paramater.

    Friday, March 29, 2013 9:06 AM
  • "Can anobody show me how to use the Process.Start correctly with the "MAL" as input paramater."

    Two people have already shown you.  Do you need more?  Here you go, I'll copy and paste from the first one.

    Shell(My.Application.Info.DirectoryPath + "\MC300TSFConv.exe MAL" + InputFile + ""  + OutputFile, AppwinStyle.NormalFocus);
        
     The MAL has nothing to do with VB or C# it is just input to the MC300TSFConv program and we have no idea what that does.


    Paul Linton

    Friday, March 29, 2013 9:21 AM
  • With Process.start you just pass separately the EXE file name and the argument: http://msdn.microsoft.com/en-us/library/h6ak8zt5.aspx My guess is that you are perhaps trying to use http://msdn.microsoft.com/en-us/library/53ezey2s.aspx that just expects the application or document file without any argument.

    Else be explicit about what is the problem you currently have. Do you have some kind of error message ?


    Please always mark whatever response solved your issue so that the thread is properly marked as "Answered".

    Friday, March 29, 2013 1:46 PM
  • Here is my conversion. I don't know where to insert the "MAL" into the code below. The code is working except for the output is empty. I figured that it has something to do with the "MAL" and the " " but don't know how to put them together to work.

    Process pro = new Process();
    pro.StartInfo.FileName = AppDomain.CurrentDomain.BaseDirectory + \\MC300TSFConv.exe;
    pro.StartInfo.Arguments = InputFile.std;
    pro.StartInfo.UseShellExecute = false;
    pro.StartInfo.RedirectStandardOutput = true;
    pro.StartInfo.CreateNoWindow = true;
    pro.Start();
    StreamReader readMC300 = pro.StandardOutput;
    string readOP = readMC300.ReadToEnd();
    StreamWriter writeOP = new StreamWriter(OutputFile.std);
    writeOP.WriteLine(readOP);
    writeOP.Close();
    readMC300.Close();
    pro.WaitForExit()

    Monday, April 1, 2013 7:32 AM
  • If you had a command prompt open and wanted to run this MC300TSFConv program, what would you type?  Forget about C# for the moment.  If you were running it manually, what would you type to get the output you are expecting?


    Paul Linton

    Monday, April 1, 2013 7:44 AM
  • OMG Im so dumb. Got it solved in a few lines. Thank you for your co-operation. Below is the working code.

    string appDomain = AppDomain.CurrentDomain.BaseDirectory + "\\MC300TSFConv.exe";
    string InputFile = "C:\\input.std";
    string OutputFile = "C:\\output.std";
    Process.Start(appDomain, ("MAL" +" "+ InputFile +" "+ OutputFile)); 

    • Marked as answer by khushairy Monday, April 1, 2013 7:46 AM
    Monday, April 1, 2013 7:46 AM