cancel
Showing results for 
Search instead for 
Did you mean: 

create an expression with a real value with VB

Builder
Builder

Hello,

 

I have a problem with running a VB, which should create an expression with a real value, e.g. 25.123.

Here is a simple test-code:

*******************************

Option Strict Off
Imports System
Imports NXOpen

Module NXJ_exp_unit_1

Sub Main(ByVal args() As String)

Dim theSession As Session = Session.GetSession()
Dim lw As ListingWindow = theSession.ListingWindow
Dim workPart As Part = theSession.Parts.Work

lw.Open()

Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "NXJ expression with units")

Dim unit1 As Unit = CType(workPart.UnitCollection.FindObject("MilliMeter"), Unit)

Dim expression1 As Expression
Dim myExpName As String = "test"
Dim myExpValue As Double = 25.123

lw.WriteLine("myExpName = " & myExpName)
lw.WriteLine("myExpValue = " & myExpValue.ToString)
lw.WriteLine("")


'create expression, type: Number, measure: length, units: mm

' gives a syntax-error:
expression1 = workPart.Expressions.CreateWithUnits(myExpName & "=" & myExpValue, unit1)
lw.WriteLine("expression created: '" & expression1.Name & " = " & expression1.RightHandSide & "'")

 

' also this gives a syntax-error:
' expression1 = workPart.Expressions.CreateWithUnits(myExpName & "=" & myExpValue.ToString, unit1)
' lw.WriteLine("expression created: '" & expression1.Name & " = " & expression1.RightHandSide & "'")

 



' this works:
' expression1 = workPart.Expressions.CreateWithUnits(myExpName & "=" & "25.123", unit1)
' lw.WriteLine("expression created: '" & expression1.Name & " = " & expression1.RightHandSide & "'")


lw.Close()
End Sub

End Module

*******************************************

 

As you can see, in the line 22, I set the expression-value to 25.123. In the following listing-window, the value will be displayed with a comma instead of the point:

 

expression-test.jpg

 

 

 

 

 

If I run the code with a value of 25 (without decimal places), it runs. Also if I uses a fixed entry of "25.123" instead of the variable "myExpValue".

So I think that everytime I run the code with real values, they will be converted to values with a comma as the "decimal point", which does not work.

 

So my question:

What can I do to prevent converting point to comma in that variable during creation of the expression?

 

I´m using NX11.0.1 MP4 on a german Windows 10 Pro 64Bit system.

 

Best regards

Michael

Michael Eichelberg, CAD-Consultant, Dr. Wallner Engineering Nord GmbH
Production: NX10.0.3 MP16, NX11.0.1 MP4
Development: Batch and VB Testing: NX12
5 REPLIES

Re: create an expression with a real value with VB

Esteemed Contributor
Esteemed Contributor

I'm guessing... the Info window is using your localization settings from Windows, which say the "," is the separator between the "whole number" and the "fractional" part?

Ken Akerboom Sr CAx Systems Engr, Moog, Inc.
Production: NX10.0.3.5 MP5 + patch/TC11.2
I'd rather be e-steemed than e-diseaseled


Re: create an expression with a real value with VB

Esteemed Contributor
Esteemed Contributor

If you go into the expression editor, what is shown there?

Ken Akerboom Sr CAx Systems Engr, Moog, Inc.
Production: NX10.0.3.5 MP5 + patch/TC11.2
I'd rather be e-steemed than e-diseaseled


Re: create an expression with a real value with VB

Phenom
Phenom

It could be the NX setting for the decimal point (found in your drafting standard -> annotation -> units -> decimal point character) or it could be using your computer's regional setting. If it is using the computer's regional setting, you can override this in your journal code by specifying a "cultural" setting to use. See the article at:

http://nxjournaling.com/content/read-text-file

for an example (skip down to the "improved code" section).

Re: create an expression with a real value with VB

Esteemed Contributor
Esteemed Contributor

I include the following lines in every NX .NET source code to make sure it runs with the by NX supported local settings.

Threading.Thread.CurrentThread.CurrentCulture = New Globalization.CultureInfo("en-US")
Threading.Thread.CurrentThread.CurrentUICulture = New Globalization.CultureInfo("en-US")

This makes sure that no German settings are used in my case.

Stefan Pendl, Systemmanager CAx, HAIDLMAIR GmbH
Production: NX10.0.3, VERICUT 8.0, FBM, MRL 3.1.4 | TcUA 10.1 MP7 Patch 0 (10.1.7.0) | TcVis 10.1
Development: VB.NET, Tcl/Tk    Testing: NX11.0 EAP, NX12.0 EAP

How to Get the Most from Your Signature in the Community

Re: create an expression with a real value with VB

Builder
Builder

Hi Stefan, Hi Cowski,

 

thank you. This solves my problem. Now I get the point before the decimal places:

expression-test-2.jpg

 

 

 

 

 

 

 

 

I´m using excact the code from Stefan and get the above result as expected.

 

Thanks a lot and best regards,

 

Michael

Michael Eichelberg, CAD-Consultant, Dr. Wallner Engineering Nord GmbH
Production: NX10.0.3 MP16, NX11.0.1 MP4
Development: Batch and VB Testing: NX12