Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What the heck do i do now? 1

Status
Not open for further replies.

Alcedes

Technical User
Mar 25, 2008
46
US
I am using this bit of code to identify what my user is clicking:



ShapeClicked = Visio.ActiveWindow.Selection.Item(1).text

simple enough. the problem is tho, the actual value of this the variable Shapeclicked.

it is [][][][]wan.25[]

i cant use that! how do i get just the wan.25 part?
 
If by "[]" you mean the little square symbols that VBA uses to represent the special ASCII characters, then those extra ones are likely carriage returns and line feeds. Try this:
Code:
ShapeClicked = Replace$(Visio.ActiveWindow.Selection.Item(1).text, vbCrLf, "")
If that doesn't work, try looping through to get the ASCII code of each character, and then use the Replace$() function to parse out those characters. The alternative is to use Regular Expressions, but that may be overkill.
 
Nope. Still there.

these stupid []'s are making it so that I cannot use that darn variable! :(
 
Hmmm, well they're not carriage returns and line feeds, but they must be some character. Use Asc(Mid$(...)) and loop through each character in the string contained in ShapeClicked. Write down the ASCII codes of the extra symbols (search VBA help for the ASCII table to see which are normal characters and which are special characters), and then use the Replace$() function to weed out the unwanted special characters.
 
they are carriage returns. but that code you provided doesnt seem to be removing them.

it easier for me to just not use carriage returns. :)
 
Code:
Sub Main()
    Dim s As String
    Dim i As Integer

    s = Chr(10) & Chr(10) & Chr(10) & Chr(10) & "wan.25" & Chr(10) 'use special character 10 for testing purposes
    For i = 1 To Len(s)
        Debug.Print Asc(Mid$(s, i, 1)) 'make not of any characters with values < 48 or > 127
    Next

    MsgBox replace$(s, Chr(10), "") 'replace 10 with the appropriate illegal character code to parse out
End Sub
 
Carriage return is char 13 and line feed is char 10...or vice versa (I never remember). Anyway, you can just replace$ chr(10) or chr(13).

vbCrLf is simply a constant to represent 13 & 10 combined, since they are usually used together in Windows... but apparently in this instance they aren't.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top