Converted VB.NET to C# With Error
-
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
-
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
Dunno, maybe remove the
newName)
and stick a)
just before the;
? -
Dunno, maybe remove the
newName)
and stick a)
just before the;
?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![^]
-
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
//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
-
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
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); -
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
Try to change to this line My.Computer.FileSystem.RenameFile((dest), newName = sheet.Cells[row, 14].value + "_" + sheet.Cells[row, 15].value)