Can help me rewrite back the code below in proper way for VB?
Public Function ConvertCompoundingPeriod2Freq(ByVal Compounding_Period As String) As Integer
Dim freq As Integer
Select Case Compounding_Period
Case "SMP" ' Simple Compounding
freq = 1
Case "CONT" ' Continuous Compounding
freq = 1000
Case "DAY" ' Daily Compounding
freq = 365
Case "MON" ' Monthly Compounding
freq = 12
Case "QURT" ' Quarterly Compounding
freq = 4
Case "SEMI" ' Semi-Annual Compounding
freq = 2
Case "ANNU" ' Annual Compounding
freq = 1
Case Else
freq = -99
End Select
ConvertCompoundingPeriod2Freq = freq
End Function
The problem being ? At first sight it seems valid code. If this is just a style question, a thing you could think about is that every time you select a data according to a value, you can use a data structure instead (for example
http://msdn.microsoft.com/en-us/library/xfhwa508(v=vs.110).aspx rather than a select case. Also if the parameter is not valid you could throw an exception rather than to return an
invalid value (ie the app could appear to work but would produce very strange result, it can be better to just fail if you have a programing error). Or rather than to provide a string (it's hard to guess which value to provide), you could use an enum (which
will trigger intellisense when writing the calling code).
Please try to give some more details so that we can understand what you wanted to change (or what is the point you want to focus on for now)...
Great, mark whatever helped so that this thread is properly mark as closed. For future questions, note that its best to be always explicit ie rather than telling that you want to rewrite some code that seems valid, tell instead what benefit you want or if
you had a problem in using this code perhaps from somewhere else in your app, tell what is the error message you have etc...
Ah, I thought you wanted to rewrite existing VB code in a better way rather than to port this code to C#. Be always explicit. As advised earlier:
- a data structure could be better
- if you pass Smp or XXx what should happen. It might be better to throw an exception to tell the parameter is invalid rather than to return 0 that you'll use in your calculation with unwanted effects. Using an enumation could be easier to know which Compounding_Periods
are allowed without having to look at this method source code...
Member
7 Points
20 Posts
Rewrite
May 08, 2014 04:53 AM|HafeesFadil|LINK
Hi guys,
Can help me rewrite back the code below in proper way for VB?
Regards,
Hafees
vb
All-Star
48670 Points
18169 Posts
Re: Rewrite
May 08, 2014 05:49 AM|PatriceSc|LINK
Hi,
The problem being ? At first sight it seems valid code. If this is just a style question, a thing you could think about is that every time you select a data according to a value, you can use a data structure instead (for example http://msdn.microsoft.com/en-us/library/xfhwa508(v=vs.110).aspx rather than a select case. Also if the parameter is not valid you could throw an exception rather than to return an invalid value (ie the app could appear to work but would produce very strange result, it can be better to just fail if you have a programing error). Or rather than to provide a string (it's hard to guess which value to provide), you could use an enum (which will trigger intellisense when writing the calling code).
Please try to give some more details so that we can understand what you wanted to change (or what is the point you want to focus on for now)...
vb
Member
7 Points
20 Posts
Re: Rewrite
May 08, 2014 05:59 AM|HafeesFadil|LINK
Yea its a valid code.. Can help me write back this code in VB form? The 1 I post.. Thank you..
vb
All-Star
48670 Points
18169 Posts
Re: Rewrite
May 09, 2014 04:50 AM|PatriceSc|LINK
Sorry but I still don't get it. It *is* VB code. Or do you mean that you want to copy/paste this code inside a Form ???
What is the problem you have ? Do you see some kind of error message when you try to use this code ??
vb
Member
7 Points
20 Posts
Re: Rewrite
May 12, 2014 03:53 AM|HafeesFadil|LINK
Problem solved sir.. Thank you for replying.. :) I put the code as reference..
vb
Star
10596 Points
1379 Posts
Re: Rewrite
May 12, 2014 06:15 AM|Sam - MSFT|LINK
Hi Hafees,
Could you POST some code here so that other members who view this thread can benefit from your REPLY.
If any of the above POST helped you do mark the post as Answer.
Thanks and Regards!
vb
All-Star
48670 Points
18169 Posts
Re: Rewrite
May 12, 2014 06:53 AM|PatriceSc|LINK
Great, mark whatever helped so that this thread is properly mark as closed. For future questions, note that its best to be always explicit ie rather than telling that you want to rewrite some code that seems valid, tell instead what benefit you want or if you had a problem in using this code perhaps from somewhere else in your app, tell what is the error message you have etc...
vb
None
0 Points
2 Posts
Re: Rewrite
May 21, 2014 03:03 AM|rajeshmpanchal|LINK
I think you have asked for VB Code, Right?
Is it syntax of VB code - int freq = 0;
We need to use ";" at the end of line?
vb
Rajesh Panchal
All-Star
48670 Points
18169 Posts
Re: Rewrite
May 21, 2014 03:57 AM|PatriceSc|LINK
Ah, I thought you wanted to rewrite existing VB code in a better way rather than to port this code to C#. Be always explicit. As advised earlier:
- a data structure could be better
- if you pass Smp or XXx what should happen. It might be better to throw an exception to tell the parameter is invalid rather than to return 0 that you'll use in your calculation with unwanted effects. Using an enumation could be easier to know which Compounding_Periods are allowed without having to look at this method source code...
vb