Regex (1 Viewer)

Alessandro Giraldi

New member
Local time
Today, 15:56
Joined
Feb 24, 2020
Messages
15
ok now is correct
tk u so much...
grazie 1000000

Public Function GetOrdito(strOrdito As String) As t_Ordito
Dim Ordito As t_Ordito
Dim character As String
Dim strnumberBefore As String
Dim numberBefore As Integer
Dim distributeNumber As Integer
Dim distribute As Boolean
Dim i As Integer
distributeNumber = 1
For i = 1 To Len(strOrdito)
character = mID(strOrdito, i, 1)
Debug.Print "Char in beginning" & character
If IsNumeric(character) Then
strnumberBefore = strnumberBefore & character
numberBefore = CInt(strnumberBefore)

Else
If distribute = False Then
' distributeNumber = 1
' Else
distributeNumber = numberBefore
End If
' Debug.Print "Char " & character & "Distribute " & distribute & " number " & distributeNumber & " Number before " & numberBefore
Select Case character

Case "A"
Ordito.A = Ordito.A + numberBefore * distributeNumber
Debug.Print Ordito.A & " A"
strnumberBefore = ""
Case "B"
Ordito.B = Ordito.B + numberBefore * distributeNumber
strnumberBefore = ""
Case "C"
Ordito.C = Ordito.C + numberBefore * distributeNumber
strnumberBefore = ""
Case "D"
Ordito.D = Ordito.D + numberBefore * distributeNumber
strnumberBefore = ""
Case "E"
Ordito.E = Ordito.E + numberBefore * distributeNumber
strnumberBefore = ""
Case "("
distribute = True
distribute = numberBefore
strnumberBefore = ""
Case ")"
distribute = False
distributeNumber = 1
strnumberBefore = ""
End Select
End If
Next i
Ordito.Total = Ordito.A + Ordito.B + Ordito.C + Ordito.D + Ordito.E
GetOrdito = Ordito


End Function
 

NauticalGent

Ignore List Poster Boy
Local time
Today, 10:56
Joined
Apr 27, 2015
Messages
6,286
Alessandro, do you live in Italy? If so, if I may ask, where? I live in Napoli myself, working for the NATO forces.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 10:56
Joined
May 21, 2018
Messages
8,463
Sorry. That was a pretty big mistake. Only reason it worked at all was I got lucky on the data I choose. I cannot tell your fixes will cover all cases. This seems to work consistently.
Code:
Public Function GetOrdito(strOrdito As String) As t_Ordito
  Dim Ordito As t_Ordito
  Dim character As String
  Dim strnumberBefore As String
  Dim numberBefore As Integer
  Dim distributeNumber As Integer
  Dim distribute As Boolean
  Dim i As Integer
  distributeNumber = 1
  For i = 1 To Len(strOrdito)
    character = Mid(strOrdito, i, 1)
    If IsNumeric(character) Then
      strnumberBefore = strnumberBefore & character
      numberBefore = CInt(strnumberBefore)
      
    ElseIf character = "(" Then
        distribute = True
        distributeNumber = numberBefore
        strnumberBefore = ""
    ElseIf character = ")" Then
        distribute = False
        distributeNumber = 1
        strnumberBefore = ""
    Else
    
    Debug.Print "Char " & character & " Distribute " & distribute & " Dist number " & distributeNumber & " Number before " & numberBefore
    Select Case character
    
     Case "A"
      Ordito.A = Ordito.A + numberBefore * distributeNumber
      Debug.Print Ordito.A & " A"
      strnumberBefore = ""
     Case "B"
      Ordito.B = Ordito.B + numberBefore * distributeNumber
      strnumberBefore = ""
     Case "C"
      Ordito.C = Ordito.C + numberBefore * distributeNumber
      strnumberBefore = ""
     Case "D"
      Ordito.D = Ordito.D + numberBefore * distributeNumber
       strnumberBefore = ""
     Case "E"
      Ordito.E = Ordito.E + numberBefore * distributeNumber
      strnumberBefore = ""
      End Select
    End If
  Next i
  Ordito.Total = Ordito.A + Ordito.B + Ordito.C + Ordito.D + Ordito.E
  GetOrdito = Ordito

 
End Function
 

Alessandro Giraldi

New member
Local time
Today, 15:56
Joined
Feb 24, 2020
Messages
15
Sorry. That was a pretty big mistake. Only reason it worked at all was I got lucky on the data I choose. I cannot tell your fixes will cover all cases. This seems to work consistently.
Code:
Public Function GetOrdito(strOrdito As String) As t_Ordito
  Dim Ordito As t_Ordito
  Dim character As String
  Dim strnumberBefore As String
  Dim numberBefore As Integer
  Dim distributeNumber As Integer
  Dim distribute As Boolean
  Dim i As Integer
  distributeNumber = 1
  For i = 1 To Len(strOrdito)
    character = Mid(strOrdito, i, 1)
    If IsNumeric(character) Then
      strnumberBefore = strnumberBefore & character
      numberBefore = CInt(strnumberBefore)
    
    ElseIf character = "(" Then
        distribute = True
        distributeNumber = numberBefore
        strnumberBefore = ""
    ElseIf character = ")" Then
        distribute = False
        distributeNumber = 1
        strnumberBefore = ""
    Else
  
    Debug.Print "Char " & character & " Distribute " & distribute & " Dist number " & distributeNumber & " Number before " & numberBefore
    Select Case character
  
     Case "A"
      Ordito.A = Ordito.A + numberBefore * distributeNumber
      Debug.Print Ordito.A & " A"
      strnumberBefore = ""
     Case "B"
      Ordito.B = Ordito.B + numberBefore * distributeNumber
      strnumberBefore = ""
     Case "C"
      Ordito.C = Ordito.C + numberBefore * distributeNumber
      strnumberBefore = ""
     Case "D"
      Ordito.D = Ordito.D + numberBefore * distributeNumber
       strnumberBefore = ""
     Case "E"
      Ordito.E = Ordito.E + numberBefore * distributeNumber
      strnumberBefore = ""
      End Select
    End If
  Next i
  Ordito.Total = Ordito.A + Ordito.B + Ordito.C + Ordito.D + Ordito.E
  GetOrdito = Ordito


End Function

Sorry MajP,
i am still here.... :)
so i have tried this case :
1 case) 2A2B A=0 B=0 TOTAL = 0 NOT OK
2 case) 2A2B2(2A2B) A=4 B=4 TOTAL = 8 NOT OK
3 case) 2A2B2(2A2B)3A3B A=7 B=7 TOTAL =14 NOT OK
4 case) 2(2A2B)3A3B A=7 B=7 TOTAL = 14 OK
5 case) 2(2A2B)3A3B2(2A2B) A=11 B=11 TOTAL = 22 OK

I think to have posted all possibility i could have.
do you have some suggestion?
because i am not so expert to understand this .
tk u and sorry for too many help.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 10:56
Joined
May 21, 2018
Messages
8,463
sorry for too many help.
No worry glad to help. However, I do not seem to have the same problems. Maybe did not copy something correctly. Try my calculator.
Ordito.jpg
 

Attachments

  • NotaOrdito.zip
    27.3 KB · Views: 88

MajP

You've got your good things, and you've got mine.
Local time
Today, 10:56
Joined
May 21, 2018
Messages
8,463
sorry that was wrong version of code. There was a hardwired string in there. All should have been wrong.
calcOrdito.png
 

Attachments

  • NotaOrdito2.zip
    23.4 KB · Views: 90

MajP

You've got your good things, and you've got mine.
Local time
Today, 10:56
Joined
May 21, 2018
Messages
8,463
Benvenuto. Out of curiosity what are these numbers? I am guessing this is some kind of manufacturing code. Is that correct? Never seen any data structure like that before. Is there a reason they store it like that.
 

Alessandro Giraldi

New member
Local time
Today, 15:56
Joined
Feb 24, 2020
Messages
15
Hi MajP,
Yes, i work in textile business, i am Technic of fabbrics and this expression i Need to calculate the colors of the yarns i Need to put in warp or in loom machine to make a design.
For ex. If you buy a garment with a smal design like attached, you have to make 4A4B to develope this design, It means 4 White and 4 black in vertical and horizontal in different kind of yarn.
I don' t know of i was clear.
😁
Tk u again for tour help.
 

Attachments

  • images.png
    images.png
    7.4 KB · Views: 83
Last edited:

MajP

You've got your good things, and you've got mine.
Local time
Today, 10:56
Joined
May 21, 2018
Messages
8,463
I figured it was a manufacturing code. Thanks.
 

Users who are viewing this thread

Top Bottom