AnsweredAssumed Answered

decimal from string

Question asked by Lasse Nielsen on Aug 25, 2015
Latest reply on Aug 25, 2015 by Ivana Kolin

I have the following macro code

 

Option Explicit

   

Dim strMaterialCode As String

Dim sglMaterialCodeLength As Single

Dim sglThickness As Single

Dim strType As String

 

 

Public sglDiaOuter As Single

Public sglDiaInner As Single

 

Sub CaseSelect()

 

     strType = "SMS1.2"

       

     Select Case strType

   

        'PE

        Case "PE11"

            Call Extractor

            Call CasePlast

        Case "PE17"

            Call Extractor

            Call CasePlast

        Case "PE33"

            Call Extractor

            Call CasePlast

                       

        'PP

        Case "PP11"

            Call Extractor

            Call CasePlast

        Case "PP17"

            Call Extractor

            Call CasePlast

        Case "PP33"

            Call Extractor

            Call CasePlast

           

           

        'SS1.6

        Case "SMS1.2"

            Call Extractor

            Call CaseSteel

        Case "SMS1.6"

            Call Extractor

            Call CaseSteel

        Case "SMS2.0"

            Call Extractor

            Call CaseSteel

           

    End Select

End Sub

 

 

Sub CaseSteel()

    sglDiaInner = sglDiaOuter - sglThickness / 1000 * 2

   

End Sub

 

 

Sub CasePlast()

    sglDiaInner = sglDiaOuter - sglDiaOuter / sglThickness / 1000 * 2

End Sub

 

 

Sub Extractor()

 

 

    Dim k As Long

    Dim i As Long

   

    k = Len(strType)

    i = 1

   

    Do

        If i > k Then Exit Do

        If IsNumeric(Mid$(strType, i, 1)) Then Exit Do

        i = i + 1

    Loop

 

 

    strMaterialCode = Left$(strType, i - 1)

    sglMaterialCodeLength = Len(strMaterialCode)

    sglThickness = Right$(strType, k - sglMaterialCodeLength)

   

End Sub

 

Since i'm new to VBA i cannot figure out why sglThickess returns the value 12 and not 1.2. What am I doing wrong?

Outcomes