Another string problem .Extracting numbers from Brackets


strings formatting drives me crazy.


I always have strings
like

mystring="Deposit Account (22.50)
or
mystring="Mycredit Account(250.50)

Basically the amaount within the brackets can be anything.

How can i get the amount within the brackets?

do I have to use a split or instr can somebody give me a solution?

thanks
vbnetuk
Gabriel_BrienzaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SteinerCommented:
Try:

msgbox val(mid(mystring,instr(mystring,"(")+1))

This will look for the opening bracket and then extract any value it can find there.
0
EDDYKTCommented:
Try this

Dim Arr
dim Value

Arr = split(mystring, "(")
value = cdbl(Arr(1)
erase Arr

msgbox value
0
Arthur_WoodCommented:
will the numbers that you want to 'extract' ALWAYS be enclosed in (....)s.   Do you care if the text says "Deposit" or "MyCredit"?

Why is the text formatted in that way?  Do you have any control over that?

AW
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

TimCotteeHead of Software ServicesCommented:
Hi Gabriel_Brienza,

Use Instr and MID

value = Mid(MyString,Instr(MyString,"(") + 1,Instr(MyString,")") - Instr(MyString,")") + 1)

Tim Cottee MCSD, MCDBA, CPIM
http://www.timcottee.tk 

Brainbench MVP for Visual Basic
http://www.brainbench.com

Experts-Exchange Advisory Board Member
0
nagvivCommented:
Dear Gabriel,

You will have to use Instr and the either split, left or right or mid.

You would get the position of ( and ) respectively using Instr and then use Mid to extract the value between the (). If you plan to do arithematic calculatins then you should convert using CInt, or CDbl


Regards,

G. Nagraj
0
Gabriel_BrienzaAuthor Commented:
Thanks for all your answers

Arthur
I dont have control the way it is formatted
I just need the numbers in the brackets and convert to currency.


Steiner
it works but i will need to convert to currency

TimCotte
it extract only a 2

EDDYKT
Tried but didnt work



0
EDDYKTCommented:
Try this

Dim Arr
Dim Value

Arr = Split(mystring, "(")
Value = Val(Arr(1))
Erase Arr
0
TimCotteeHead of Software ServicesCommented:
Another try with the brackets in the right places:

Value = Mid(MyString, InStr(MyString, "(") + 1, InStr(MyString, ")") - InStr(MyString, "(") - 1)
0
SteinerCommented:
You can convert it to currency using cCur:

msgbox ccur(val(mid(mystring,instr(mystring,"(")+1)))

Or is it about formatting?

msgbox format(val(mid(mystring,instr(mystring,"(")+1)),"#,###.00")
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Gabriel_BrienzaAuthor Commented:
Thanks everybody  for your help
and suggestions.
In the end more than one answer was good but Steiner was the first correct one

Thanks again


0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.