Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Another string problem .Extracting numbers from Brackets

Posted on 2003-03-17
10
Medium Priority
?
188 Views
Last Modified: 2012-05-04

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
0
Comment
Question by:Gabriel_Brienza
  • 2
  • 2
  • 2
  • +3
10 Comments
 
LVL 11

Expert Comment

by:Steiner
ID: 8152052
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
 
LVL 26

Expert Comment

by:EDDYKT
ID: 8152063
Try this

Dim Arr
dim Value

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

msgbox value
0
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 8152067
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 43

Expert Comment

by:TimCottee
ID: 8152089
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
 
LVL 1

Expert Comment

by:nagviv
ID: 8152097
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
 

Author Comment

by:Gabriel_Brienza
ID: 8152357
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
 
LVL 26

Expert Comment

by:EDDYKT
ID: 8152394
Try this

Dim Arr
Dim Value

Arr = Split(mystring, "(")
Value = Val(Arr(1))
Erase Arr
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 8152465
Another try with the brackets in the right places:

Value = Mid(MyString, InStr(MyString, "(") + 1, InStr(MyString, ")") - InStr(MyString, "(") - 1)
0
 
LVL 11

Accepted Solution

by:
Steiner earned 80 total points
ID: 8152773
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
 

Author Comment

by:Gabriel_Brienza
ID: 8157568
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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month15 days, 20 hours left to enroll

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question