Instrument Tags in Process Engineering

S

Steve

I am no longer a wiz at Visual Basic, used to be in basic
but then the world passed me by. Anyway, the problem
Ihave is that I create a tag for an instrument that
consists of Type - Loop Number. The problem is that I do
not want the Type - portion to show in the lower portion
of the shape. I believe that Text Field 1 in the
shapesheet controls this. I cannot find a function in the
list that would only return the integers in the string (or
something similar). For example, the tag (displayed text)
might be CV-456 and I only want 456 to display.

Please tell me how to accomplish this. thanks in advance.
 
T

Tomas Larsson

Do two fields in "Custom properties" one for Type and one
for loop, the insert "Prop.Loop" in the textfield With
the Insert|Field command.

Tomas Larsson
 
A

Al Edlund

if you have 'standardized' on a hyphen as your delimiter, here is some
general code that I use to parse a variety of formats


dim InpString as string
dim OutString as string
dim DelString as string

InpString = "cv-456"
DelString = "-"

OutString = funcGetTokens(InpString,DelString,2)

al


Public Function funcGetTokens(strTemp As String, strDelimiter As String,
lngIndex As Long) As String

' funcGetTokens is a general parser that the user supplies
' an input string, a delimiter (1 or more characters) and an index
' into the input string to get a subset of the string
' if csv we watch for parens (i.e. embedded lists)

Dim lngTokenCount As Long
Dim lngCount As Long
Dim lngTempPos As Long
Dim lngSPos As Long
Dim lngEPos As Long
Dim intLenDel As Integer
Dim boolEmbeddedList As Boolean
Dim intListStart As Integer
Dim intListStop As Integer
Dim boolCSV As Boolean

' is this a csv parse ?
If strDelimiter = "," Then
boolCSV = True
Else
boolCSV = False
End If

intListStart = InStr(1, strTemp, "(", vbBinaryCompare)
intListStop = InStr(1, strTemp, ")", vbBinaryCompare)
If intListStop > intListStart Then
boolEmbeddedList = True
Else
boolEmbeddedList = False
End If


lngTokenCount = funcCountTokens(strTemp, strDelimiter)
If lngIndex < 1 Or lngIndex > lngTokenCount Then
funcGetTokens = 0
Exit Function
End If

intLenDel = Len(strDelimiter)
lngCount = 1
lngSPos = 1

If lngIndex = 1 Then
If boolCSV = True And boolEmbeddedList = True Then
' recheck where the list is from this spot
intListStart = InStr(1, strTemp, "(", vbBinaryCompare)
intListStop = InStr(1, strTemp, ")", vbBinaryCompare)
lngEPos = InStr(1, strTemp, strDelimiter) - intLenDel
' don't point into a list
If lngEPos < intListStart Then
funcGetTokens = Mid(strTemp, 1, lngEPos - 1 + intLenDel)
Exit Function
End If
Else
lngEPos = InStr(1, strTemp, strDelimiter) - intLenDel
funcGetTokens = Mid(strTemp, 1, lngEPos - 1 + intLenDel)
Exit Function
End If
End If

For lngCount = 2 To lngIndex
If boolCSV = True And boolEmbeddedList = True Then
' recheck where the list is from this spot
intListStart = InStr(lngSPos, strTemp, "(", vbBinaryCompare)
intListStop = InStr(lngSPos, strTemp, ")", vbBinaryCompare)
lngTempPos = InStr(lngSPos, strTemp, strDelimiter, 0) -
intLenDel
' don't point into a list
If lngTempPos < intListStart Or lngTempPos > intListStop
Then
lngSPos = lngTempPos
lngCount = lngCount + 1
End If
Else
lngSPos = InStr(lngSPos, strTemp, strDelimiter, 0) +
intLenDel
DoEvents
End If
Next lngCount
DoEvents
lngEPos = InStr(lngSPos, strTemp, strDelimiter, 0) - intLenDel

If lngEPos <= 0 Then
lngEPos = Len(strTemp)
End If
funcGetTokens = Mid(strTemp, lngSPos, lngEPos - lngSPos + intLenDel)

End Function

Public Function funcCountTokens(strTemp As String, strDelimiter As
String) As Long
'
' Counts strings separated by input string delimter
' if the delimiter is a comma then check for embedded lists
'
Dim lngTokenCount As Long
Dim lngIndex As Long
Dim lngTempIndex As Long
Dim lngDelLen As Long
Dim lngInput As Long
Dim boolEmbeddedList As Boolean
Dim intListStart As Integer
Dim intListStop As Integer
Dim boolCSV As Boolean

' is this a csv parse ?
If strDelimiter = "," Then
boolCSV = True
Else
boolCSV = False
End If

intListStart = InStr(1, strTemp, "(", vbBinaryCompare)
intListStop = InStr(1, strTemp, ")", vbBinaryCompare)
If intListStop > intListStart Then
boolEmbeddedList = True
Else
boolEmbeddedList = False
End If

lngInput = Len(strTemp)
If VarType(strTemp) <> vbString Or Len(strTemp) = 0 Then
funcCountTokens = 0
Exit Function
End If

lngDelLen = Len(strDelimiter)


' first check to see if there is a delimter in the string
lngIndex = InStr(strTemp, strDelimiter)
lngTokenCount = 1

Do While ((lngIndex > 0) And (lngIndex <= lngInput))
' since we got here we must have found a token
If boolCSV = True And boolEmbeddedList = True Then
' recheck where the list is from this spot
intListStart = InStr(1, strTemp, "(", vbBinaryCompare)
intListStop = InStr(1, strTemp, ")", vbBinaryCompare)
lngTempIndex = InStr(lngIndex + lngDelLen, strTemp,
strDelimiter, 0)
If lngTempIndex > intListStart Or lngTempIndex < intListStop
Then
lngTokenCount = lngTokenCount + 1
lngIndex = lngTempIndex
Else
lngIndex = lngIndex + 1
End If
Else
lngTokenCount = lngTokenCount + 1
lngIndex = InStr(lngIndex + lngDelLen, strTemp,
strDelimiter, 0)
End If
DoEvents
Loop

' suspect I need some logic for what happens if no delimter found
funcCountTokens = lngTokenCount

End Function
 
S

Steve

After complaining to microsoft, I got an answer that they
can't do it. Hmmmm. Anyway, turns out your method works
and quite simple.

Thank you.
 
M

Mark Nelson [MS]

If you have any further trouble, please post again and I'll be happy to
help. I created the Instrument shapes for several versions of Visio.
 
S

Steve

Ok, have this set up for one shape and works great.
However, when i copy the shape or copy it into a stencil,
the change does not come with it. The custom property is
there, but the Loop no longer prints on the shape and the
text field has defaulted back to original.
 
M

Mark Nelson [MS]

What version of Visio are you using? I wonder whether the Process
Engineering solution is interfering with what you want to do.
 
G

Guest

Visio Professional 2002 (10.0.525)

-----Original Message-----
What version of Visio are you using? I wonder whether the Process
Engineering solution is interfering with what you want to do.

--
Mark Nelson
Microsoft Corporation

This posting is provided "AS IS" with no warranties, and confers no rights.





.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top