By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,537 Members | 881 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,537 IT Pros & Developers. It's quick & easy.

converting C# to VB problem

P: 2
Hello, I have this code in C# and it works perfect:

protected string GetUniqueName(string filename) {
string temp = filename;

for (int x=1; System.IO.File.Exists(temp); x++){
temp = filename.Substring(0, filename.LastIndexOf(".")) + x + filename.Substring(filename.LastIndexOf("."));
}
return new System.IO.FileInfo(temp).Name;
}

Then I converted it to VB:

Protected Function GetUniqueName(ByVal filename As String) As String
Dim temp As String = filename
Dim x As Integer = 1
While System.IO.File.Exists(temp)
temp = filename.Substring(0, filename.LastIndexOf(".")) + x + filename.Substring(filename.LastIndexOf("."))
System.Math.Min(System.Threading.Interlocked.Incre ment(x), x - 1)
End While
Return (New System.IO.FileInfo(temp)).Name
End Function

Now I am getting an error:

Input string was not in a correct format.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.FormatException: Input string was not in a correct format.

Source Error:

Line 303: Dim x As Integer = 1
Line 304: While System.IO.File.Exists(temp)
Line 305: temp = filename.Substring(0, filename.LastIndexOf(".")) + x + filename.Substring(filename.LastIndexOf("."))
Line 306: System.Math.Min(System.Threading.Interlocked.Incre ment(x), x - 1)
Line 307: End While

Source File: D:\wwwroot\www.yourkinetico.com\wwwroot\AdPlanner\ App_Code\Utils\Upload.vb Line: 305

Stack Trace:

[FormatException: Input string was not in a correct format.]
Microsoft.VisualBasic.CompilerServices.Conversions .ParseDouble(String Value, NumberFormatInfo NumberFormat) +211
Microsoft.VisualBasic.CompilerServices.Conversions .ToDouble(String Value, NumberFormatInfo NumberFormat) +74


Any help would be greatly appreciated!
May 23 '07 #1
Share this Question
Share on Google+
1 Reply


bartonc
Expert 5K+
P: 6,596
This topic received much discussion here.
May 23 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.