
Public Function Test(Txt As String, RExpr As String) As Boolean
Dim regEx As New RegExp
If RExpr <> "" Then
With regEx
.Global = True
.MultiLine = True
.IgnoreCase = True
.Pattern = RExpr
End With
Test = regEx.Test(Txt)
End If
End Function |
Sub RegEx_Tester()
Set objRegExp_1 = CreateObject("vbscript.regexp")
objRegExp_1.Global = True
objRegExp_1.IgnoreCase = False
objRegExp_1.Pattern = ^(97(8|9))?d{9}(d|X)$ ' nell'esempio incontrato era: objRegExp_1.Pattern=[a-z,A-Z]*@[a-z,A-Z]*.com. A me qualsiasi espressione da errore al primo carattere dicendo: "Errore di compilazione. Si aspettava espressione."
....l'esempio continua con
strToSearch="ABC@xyz.com"
Set regExp_Matches = objRegExp_1.Execute(strToSearch) 'che nel mio caso sarebbe TextBox1.Text
If regExp_Matches.Count = 1
MsgBox("This string is a valid email address.")
End if
End Sub |
| scossa's web site |
| Se tu hai una mela, ed io ho una mela, e ce le scambiamo, allora tu ed io abbiamo sempre una mela per uno. Ma se tu hai un'idea, ed io ho un'idea, e ce le scambiamo, allora abbiamo entrambi due idee. (George Bernard Shaw) |
Public Function Test2(Txt As String) As Boolean
Const sPattern = "ISBN(-1(?:(0)|3))?:?x20(s)*[0-9]+[- ][0-9]+[- ][0-9]+[- ][0-9]*[- ]*[xX0-9]"
Dim regEx As Object
Set regEx = CreateObject("VBScript.RegExp")
With regEx
.Global = True
.MultiLine = False
.IgnoreCase = True
.Pattern = sPattern
End With
Test2 = regEx.Test(Txt)
End Function |
| scossa's web site |
| Se tu hai una mela, ed io ho una mela, e ce le scambiamo, allora tu ed io abbiamo sempre una mela per uno. Ma se tu hai un'idea, ed io ho un'idea, e ce le scambiamo, allora abbiamo entrambi due idee. (George Bernard Shaw) |
Public Function Test(Txt As String) As Boolean
Dim regEx As New RegExp
With regEx
.Global = True
.MultiLine = True
.IgnoreCase = True
.Pattern = "^(97(8|9))?d{9}(d|X)$"
End With
Test = regEx.Test(Txt)
End Function |
| scossa's web site |
| Se tu hai una mela, ed io ho una mela, e ce le scambiamo, allora tu ed io abbiamo sempre una mela per uno. Ma se tu hai un'idea, ed io ho un'idea, e ce le scambiamo, allora abbiamo entrambi due idee. (George Bernard Shaw) |
| scossa's web site |
| Se tu hai una mela, ed io ho una mela, e ce le scambiamo, allora tu ed io abbiamo sempre una mela per uno. Ma se tu hai un'idea, ed io ho un'idea, e ce le scambiamo, allora abbiamo entrambi due idee. (George Bernard Shaw) |
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If Not Test(Me.TextBox1.Value) Then
MsgBox "Valore errato"
Cancel = True
End If
End Sub
|
Option Base 1
Sub a()
Dim arr() As Integer
isbn = Range("A1").Text
L = Len(isbn)
ReDim arr(L)
molt = Array(1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3)
For j = 1 To L
arr(j) = Val(Mid(isbn, j, 1))
Next
For j = 1 To L
s1 = s1 + arr(j) * molt(j)
Next
Debug.Print s1
End Sub |
Public Function CheckIsbn13(codice As String) As String
Dim i As Integer
Dim r As Integer
Dim somma As Long
codice = Replace(codice, "-", "")
If (Len(codice) < 12) Or (Len(codice) > 13) Then
MsgBox "Codice Errato"
Exit Function
End If
For i = 1 To 12
r = CInt(Mid(codice, i, 1))
If i Mod 2 = 1 Then
somma = somma + r
Else
somma = somma + r * 3
End If
Next
r = somma Mod 10
If r <> 0 Then r = 10 - r
CheckIsbn13 = CStr(r)
End Function |
Public Function Sbn13_Ok(codice As String) As Boolean
Dim i As Integer
Dim somma As Long
codice = Replace(codice, "-", "")
If Len(codice) <> 13 Then
Sbn13_Ok = False
Else
For i = 1 To 12
somma = somma + CInt(Mid(codice, i, 1)) * (3 - 2 * (i Mod 2))
Next
r = somma Mod 10
Sbn13_Ok = CStr(IIf(somma Mod 10 = 0, 0, 10 - somma Mod 10)) = Mid(codice, 13, 1)
End If
End Function
Sub test()
MsgBox Sbn13_Ok(Range("A1"))
End Sub
|
| scossa's web site |
| Se tu hai una mela, ed io ho una mela, e ce le scambiamo, allora tu ed io abbiamo sempre una mela per uno. Ma se tu hai un'idea, ed io ho un'idea, e ce le scambiamo, allora abbiamo entrambi due idee. (George Bernard Shaw) |
| scossa's web site |
| Se tu hai una mela, ed io ho una mela, e ce le scambiamo, allora tu ed io abbiamo sempre una mela per uno. Ma se tu hai un'idea, ed io ho un'idea, e ce le scambiamo, allora abbiamo entrambi due idee. (George Bernard Shaw) |
'---------------------------------------------------------------------------------------
' Procedure : CheckIsbn
' Author : scossa
' Date : 04/11/2014
' Purpose :
'---------------------------------------------------------------------------------------
'
Public Function CheckIsbn(ByVal sIsbn As String) As Variant
Dim vRet_ As Variant
Dim nLen As Long
nLen = Len(sIsbn)
If nLen = 13 Then
vRet_ = Evaluate("IF(MOD(SUM({1,3,1,3,1,3,1,3,1,3,1,3,1}*INDEX(MID(" & sIsbn & ",{1,2,3,4,5,6,7,8,9,10,11,12,13},1),)),10)=0,""OK"",""ERRATO"")")
ElseIf nLen = 10 Then
vRet_ = Replace(Evaluate("11-MOD(SUM({10,9,8,7,6,5,4,3,2}*INDEX(MID(" & Replace(sIsbn, "X", "") & ",{1,2,3,4,5,6,7,8,9},1),)),11)"), 10, "X") = Right(sIsbn, 1)
Else
vRet_ = ""
End If
CheckIsbn = vRet_
End Function
|
| scossa's web site |
| Se tu hai una mela, ed io ho una mela, e ce le scambiamo, allora tu ed io abbiamo sempre una mela per uno. Ma se tu hai un'idea, ed io ho un'idea, e ce le scambiamo, allora abbiamo entrambi due idee. (George Bernard Shaw) |
| scossa's web site |
| Se tu hai una mela, ed io ho una mela, e ce le scambiamo, allora tu ed io abbiamo sempre una mela per uno. Ma se tu hai un'idea, ed io ho un'idea, e ce le scambiamo, allora abbiamo entrambi due idee. (George Bernard Shaw) |
Private Sub GoBack()
Me.TextBox1.BackColor = &H80000005
blExit = True
CommandButton2_Click
Unload Me
Sheets("Menu").Select
End Sub
Private Sub EmptyISBN()
With Me.TextBox1
If MsgBox(Prompt:="Campo Obligatorio!" & vbNewLine & vbNewLine _
& "REINTENTAR para volver a ingresar o CANCELAR para Salir", _
Buttons:=vbRetryCancel, Title:="Puesto de Libros") = vbCancel _
Then
.BackColor = &H80000005
GoBack
Else
.BorderStyle = fmBorderStyleSingle
.BorderColor = RGB(255, 80, 20)
.BackColor = RGB(255, 255, 10)
TextBox11.Text = ""
End If
End With
End Sub
Private Sub ValidISBN()
With TextBox1
TextBox11.Text = "ISBN VÁLIDO"
.BorderStyle = fmBorderStyleSingle
.BorderColor = RGB(0, 0, 70)
.BackColor = RGB(150, 200, 255)
End With
End Sub
Private Sub InvalidISBN()
TextBox11.Text = "ISBN NO VÁLIDO"
With TextBox1
If MsgBox(Prompt:="Ingresar un ISBN válido" _
& vbNewLine _
& vbNewLine _
& "REINTENTAR para volver a ingresar o CANCELAR para Salir", _
Buttons:=vbRetryCancel, _
Title:="Puesto de Libros") <> vbCancel _
Then
.BackColor = &H80000005
.BorderStyle = fmBorderStyleSingle
.BorderColor = RGB(255, 80, 20)
.BackColor = RGB(255, 255, 10)
.SetFocus
Else
GoBack
End If
.Text = ""
End With
End Sub
Private Sub CommandButton5_Click()
Dim cdgo, chrcontr As String
Dim Res As VbMsgBoxResult
If Not blExit Then
With TextBox1
cdgo = TextBox1.Text
If cdgo = "" Then
EmptyISBN
ElseIf cdgo = "111" Then
TextBox11.Text = "SÍN ISBN"
.BorderStyle = fmBorderStyleSingle
.BorderColor = RGB(0, 0, 70)
.BackColor = RGB(150, 200, 255)
ElseIf Len(cdgo) = 13 Then
TextBox10.Text = CheckIsbn13(TextBox1.Text)
If CInt(Mid(cdgo, 13, 1)) = TextBox10.Text Then
ValidISBN
Else
InvalidISBN
End If
ElseIf Len(cdgo) = 10 Then
If IsbnOk(cdgo) Then
ValidISBN
Else
InvalidISBN
End If
Else
InvalidISBN
End If
End With
End If
End Sub
|
| scossa's web site |
| Se tu hai una mela, ed io ho una mela, e ce le scambiamo, allora tu ed io abbiamo sempre una mela per uno. Ma se tu hai un'idea, ed io ho un'idea, e ce le scambiamo, allora abbiamo entrambi due idee. (George Bernard Shaw) |
Public Function Sbn13_Ok(codice As String) As Boolean
Dim i As Integer
Dim somma As Long
codice = Replace(codice, "-", "")
If Len(codice) <> 13 Then
Sbn13_Ok = False
Else
For i = 1 To 12
somma = somma + CInt(Mid(codice, i, 1)) * (3 - 2 * (i Mod 2))
Next
Sbn13_Ok = CStr(IIf(somma Mod 10 = 0, 0, 10 - somma Mod 10)) = Mid(codice, 13, 1)
End If
End Function |
codice = Trim(Replace(codice, "-", "")) |
| scossa's web site |
| Se tu hai una mela, ed io ho una mela, e ce le scambiamo, allora tu ed io abbiamo sempre una mela per uno. Ma se tu hai un'idea, ed io ho un'idea, e ce le scambiamo, allora abbiamo entrambi due idee. (George Bernard Shaw) |
