Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Substring
#1
I would like to take out the yearly premium from this string:
The estimated monthly premium* is $87.67
The annual Premium for this coverage is $1,052.00

Which function should I use? I am looking at split but I do not see an example on how to use it. Let me rephrase that .. I do not understand the example. Not sure what this is MyArray = Split(MyString, "x", -1, 1) .. -1? In any case if this is the appropriate function how do you use this and if there is a better one, what is it and how do you use that one?
Reply
#2
Swat Wrote:




Can you try CDbl, this will give you the number portion and ignore the $ sign. I am guessing this is what you are trying to accomplish.
See sample code below.


strMonthlyPremium = "$87.67"
strAnnualPremium = "$1,052.00"
MonthlyPremium = cdbl( strMonthlyPremium )
AnnualPremium = cdbl( strAnnualPremium )

msgbox MonthlyPremium
msgbox AnnualPremium


Hi,
Thanks. But I am trying to take those figures out of the sentence. Does this make sense? I have to find them both in the sentence and take them out with or without $ sign. That part does not matter.
Reply
#3
Hi,

I suggest the below script, try it once:

Code:
strMonthlyPremium = "$87.67" strAnnualPremium = "$1,052.00" MonthlyPremium=right(strMonthlyPremium,len(strMonthlyPremium)-1) AnnualPremium=right(strAnnualPremium,len(strAnnualPremium)-1) msgbox MonthlyPremium msgbox AnnualPremium

Thanks & Regards,
Uday.
Reply
#4
Hi,
Please find the below code
Code:
Dim MyString, MyArray, Msg MyString = "VBScriptXisXfun!" MyArray = Split(MyString, "x", -1, 1) ' MyArray(0) contains "VBScript". ' MyArray(1) contains "is". ' MyArray(2) contains "fun!". Msg = MyArray(0) & " " & MyArray(1) Msg = Msg & " " & MyArray(2) MsgBox Msg


The above string "VBScriptXisXfun!" was splited into three parts as x is appeared twice in the string.
In the same way you can able to split the string "The annual Premium for this coverage is $1,052.00" based on $ character.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  VBA Code to read a substring Dwarak Calayampundi 2 3,511 10-04-2016, 09:15 PM
Last Post: venkatesh9032

Forum Jump:


Users browsing this thread: 1 Guest(s)