Last post May 21, 2014 03:57 AM by PatriceSc
May 08, 2014 04:53 AM|HafeesFadil|LINK
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
freq = -99
ConvertCompoundingPeriod2Freq = freq
May 08, 2014 05:49 AM|PatriceSc|LINK
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)...
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..
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 ??
May 12, 2014 03:53 AM|HafeesFadil|LINK
Problem solved sir.. Thank you for replying.. :) I put the code as reference..
public int ConvertCompoundingPeriod2Freq(string Compounding_Period)
int freq = 0;
if (Compounding_Period == "SMP")
freq = 1;
else if (Compounding_Period == "CONT")
freq = 1000;
else if (Compounding_Period == "DAY")
freq = 365;
else if (Compounding_Period == "MON")
freq = 12;
else if (Compounding_Period == "QURT")
freq = 4;
else if (Compounding_Period == "SEMI")
freq = 2;
else if (Compounding_Period == "ANNU")
freq = 1;
freq = -99;
May 12, 2014 06:15 AM|Sam - MSFT|LINK
Problem solved sir.. Thank you for replying.. :)
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!
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...
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?
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...