VBA syntax error on "replace" function (replace character in string)

VBA syntax error on "replace" function (replace character in string)

j_steenbergen
Enthusiast Enthusiast
2,541 Views
8 Replies
Message 1 of 9

VBA syntax error on "replace" function (replace character in string)

j_steenbergen
Enthusiast
Enthusiast

I have a string in which I'd like to replace commas with a dot. Normally in VBA you would use:

 

Dim s As String
s = "15,6kg"
s = Replace(s, ",", ".")

Except that I get a syntax error on the replace function. Pretty weird, because it is listed as function in the Inventor VBA object browser. Auto correct also makes the r from replace lower case so it somehow doesn't recognize it.

 

It seems with iLogic a similar syntax is working:

https://forums.autodesk.com/t5/inventor-customization/ilogic-rule-replace-character-in-string/m-p/48...

 

So am I doing something wron or is this a bug?

0 Likes
Accepted solutions (1)
2,542 Views
8 Replies
Replies (8)
Message 2 of 9

bradeneuropeArthur
Mentor
Mentor

Are you using this in I-logic or in VBA?

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 3 of 9

j_steenbergen
Enthusiast
Enthusiast

I'm using VBA (see title)

0 Likes
Message 4 of 9

bradeneuropeArthur
Mentor
Mentor
Accepted solution

Than use this:

 

Public Sub main()

Dim s As String
s = "15,6kg"
s = VBA.Replace(s, ",", ".")

MsgBox s
End Sub

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

Message 5 of 9

j_steenbergen
Enthusiast
Enthusiast

Wow, that did the trick. Thanks!

0 Likes
Message 6 of 9

TobFischer94
Enthusiast
Enthusiast

... and how would it be possible in iLogic?

 

Nevermind, i found out, the following text did the trick for me. In my example, "param" is the numeric value with a comma, and "Variable" is the string that gets converted with a period

 

Variable = param
Variable = Replace(Variable, ",", ".")

Message 7 of 9

bradeneuropeArthur
Mentor
Mentor
Public Sub main
	
Dim st As String = "aba"

st = Replace(st,"b","c")
MsgBox (st)
End Sub
Public Sub main()

Dim s As String
s = "15,6kg"
s = Replace(s, ",", ".")

MsgBox s
End Sub

 

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

Message 8 of 9

maxim.teleguz
Advocate
Advocate

this right here is what i have been searching for the last 5 years. 

Message 9 of 9

maxim.teleguz
Advocate
Advocate

you can shorten it like so:

Public Sub main
Dim st As String = Replace(st,"b","c")
MsgBox (st) End Sub


or my code and how i used it:

 

a = 'pass on your string here from your code

Dim TXT2Find As String = "Precision='2'"
Dim NewTXT As String = "Precision='3'"
		
If a Like NewTXT Then
MsgBox("nothing changed")
Exit Sub
Else
a = Replace(a, TXT2Find, NewTXT)
End If 


 

0 Likes