miércoles, 13 de febrero de 2008


 


 

Public
Class formSuma_de_4_en_4


 


Private
Sub cmdSuma_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSuma.Click


Dim i As
Integer, n As
Integer


Dim sn As
Single


Dim s As
Long


Dim st As
String


On
Error
GoTo Errors_cmdSuma

s = 0

st = ""

sn = Val(txtN.Text)

n = Int(sn)


If txtN.Text = ""
Then


Exit
Sub


ElseIf n <> sn Or n < 0 Or n > 30000 Then

MsgBox("Entra un número enter comprés entre 0 i 30.000", MsgBoxStyle.Exclamation)

txtN.Text = ""


Exit
Sub


End
If


For i = 1 To n - 4 Step 4

s = s + i

st = st + Str(i) + " + "


Next i

s = s + i

st = st + Str(i) + " = " + Str(s)

txtSuma.Text = st

Errors_cmdSuma:


Select
Case Err.Number


Case 0, 20 'No hi ha cap error


Case 6 'Overflow

MsgBox("Entra un número més petit", MsgBoxStyle.Information)

txtN.Text = ""


Exit
Sub


Case
Else

MsgBox("Error no previst: " + Str(Err.Number) + Err.Description)


On
Error
GoTo 0


Resume


End
Select


End
Sub


 


Private
Sub txtN_KeyUp(ByVal sender As
Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtN.KeyUp


Select
Case e.KeyValue 'Controlem l'entrada per teclat


Case 9, 16 To 20, 33 To 40, 44 To 46, 48 To 57, 91 To 93, 96 To 105, 110, 112 To 123, 144 To 145 'Tab, Ctrl-Alt, cursors, Del, 0 to 9, 0 To 9 teclat numèric, punt decimal, F1 to F12, Bloq Num-Bloq Despl


Case 13


Call cmdSuma_Click(sender, e)


Case 8, 27 'Esborrar amb BackSpace, Escape


Case
Else


'MsgBox("Entro: no número" + Str(e.KeyValue))

txtN.Text = ""


'If txtN.Text <> "" Then txtN.Text = Mid(txtN.Text, 1, Len(txtN.Text) - 1)


End
Select


End
Sub


 


Private
Sub txtN_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtN.TextChanged

txtSuma.Text = ""


End
Sub

End
Class

No hay comentarios: