|
Visual Basic-5
32.- Al revés
 |
Private Sub cmdPulsa_Click()
a$ = Text1.Text
x = Len(a$)
For n = x To 1 Step -1
b$ = Mid(a$, n, 1)
c$ = c$ + UCase(b$)
Next n
Text2.Text = c$
' Hay una funcion llamada StrReverse("asd")
' que hace lo mismo
End Sub
|
33.- Codifica
 |
Private Sub Command1_Click()
a$ = Text1.Text
x = Len(a$)
For n = 1 To x
ca$ = Mid(a$, n, 1)
cod = Asc(ca$)
Text2.Text = Text2.Text & cod & "-"
Next n
End Sub
Private Sub Command2_Click()
Text1.Text = ""
Text2.Text = ""
End Sub
|
|
Esto es un ejemplo de concatenación:
Text2.Text = Text2.Text & cod & "-"
|
34.- Colores
Los botones se han creado mediante una matriz de controles:
Boton(0), Boton(1), Boton(2), Boton(3), Boton(4), ..... |
Hay que poner el Timer1.Interval en
10 |
Private Sub Timer1_Timer()
Randomize Timer
x = Int(Rnd * 8)
c = Int(Rnd * 6) + 9
Boton(x).BackColor = QBColor(c)
End Sub
|
 |
35.- Semáforo
Private Sub Timer1_Timer()
x = x + 1
If x = 8 Then x = 0
Select Case x
Case Is < 3
Shape1.FillColor = QBColor(12)
Shape2.FillColor = QBColor(6)
Shape3.FillColor = QBColor(2)
Case Is = 4
Shape1.FillColor = QBColor(4)
Shape2.FillColor = QBColor(14)
Shape3.FillColor = QBColor(2)
Case Is > 4
Shape1.FillColor = QBColor(4)
Shape2.FillColor = QBColor(6)
Shape3.FillColor = QBColor(10)
End Select
End Sub
|
 |
36.- Temporizador
 |
Dim ahora, total, comenzo, fin, prog
Private Sub Command1_Click()
hh = Val(Text1.Text)
mm = Val(Text2.Text)
ss = Val(Text3.Text)
total = hh * 3600 + mm * 60 + ss
comenzo = Timer
fin = comenzo + total
Timer1.Interval = 1
If Option1.Value = True Then prog = "C:\Windows\Calc.exe"
If Option2.Value = True Then prog = "C:\Archivo....Mspaint.exe"
If Option3.Value = True Then prog = "C:\Windows\Explorer.exe"
End Sub
Private Sub Timer1_Timer()
ahora = Timer
Text4.Text = Int(ahora - comenzo)
If ahora > fin Then
d = Shell(prog, 1)
Timer1.Interval = 0
End If
End Sub
|
|
Las rutas de las aplicaciones tienes
que cambiarlas.
Si tienes XP, la calculadora estará en \Windows\System32\calc.exe.
Para hacer las pruebas establece pocos segundos: 6
|
37.- Factorial
Private Sub otro()
repe: a = InputBox("Introduce un número del 1 al 20", "Factorial")
If a = "" Then End
If Val(a) < 1 Or Val(a) > 20 Then
b = MsgBox("Entrada no válida", vbOKOnly, "Error")
GoTo repe
Else
x = 1
For n = 1 To a
x = x * n
Next n
b = MsgBox("El factorial de " & a & " es : " & x, vbOKOnly, "Resultado")
otro
End If
End Sub
Private Sub Form_Load()
otro
End Sub
|
|
Estudio del InputBox y MsgBox.
No hace falta controles, sólo el formulario y la Sub-rutina
otro.
|
38.- Multiplicar
|
|
Dim r, m
Private Sub Command1_Click()
Text2.Text = ""
m = Val(Text1.Text)
If m > 0 And m < 10 Then
For n = 0 To 9
r = n * m
Text2.Text = Text2.Text & m & " x " & n & " = " & r & vbCrLf
Next n
Else
re = MsgBox("Número no válido." & vbCrLf & "Debe estar_
comprendido entre 1 y 9.", vbCritical + vbOKOnly, "No vale")
End If
End Sub
|
39.- Disparo
Dim h, v, i, a, b, c
Private Sub Command1_Click()
Timer2.Interval = 10
Command1.Enabled = False
End Sub
Private Sub Form_Load()
i = 100
b = 5160
End Sub
Private Sub Timer1_Timer()
h = h + i
If h > Width Then i = -100
If h < 0 Then i = 100
Super.Move h, v
End Sub
Private Sub Timer2_Timer()
b = b - 100
If b < 0 Then
b = 5160
Timer2.Interval = 0
Command1.Enabled = True
End If
Check1.Move 3420, b
End Sub
|
 |
Bajo el botón azul de la parte inferior
hay un CheckBox.
El CheckBox sólo sube. |
40.- Frutas
Dim na, nakg, napts, ma, makg, mapts,_
mel, melkg, melpts, pla, plakg,_
plapts As Long
Private Sub Form_Load()
End Sub
Private Sub Text5_Change()
On Error Resume Next
na = Text1.Text
nakg = Text5.Text
napts = na * nakg
Text9.Text = napts
suma
End Sub
Private Sub Text6_Change()
On Error Resume Next
ma = Text2.Text
makg = Text6.Text
mapts = ma * makg
Text10.Text = mapts
suma
End Sub
Private Sub Text7_Change()
On Error Resume Next
mel = Text3.Text
melkg = Text7.Text
melpts = mel * melkg
Text11.Text = melpts
suma
End Sub
Private Sub Text8_Change()
On Error Resume Next
pla = Text4.Text
plakg = Text8.Text
plapts = pla * plakg
Text12.Text = plapts
suma
End Sub
Public Sub suma()
On Error Resume Next
total = napts + mapts + melpts _
+ plapts
Text13.Text = total
End Sub
|
 |
Página
siguiente (6) >>
|
|