?
Solved

How to correct spaces in brackets

Posted on 2004-10-20
9
Medium Priority
?
288 Views
Last Modified: 2010-05-02
Is there any way to delete spaces at the start of bracket and end of brackets while changing the Font Style of brackets and contents seperately through VB.
0
Comment
Question by:micazone
[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
9 Comments
 
LVL 2

Assisted Solution

by:koolnurd
koolnurd earned 150 total points
ID: 12366514
try using

trim(string)

trim is a function which remove spaces from the begining and end of the string.
0
 
LVL 11

Expert Comment

by:dbrckovi
ID: 12366750
Can you give us an example?
0
 
LVL 2

Assisted Solution

by:craigewens
craigewens earned 600 total points
ID: 12367521
Try something like this:

Function RemoveBracketSpaces(txtInput As String) As String
    RemoveBracketSpaces = Replace(Replace(txtInput, "( ", "("), " )", ")")
End Function

Craig
0
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!

 
LVL 2

Accepted Solution

by:
craigewens earned 600 total points
ID: 12368153
With regards to having different fonts within the same object, i guess it'd depend on the object your trying to use. A label for example can't do this (AFAIK). The way i'd get round this though is to split your string into 3 parts. Here are three functions to do this for you.. use them and populate 3 different labels having the fonts any way you wish... just place them next to each other so they look like one :)

Function LeftString(txtInput As String, txtSearch As String) As String
    LeftString = Left(txtInput, InStr(1, txtInput, txtSearch) - 1)
End Function
Function RightString(txtInput As String, txtSearch As String) As String
    RightString = Right(txtInput, Len(txtInput) - InStrRev(txtInput, txtSearch))
End Function
Function MidString(txtInput As String, txtSearchStart As String, txtSearchEnd As String) As String
    MidString = Mid(txtInput, _
            InStr(1, txtInput, txtSearchStart) + 1, _
            Len(txtInput) - InStr(1, txtInput, txtSearchStart) - (Len(txtInput) - InStrRev(txtInput, txtSearchEnd)) - 1)
End Function
0
 

Author Comment

by:micazone
ID: 12369130
Thanks
How to put in sub or make a full script.
I am not a programmer hence this help needed.
0
 
LVL 2

Expert Comment

by:craigewens
ID: 12369250
Post a sample of your code with comments directing where you'd like the operations to take place. Eg...

code blaa
code blaa
code blaa
' now make my variable txtTempString have no spaces
code blaa
code blaa
' now put my variable txtTempString into label1.caption
code blaa
code blaa


etc etc
0
 

Author Comment

by:micazone
ID: 12371881
I have to replace and fomat all the text srings within brackets in a document, possibly a wild card type.
i.e. need to remove spaces before and after text string present in the document.
0
 

Author Comment

by:micazone
ID: 12381490
Please help with a macro please
0
 

Author Comment

by:micazone
ID: 12387281
Can the following work? Sorry I am not and expoert or programmer.
Sub correctBrackets()
Function LeftString(txtInput As String, txtSearch As String) As String
    LeftString = Left(txtInput, InStr(1, txtInput, txtSearch) - 1)
End Function
Function RightString(txtInput As String, txtSearch As String) As String
    RightString = Right(txtInput, Len(txtInput) - InStrRev(txtInput, txtSearch))
End Function
Function MidString(txtInput As String, txtSearchStart As String, txtSearchEnd As String) As String
    MidString = Mid(txtInput, _
            InStr(1, txtInput, txtSearchStart) + 1, _
            Len(txtInput) - InStr(1, txtInput, txtSearchStart) - (Len(txtInput) - InStrRev(txtInput, txtSearchEnd)) - 1)
End Function
End Sub
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month12 days, 23 hours left to enroll

777 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