?
Solved

Another string problem .Extracting numbers from Brackets

Posted on 2003-03-17
10
Medium Priority
?
187 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: 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!

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…
Suggested Courses
Course of the Month11 days, 11 hours left to enroll

752 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