The document contains code for a program with three commands. Command 1 calculates the sum of integers from 1 to a number entered by the user. It displays the results in a list. Command 2 clears the text boxes and list. Command 3 closes the program. The code includes validation to require numeric input only for the text boxes.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
67 views7 pages
Ejercicios en Visual Basic
The document contains code for a program with three commands. Command 1 calculates the sum of integers from 1 to a number entered by the user. It displays the results in a list. Command 2 clears the text boxes and list. Command 3 closes the program. The code includes validation to require numeric input only for the text boxes.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7
Dim TOTAL As Integer
Dim num As Integer
Dim prog As Integer
Private Sub Command1_Click()
If Text1.Text = "" Then MsgBox "Debe ingresar un número" Text1.SetFocus Else TOTAL = Val(Text1.Text) For I = 1 To TOTAL num = 1 prog = 0 For j = 1 To I prog = prog + j Next List1.AddItem "T" & I & " = " & prog Next End If End Sub
Private Sub Command2_Click()
Text1.Text = "" List1.Clear Text1.SetFocus End Sub
Private Sub Command3_Click()
Unload Me End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 And Len(Text1) > 0 Then KeyAscii = 0 SendKeys "{tab}" ElseIf KeyAscii <> 8 Then If Not IsNumeric("0" & Text1.Text & Chr(KeyAscii)) Then Beep KeyAscii = 0 End If End If End Sub
Dim num As Integer
Dim prog As Integer
Private Sub Command1_Click()
If Text1.Text = "" Then MsgBox "Debe ingresar un número" Text1.SetFocus Else num = Val(Text1.Text) prog = 0 For I = 1 To num prog = prog + I Next Text2.Text = prog End If End Sub
Private Sub Command2_Click()
Text1.Text = "" Text2.Text = "" Text1.SetFocus End Sub
Private Sub Command3_Click()
Unload Me End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 And Len(Text1) > 0 Then KeyAscii = 0 SendKeys "{tab}" ElseIf KeyAscii <> 8 Then If Not IsNumeric("0" & Text1.Text & Chr(KeyAscii)) Then Beep KeyAscii = 0 End If End If End Sub
Private Sub Text2_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 And Len(Text2) > 0 Then KeyAscii = 0 SendKeys "{tab}" ElseIf KeyAscii <> 8 Then If Not IsNumeric("0" & Text2.Text & Chr(KeyAscii)) Then Beep KeyAscii = 0 End If End If End Sub Dim num As Integer Dim p As Integer
Private Sub Command1_Click()
If Text1.Text = "" Then MsgBox "Debe ingresar un número" Text1.SetFocus Else p = Val(Text1.Text) num = Val(Text2.Text) z=1 For I = 1 To num z = z + (2 * p) * (I - 1) List1.AddItem "S" & I & " = " & z Next End If End Sub
Private Sub Command2_Click()
Text1.Text = "" Text2.Text = "" List1.Clear Text1.SetFocus End Sub Private Sub Command3_Click() Unload Me End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 And Len(Text1) > 0 Then KeyAscii = 0 SendKeys "{tab}" ElseIf KeyAscii <> 8 Then If Not IsNumeric("0" & Text1.Text & Chr(KeyAscii)) Then Beep KeyAscii = 0 End If End If End Sub
Private Sub Text2_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 And Len(Text2) > 0 Then KeyAscii = 0 SendKeys "{tab}" ElseIf KeyAscii <> 8 Then If Not IsNumeric("0" & Text2.Text & Chr(KeyAscii)) Then Beep KeyAscii = 0 End If End If End Sub Dim num As Integer Dim p As Integer
Private Sub Command1_Click()
If Text1.Text = "" Then MsgBox "Debe ingresar un número" Text1.SetFocus Else p = Val(Text1.Text) num = Val(Text2.Text) z=1 For I = 1 To num z = z + (2 * p) * (I - 1) Next Text3.Text = "S" & num & " = " & z End If End Sub
Private Sub Command2_Click()
Text1.Text = "" Text2.Text = "" Text3.Text = "" Text1.SetFocus End Sub Private Sub Command3_Click() Unload Me End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 And Len(Text1) > 0 Then KeyAscii = 0 SendKeys "{tab}" ElseIf KeyAscii <> 8 Then If Not IsNumeric("0" & Text1.Text & Chr(KeyAscii)) Then Beep KeyAscii = 0 End If End If End Sub
Private Sub Text2_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 And Len(Text2) > 0 Then KeyAscii = 0 SendKeys "{tab}" ElseIf KeyAscii <> 8 Then If Not IsNumeric("0" & Text2.Text & Chr(KeyAscii)) Then Beep KeyAscii = 0 End If End If End Sub
(Dear America) White, Ellen Emerson - Voyage On The Great Titanic - The Diary of Margaret Ann Brady - RMS Titanic, 1912 - Ellen Emerson White (1998, Scholastic Inc.) - Libgen - Li