Solved

How to correct spaces in brackets

Posted on 2004-10-20
9
285 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 50 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 200 total points
ID: 12367521
Try something like this:

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

Craig
0
Technology Partners: 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 200 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

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

Suggested Solutions

Title # Comments Views Activity
VBA/SQL - Connect to SQL server and pull data 4 137
VBA filters 2 71
How to make an ADE file by code? 11 100
Child Form in front 4 57
Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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…
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…

730 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