Solved

How to correct spaces in brackets

Posted on 2004-10-20
9
283 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
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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

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…
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 …
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…

829 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