Mostrando las entradas con la etiqueta Break. Mostrar todas las entradas
Mostrando las entradas con la etiqueta Break. Mostrar todas las entradas

lunes, 5 de diciembre de 2016

Captura la Ventana activa

Código original extraído de IDE Gambas 3.9


' gambas class file

Public Sub Form_Open()

Me.W = btnTakeScreenshot.Font.TextWidth(btnTakeScreenshot.Text) + Desktop.Scale * 14
Me.Move(Desktop.X + Desktop.W - Me.W, Desktop.Y)

End


Public Sub btnTakeScreenshot_Click()

Dim hWindow As DesktopWindow
Dim hPict As Picture
Dim I As Integer
Dim sDir As String
Dim sPath As String

Me.Hide
Wait 0.1

hWindow = New DesktopWindow(Desktop.ActiveWindow)
hPict = hWindow.GetScreenshot()

sDir = Project.Dir &/ ".hidden/screenshots"
For I = 1 To 999
sPath = sDir &/ Format(Now, "yyyy-mm-dd")
If I > 1 Then sPath &= "-" & CStr(I)
sPath &= ".png"
If Not Exist(sPath) Then
If Not IsDir(sDir) Then Project.InsertDirectory(sDir)
hPict.Save(sPath)
Project.InsertFile(File.Name(sPath), File.Dir(sPath))
Break
Endif
Next

Me.Show

End

Public Sub btnClose_Click()

Me.Close

End


Aquí mi adaptación al ejemplo que queria hacer.

' gambas class file

'Código extraído de gambas (FScreenshot)
'Modificado por postapase para hacer un ejemplo
'Este ejemplo captura una foto de la ventana activa

Private sDir As String

Public Sub Form_Open()
Me.W = btnTakeScreenshot.Font.TextWidth(btnTakeScreenshot.Text) + Desktop.Scale * 14
Me.Move(Desktop.X + Desktop.W - Me.W, Desktop.Y)

sDir = User.Home &/ "MisCapturas"

If Not Exist(sDir) Then
Mkdir sDir
Wait 0.1
Endif
End

Public Sub btnTakeScreenshot_Click()
Dim hWindow As DesktopWindow
Dim hPict As Picture
Dim I As Integer
Dim sPath As String

Me.Hide
Wait 0.1

hWindow = New DesktopWindow(Desktop.ActiveWindow)
hPict = hWindow.GetScreenshot()

For I = 1 To 999
sPath = sDir &/ Format(Now, "yyyy-mm-dd")
If I > 1 Then sPath &= "-" & CStr(I)
sPath &= ".png"
If Not Exist(sPath) Then
hPict.Save(sPath)
Break
Endif
Next

Me.Show

End

Public Sub btnClose_Click()
Me.Close
End

Public Sub ToolButtonDir_Click()
If Not Exist(sDir) Then Return
Desktop.Open(sDir)
End

El código fuente esta en la Granja de Gambas, Saludos.

domingo, 19 de octubre de 2014

Solución a reto Solveet (MayorSinDigito)



Se tiene un número X y se indica un dígito Y. Devolver un número Z que sea menor a X y que no posea el dígito Y.
La función/método puede aceptar dos argumentos: el número X y el dígito Y. No es necesario agregar ninguna validación para Y.
Ejemplos:
mayorSinDigito(123, 2) => 119
mayorSinDigito(113, 2) => 111
mayorSinDigito(113, 1) => 99


' gambas class file

' by postapase

Public Sub Form_Open()
Dim Num As Integer

Repeat
cbxDigitos.Add(Num)
Inc Num
Until Num > 9
cbxDigitos.Index = 0

End

Public Sub btnBuscar_Click()
MayorSinDigito(txtMayor.Text, cbxDigitos.Text)
End

Public Sub MayorSinDigito(Mayor As String, Digito As Integer)
Dim a, Resta1 As Integer

Resta1 = Mayor - 1

For a = Resta1 To 1 Step -1
If InStr(CString(a), CString(Digito)) = 0 Then
LabResultado.Text = "Número mayor es:" & a & " , sin digito " & Digito
Break
Endif
Next

End

martes, 2 de septiembre de 2014

Break

Ejemplo simple de como usar Break.



' gambas class file

'by postapase
'usando Break

Public ArrayDeNumeros As New Integer[] 'declaramos un array
' que contendra solo números (tipo integer)y lo inicializamos con New

Public Sub Form_Open()
Dim x As Integer 'declaramos una variable de tipo numerico llamada x para el bucle

Me.Center 'centra el formulario en referencia al escritorio

For x = 1 To 9999 'bucle que agregará al array numérico llamado ArrayDeNumeros los números del 1 al 9999
ArrayDeNumeros.Add(x) ' add lo que hace es agregar el número que contiene x al array
Next

End

Public Sub BuscarNumero()
Dim x As Integer

If Val(txtNumero.Text) <= 0 Then
txtNumero.Text = ""
txtNumero.SetFocus
Return
Endif

For x = 0 To ArrayDeNumeros.Count - 1
LabArray.Text = ArrayDeNumeros[x] 'esto visualiza el número del array actual que se comparara con el número ingresado.
Wait 0.01 ' genera una pausa antes de continuar asi podemos visualizar mejor el proceso
If ArrayDeNumeros[x] = txtNumero.Text Then 'si el item del array es igual al textbox se activa el mensaje
' y el Break, ya que no tiene sentido seguir buscando pues ya encontramos el número, ahí el sentido
' que tiene el comando Break
Message("Break detuvo el bucle porque tu número fue encontrado\nEl número es: " & ArrayDeNumeros[x])
txtNumero.Text = "" 'deja vacío el textbox
txtNumero.SetFocus 'lleva el foco al textbox y queda titilando el cursor pronto para escribir nuevamente
Break ' detiene el bucle y continua leyendo el código después de la instrucción Next
Endif
Next

End


Public Sub btnBuscar_Click()
BuscarNumero 'ejecuta la rutina BuscarNumero
End

Public Sub txtNumero_KeyPress() 'evento que sucede cuando presionamos una tecla
Select Case Key.Code ' examina que tecla fue presionada
Case 48 To 57 'si se preciona alguna tecla del 0 al nueve no hace nada
Case Else ' en cambio si se preciona cualquier tecla que no sea las incluidas en el Case anterior detiene el evento
'lo que logramos con esto es que el usuario no pueda teclear letras o cualquier caracter que no sea un número
Stop Event
End Select
End
Código fuente: Break-0.0.1.tar.gz