Click here to Skip to main content
15,904,935 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
public object My_D2sYMD(w_date)
{
	string Ret_Val = null;
	Ret_Val = n2s(Convert.ToDateTime(w_date).Year, 4) + n2s(Convert.ToDateTime(w_date).Month, 2) + n2s(Convert.ToDateTime(w_date).Day, 2);
	return Ret_Val;
}

public object n2s(float w, int n)
{
	string Ret_Val = null;
	Ret_Val = "0000000000" + w;
	Ret_Val = Ret_Val.Substring(Strings.Len(Ret_Val) - n, n);
	return Ret_Val;
}

private object Dt_mdy2ymd(string w_dt)
{
	return w_dt.Substring(6, 4) + w_dt.Substring(0, 2) + w_dt.Substring(3, 2);
}

private object Dt_YMD2DMY(string w_dt)
{
	if (Strings.Len(Strings.Trim(w_dt)) == 8) {
		return w_dt.Substring(6, 2) + "/" + w_dt.Substring(4, 2) + "/" + w_dt.Substring(0, 4);
	} else {
		return "";
	}
}

please check all these functions and provide solution so i can use these functions also in c# i convert these in c# using converter but they give some error msg like
Error	1	'System.Linq.Strings' is inaccessible due to its protection level	C:\Users\The Web Soluution\Documents\Visual Studio 2008\WebSites\WebSite2\App_Code\Class1.cs	23	37	C:\...\WebSite2\
Error	2	Operator '+' cannot be applied to operands of type 'object' and 'object'	C:\Users\The Web Soluution\Documents\Visual Studio 2008\WebSites\WebSite2\App_Code\Class1.cs	29	19	C:\...\WebSite2\
Error	3	'System.Linq.Strings' is inaccessible due to its protection level	C:\Users\The Web Soluution\Documents\Visual Studio 2008\WebSites\WebSite2\App_Code\Class1.cs	44	13	C:\...\WebSite2\

plz provide solution as soon as possible


[edit]Code block added - OriginalGriff[/edit]
Posted
Updated 30-Nov-13 23:07pm
v2

1 solution

Really?
Why did you convert these from VB without knowing what you were doing?

Let's look at some of this, shall we?

C#
public object n2s(float w, int n)
{
    string Ret_Val = null;
    Ret_Val = "0000000000" + w;
    Ret_Val = Ret_Val.Substring(Strings.Len(Ret_Val) - n, n);
    return Ret_Val;
}

1) Why does it return an object when it clearly should return a string?
2) Why are you converting to a fixed number of digits without checking if the number is actually larger or smaller than that number of digits? Or includes an exponent?
3) Why do you try to access Linq at all?
4) Why not just use .NET string formatting? If you look here http://msdn.microsoft.com/en-us/library/dd260048(v=vs.110).aspx[^] it shows you how to do it properly...

You can't just pick up old (pretty rubbish) VB6 code, and expect an online translator to turn it into good quality modern C# - it isn't going to happen.
 
Share this answer
 
Comments
UD(IA) 1-Dec-13 5:26am    
these function use because i want to store date and time according to me and these function change datatime as i need and i store date in database in varchar(8) and when i print i use funcation to add / and when i use from date.now() than it convert it into withoutslash and as according to me so plz tell me errors i can provide its vb format which work correctly is
Private Function Dt_mdy2ymd(ByVal w_dt As String)
Return w_dt.Substring(6, 4) & w_dt.Substring(0, 2) & w_dt.Substring(3, 2)
End Function
Function My_D2sYMD(ByVal w_date)
Dim Ret_Val As String
'If ValidateDate(w_date) Then
Ret_Val = n2s(Convert.ToDateTime(w_date).Year, 4) & n2s(Convert.ToDateTime(w_date).Month, 2) & n2s(Convert.ToDateTime(w_date).Day, 2)
'Else
' Ret_Val = ""
'End If
My_D2sYMD = Ret_Val
End Function
Function n2s(ByVal w As Single, ByVal n As Integer)
Dim Ret_Val As String
Ret_Val = "0000000000" & w
Ret_Val = Ret_Val.Substring(Len(Ret_Val) - n, n)
Return Ret_Val
End Function
Private Function Dt_YMD2DMY(ByVal w_dt As String)
If Len(Trim(w_dt)) = 8 Then
Return w_dt.Substring(6, 2) & "/" & w_dt.Substring(4, 2) & "/" & w_dt.Substring(0, 4)
Else
Return ""
End If
End Function
Private Function Dt_YMD2MDY(ByVal w_dt As String)
If Len(Trim(w_dt)) = 8 Then
Return w_dt.Substring(4, 2) & "/" & w_dt.Substring(6, 2) & "/" & w_dt.Substring(0, 4)
Else
Return ""
End If
End Function
please tell me where is the problems in conversion
UD(IA) 1-Dec-13 6:27am    
ok than tell me good and better way to do this thing...and where i can find new ways to learn asp.net with c#
OriginalGriff 1-Dec-13 6:37am    
Look at MSDN for number and date formatting: both ToString and String.Format have format strings which can do what you want without faffing about. The link I gave you covers integer, float, and double formatting, and the DateTime version is very similar.
Just to help, this summarises the DateTime formatting codes:
http://www.codeproject.com/Tips/54577/Formatting-a-DateTime-for-display-format-string-de
UD(IA) 1-Dec-13 9:57am    
Thank you very much
OriginalGriff 1-Dec-13 10:01am    
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900