how to calculate with an variable in mm

how to calculate with an variable in mm

Darkforce_the_ilogic_guy
Advisor Advisor
756 Views
4 Replies
Message 1 of 5

how to calculate with an variable in mm

Darkforce_the_ilogic_guy
Advisor
Advisor

I have an ilogic that I trying to take an price *number of profil * length of profil

 

when I just calculate price *number of profil it work fine , but my code stop working as soon as I try  to add the length of profil.. the code fail.  I have no idear of why... 

 

Public Sub Main()
Dim NameList As New ArrayList()
Dim IsRHS As Boolean = False
Dim wrongDisplayname As String
Dim Tocopypast As String
Dim oAsmDoc As AssemblyDocument
Dim Antal
oAsmDoc = ThisApplication.ActiveDocument

Dim oRefDocs As DocumentsEnumerator
oRefDocs = oAsmDoc.AllReferencedDocuments

Dim oRefDoc As Document


NameList.Add("3116030034")
NameList.Add("3116040043")
NameList.Add("3116040044")
NameList.Add("3116030053")
NameList.Add("3116030054")
NameList.Add("3116050053")
NameList.Add("3116050054")
NameList.Add("3116050055")
NameList.Add("3116050056")
NameList.Add("3116050058")
NameList.Add("3116040063")
NameList.Add("3116040064")
NameList.Add("3116030064")
NameList.Add("3116060064")
NameList.Add("3116060065")
NameList.Add("3116060066")
NameList.Add("3116040084")
NameList.Add("3116040085")
NameList.Add("3116040086")
NameList.Add("3116050084")
NameList.Add("3116050085")
NameList.Add("3116080065")
NameList.Add("3116080083")
NameList.Add("3116080084")
NameList.Add("3116080085")
NameList.Add("3116080086")
NameList.Add("3116080088")
NameList.Add("3116090098")
NameList.Add("3116050103")
NameList.Add("3116050104")
NameList.Add("3116050106")
NameList.Add("3116050108")
NameList.Add("3116060103")
NameList.Add("3116060106")
NameList.Add("3116080104")
NameList.Add("3116080106")
NameList.Add("3116100104")
NameList.Add("3116100105")
NameList.Add("3116100106")
NameList.Add("3116100108")
NameList.Add("3116100109")
NameList.Add("3116060124")
NameList.Add("3116060125")
NameList.Add("3116060126")
NameList.Add("3116060128")
NameList.Add("3116060129")
NameList.Add("3116080125")
NameList.Add("3116080126")
NameList.Add("3116120125")
NameList.Add("3116120128")
NameList.Add("3116120130")
NameList.Add("3116140150")
NameList.Add("3116075156")
NameList.Add("3116100155")
NameList.Add("3116100156")
NameList.Add("3116100158")
NameList.Add("3116100159")
NameList.Add("3116080164")
NameList.Add("3116080165")
NameList.Add("3116080166")
NameList.Add("3116080168")
NameList.Add("3116080169")
NameList.Add("3116160168")
NameList.Add("3116180180")
NameList.Add("3116100205")
NameList.Add("3116100206")
NameList.Add("3116100208")
NameList.Add("3116100210")
NameList.Add("3116120206")
NameList.Add("3116200206")
NameList.Add("3116150256")
NameList.Add("3116100308")
NameList.Add("3116100310")
NameList.Add("3116200410")
NameList.Add("3116400410")




For Each oRefDoc In oRefDocs
	
	
	
	For Each rawmaterial In NameList 
		
	
	
Try	
If iProperties.Value(oRefDoc.DisplayName, "Custom", "Raw Material") = rawmaterial Then

IsRHS = True
assemblyDoc = oAsmDoc
assemblyDef = assemblyDoc.ComponentDefinition
Antal = assemblyDef.Occurrences.AllReferencedOccurrences(oRefDoc)
Length = iProperties.Value(oRefDoc.DisplayName, "Custom", "G_L")
MsgBox(iProperties.Value(oRefDoc.DisplayName, "Custom", "G_L"))


'debug("Length " & Length.ToString )
price =  Antal.Count * 42 '* Length
debug(iProperties.Value(oRefDoc.DisplayName, "Project", "Part Number") & " " & "number of unit " & Antal.Count.ToString & " Money Save by change to RHP " & price & " kr")
End If 

Catch
IsRHS = False	
End Try
 
Next

If IsRHS = True Then
	If  iProperties.Value(oRefDoc.DisplayName, "Custom", "Raw Material") <>  "" Then 
	debug(iProperties.Value(oRefDoc.DisplayName,"Project", "Part Number"))
wrongDisplayname = wrongDisplayname & vbLf & vbLf & "Partnumber " & iProperties.Value(oRefDoc.DisplayName, "Project", "Part Number")

		
Tocopypast = Tocopypast & iProperties.Value(oRefDoc.DisplayName, "Project", "Part Number") & " OR "
Clipboard.SetText(Tocopypast)
IsRHS = False
End If	
End If 
Next


	
	
MessageBox.Show(wrongDisplayname, "Use RHS material")
End Sub

Public Sub debug(txt As String)
	Trace.WriteLine("NTI : " & txt)
End Sub

 

 

0 Likes
Accepted solutions (2)
757 Views
4 Replies
Replies (4)
Message 2 of 5

FINET_Laurent
Advisor
Advisor

Just looking through I don't see Length variable declared anywhere?

Maybe declaring it as double will help ?

 

Regards,

 

FINET L.

If this post solved your question, please kindly mark it as "Solution"

If this post helped out in any way to solve your question, please drop a "Like"

@LinkedIn     @JohnCockerill

0 Likes
Message 3 of 5

Darkforce_the_ilogic_guy
Advisor
Advisor

it seems that it can´t convert an string with number and unit to an pure number 

 

the string is somthing like "361 mm"   it say Can´t change stregen "361,0 mm" to duble

0 Likes
Message 4 of 5

JhoelForshav
Mentor
Mentor
Accepted solution

Hi @Darkforce_the_ilogic_guy 

I wrote this function (GetDoubleVal) for you to convert the value to a double. See example below:

Sub Main
Dim oLength = "1234.56 mm"
Dim oLengthDouble = GetDoubleVal(oLength)
MsgBox(oLengthDouble)
End Sub

Function GetDoubleVal(oValue As Object) As Double
	Return CDblAny(System.Text.RegularExpressions.Regex.Replace(oValue.ToString, "[A-Za-z ]", ""))
End Function

 

Message 5 of 5

Darkforce_the_ilogic_guy
Advisor
Advisor
Accepted solution

I ende up using this code to remove the mm form text, and use the varible to convert it to an Double

Dim messing As Double = Split(iProperties.Value(oRefDoc.DisplayName, "Custom", "G_L")," mm")(0)

 

0 Likes