Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Converted VB.NET to C# With Error

Converted VB.NET to C# With Error

Scheduled Pinned Locked Moved C#
csharphelpquestionlearning
6 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    daveofgv
    wrote on last edited by
    #1

    I am a VB.NET Programmer learning C#. One of my applications I transfered over to C# via an online converion tool. I am receiving an error which I do not see why it's causing an error. What I have now is:

    try {

    		if (System.IO.File.Exists(srcedest) == false) {
    			//My.Computer.FileSystem.RenameFile((dest), newName:=sheet.Cells(row, 14).value & "\_" & sheet.Cells(row, 15).value)
                My.Computer.FileSystem.RenameFile((dest), newName) sheet.Cells(row, 1).value;
    			// & "\_" & sheet.Cells(row, 2).value & "\_" & sheet.Cells(row, 3).value)
    
    		}
    
    	} catch (Exception ex) {
    		txtLog3.AppendText(sheet.Cells(row, 1).value);
    		// & "\_" & sheet.Cells(row, 3).value & vbCrLf)
    	}
    

    With the error of "expecting ;" at the "sheet" in My.Computer.FileSystem.RenameFile((dest), newName) sheet.Cells(row, 1).value; Why would this cause an error since you don't put a ";" until the end of a statement? Thanks in advanced. daveofgv

    P P B G 4 Replies Last reply
    0
    • D daveofgv

      I am a VB.NET Programmer learning C#. One of my applications I transfered over to C# via an online converion tool. I am receiving an error which I do not see why it's causing an error. What I have now is:

      try {

      		if (System.IO.File.Exists(srcedest) == false) {
      			//My.Computer.FileSystem.RenameFile((dest), newName:=sheet.Cells(row, 14).value & "\_" & sheet.Cells(row, 15).value)
                  My.Computer.FileSystem.RenameFile((dest), newName) sheet.Cells(row, 1).value;
      			// & "\_" & sheet.Cells(row, 2).value & "\_" & sheet.Cells(row, 3).value)
      
      		}
      
      	} catch (Exception ex) {
      		txtLog3.AppendText(sheet.Cells(row, 1).value);
      		// & "\_" & sheet.Cells(row, 3).value & vbCrLf)
      	}
      

      With the error of "expecting ;" at the "sheet" in My.Computer.FileSystem.RenameFile((dest), newName) sheet.Cells(row, 1).value; Why would this cause an error since you don't put a ";" until the end of a statement? Thanks in advanced. daveofgv

      P Offline
      P Offline
      PIEBALDconsult
      wrote on last edited by
      #2

      Dunno, maybe remove the newName) and stick a ) just before the ; ?

      L 1 Reply Last reply
      0
      • P PIEBALDconsult

        Dunno, maybe remove the newName) and stick a ) just before the ; ?

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        Apparently, I can only report you. Spam or Abusive. The new UI must be a huge success, if it's causing the hamsters so much overtime.

        Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] They hate us for our freedom![^]

        1 Reply Last reply
        0
        • D daveofgv

          I am a VB.NET Programmer learning C#. One of my applications I transfered over to C# via an online converion tool. I am receiving an error which I do not see why it's causing an error. What I have now is:

          try {

          		if (System.IO.File.Exists(srcedest) == false) {
          			//My.Computer.FileSystem.RenameFile((dest), newName:=sheet.Cells(row, 14).value & "\_" & sheet.Cells(row, 15).value)
                      My.Computer.FileSystem.RenameFile((dest), newName) sheet.Cells(row, 1).value;
          			// & "\_" & sheet.Cells(row, 2).value & "\_" & sheet.Cells(row, 3).value)
          
          		}
          
          	} catch (Exception ex) {
          		txtLog3.AppendText(sheet.Cells(row, 1).value);
          		// & "\_" & sheet.Cells(row, 3).value & vbCrLf)
          	}
          

          With the error of "expecting ;" at the "sheet" in My.Computer.FileSystem.RenameFile((dest), newName) sheet.Cells(row, 1).value; Why would this cause an error since you don't put a ";" until the end of a statement? Thanks in advanced. daveofgv

          P Offline
          P Offline
          Pete OHanlon
          wrote on last edited by
          #4

          //My.Computer.FileSystem.RenameFile((dest), newName:=sheet.Cells(row, 14).value & "_" & sheet.Cells(row, 15).value)
          My.Computer.FileSystem.RenameFile((dest), newName) sheet.Cells(row, 1).value;

          Your second line isn't the same as the first one. The reason is down to the fact that in the VB line, it's attempting to put sheet.Cells(row,1).value into the optional parameter newName. In your version, you don't do that - so the statement ends after the call to RenameFile.

          *pre-emptive celebratory nipple tassle jiggle* - Sean Ewington

          "Mind bleach! Send me mind bleach!" - Nagy Vilmos

          CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

          1 Reply Last reply
          0
          • D daveofgv

            I am a VB.NET Programmer learning C#. One of my applications I transfered over to C# via an online converion tool. I am receiving an error which I do not see why it's causing an error. What I have now is:

            try {

            		if (System.IO.File.Exists(srcedest) == false) {
            			//My.Computer.FileSystem.RenameFile((dest), newName:=sheet.Cells(row, 14).value & "\_" & sheet.Cells(row, 15).value)
                        My.Computer.FileSystem.RenameFile((dest), newName) sheet.Cells(row, 1).value;
            			// & "\_" & sheet.Cells(row, 2).value & "\_" & sheet.Cells(row, 3).value)
            
            		}
            
            	} catch (Exception ex) {
            		txtLog3.AppendText(sheet.Cells(row, 1).value);
            		// & "\_" & sheet.Cells(row, 3).value & vbCrLf)
            	}
            

            With the error of "expecting ;" at the "sheet" in My.Computer.FileSystem.RenameFile((dest), newName) sheet.Cells(row, 1).value; Why would this cause an error since you don't put a ";" until the end of a statement? Thanks in advanced. daveofgv

            B Offline
            B Offline
            Bernhard Hiller
            wrote on last edited by
            #5

            Using a parameter name followed by a := means that you create that variable on the fly and assign the value to it. Just think of two statements:

            string newName = sheet.Cells(row, 14).value + "_" + sheet.Cells(row, 15).value);
            My.Computer.FileSystem.RenameFile(dest, newName);

            1 Reply Last reply
            0
            • D daveofgv

              I am a VB.NET Programmer learning C#. One of my applications I transfered over to C# via an online converion tool. I am receiving an error which I do not see why it's causing an error. What I have now is:

              try {

              		if (System.IO.File.Exists(srcedest) == false) {
              			//My.Computer.FileSystem.RenameFile((dest), newName:=sheet.Cells(row, 14).value & "\_" & sheet.Cells(row, 15).value)
                          My.Computer.FileSystem.RenameFile((dest), newName) sheet.Cells(row, 1).value;
              			// & "\_" & sheet.Cells(row, 2).value & "\_" & sheet.Cells(row, 3).value)
              
              		}
              
              	} catch (Exception ex) {
              		txtLog3.AppendText(sheet.Cells(row, 1).value);
              		// & "\_" & sheet.Cells(row, 3).value & vbCrLf)
              	}
              

              With the error of "expecting ;" at the "sheet" in My.Computer.FileSystem.RenameFile((dest), newName) sheet.Cells(row, 1).value; Why would this cause an error since you don't put a ";" until the end of a statement? Thanks in advanced. daveofgv

              G Offline
              G Offline
              GREG_DORIANcod
              wrote on last edited by
              #6

              Try to change to this line My.Computer.FileSystem.RenameFile((dest), newName = sheet.Cells[row, 14].value + "_" + sheet.Cells[row, 15].value)

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups