prova13

gestione stringa con funzioni varie vedi prova13.xls

 

Private Sub CommandButton1_Click()
Rem esercitazione per gestione stringa
Rem notare che se manca segno + nella stringa
Rem viene conteggiato automaticamente
Rem esempio stringa 125abc risulta lunga 6 ma valore 125 lungo non 3 ma 4

Dim nv, nt As Integer
Rem inserire segno + o -
nt = 0
nv = 0
's = "+125abc"
's="125abc"
s = "+123ab456xyz"
ls = Len(s)
vs = Val(s)
sv = Str$(vs)
lv = Len(sv)
sr = Right(s, (ls - lv))
lsr = Len(sr)
sv2 = Mid$(sr, 3, 3)
ss2 = Left(sr, 2)
ss3 = Right(sr, 3)

Cells(1, 1) = "stringa s"
Cells(2, 1) = "lunghezza ls"
Cells(3, 1) = "valore vs"
Cells(4, 1) = "stringa valore sv"
Cells(5, 1) = "lunghezza stringa valore lv"
Cells(6, 1) = "stringa residua sr"
Cells(7, 1) = "lunghezza stringa residua lsr"
Cells(8, 1) = "numero cifre residue nv"
Cells(9, 1) = "numero caratteri residui nt"
Cells(10, 1) = "stringa numerica interna sv2"
Cells(11, 1) = "stringa iniziale ss2"
Cells(12, 1) = "stringa finale ss3"


Cells(1, 3) = "ricerca cifre e caratteri in residua"
For a = 1 To lsr
ca = Mid$(sr, a, 1)
If IsNumeric(ca) Then
nv = nv + 1
Else
nt = nt + 1
End If
Cells(a, 5) = ca
Next a

Cells(1, 2) = s
Cells(2, 2) = ls
Cells(3, 2) = vs
Cells(4, 2) = sv
Cells(5, 2) = lv
Cells(6, 2) = sr
Cells(7, 2) = lsr
Cells(8, 2) = nv
Cells(9, 2) = nt

Cells(10, 2) = sv2
Cells(11, 2) = ss2
Cells(12, 2) = ss3

End Sub

Private Sub CommandButton2_Click()
For riga = 1 To 13
For colonna = 1 To 6
Cells(riga, colonna) = ""
Next colonna
Next riga
End Sub

Private Sub CommandButton3_Click()
Rem esercitazione per gestione stringa

Dim nv, nt As Integer
Rem inserire segno + o -
nt = 0
nv = 0
s = "-123dfab45676xyz"
ls = Len(s)
vs = Val(s)
sv = Str$(vs)
lv = Len(sv)
sr = Right(s, (ls - lv))
lsr = Len(sr)
sv2 = Mid$(sr, 5, 5)
ss2 = Left(sr, 4)
ss3 = Right(sr, 3)

Cells(1, 1) = "stringa s"
Cells(2, 1) = "lunghezza ls"
Cells(3, 1) = "valore vs"
Cells(4, 1) = "stringa valore sv"
Cells(5, 1) = "lunghezza stringa valore lv"
Cells(6, 1) = "stringa residua sr"
Cells(7, 1) = "lunghezza stringa residua lsr"
Cells(8, 1) = "numero cifre residue nv"
Cells(9, 1) = "numero caratteri residui nt"
Cells(10, 1) = "stringa numerica interna sv2"
Cells(11, 1) = "stringa iniziale ss2"
Cells(12, 1) = "stringa finale ss3"


Cells(1, 3) = "ricerca cifre e caratteri in residua"
For a = 1 To lsr
ca = Mid$(sr, a, 1)
If IsNumeric(ca) Then
nv = nv + 1
Else
nt = nt + 1
End If
Cells(a, 5) = ca
Next a

Cells(1, 2) = s
Cells(2, 2) = ls
Cells(3, 2) = vs
Cells(4, 2) = sv
Cells(5, 2) = lv
Cells(6, 2) = sr
Cells(7, 2) = lsr
Cells(8, 2) = nv
Cells(9, 2) = nt

Cells(10, 2) = sv2
Cells(11, 2) = ss2
Cells(12, 2) = ss3

End Sub