Beruflich Dokumente
Kultur Dokumente
--------------------------------------------------------------------------------
Uso de Random:
La funcin Rnd o Random posee la virtud de obtener nmeros aleatorios entre
0 y 1:
El nico inconveniente a la hora de usar Rnd, es que hay que inicializarlo, en
otro caso,
el resultado de la funcin Rnd, ser siempre el mismo dentro de un
determinado ordenador.
Por ejemplo, el cdigo:
Otra forma:
En el Formulario [Form1 por defecto] :
Private Sub Form_Load()
Dim LineWidth As Long
Me.Caption = "Rich Text Box Ejemplo de Impresion"
Command1.Move 10, 10, 600, 380
Command1.Caption = "&Imprimir"
RichTextBox1.SelFontName = "Verdana, Tahoma, Arial"
RichTextBox1.SelFontSize = 10
LineWidth = WYSIWYG_RTF(RichTextBox1, 1440, 1440)
Me.Width = LineWidth + 200
End Sub
Private Sub Form_Resize()
RichTextBox1.Move 100, 500, Me.ScaleWidth - 200, Me.ScaleHeight - 600
End Sub
Private Sub Command1_Click()
PrintRTF RichTextBox1, 1440, 1440, 1440, 1440
End Sub
Crear un mdulo y escribir:
Private Type Rect
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Type CharRange
cpMin As Long
cpMax As Long
End Type
Private Type FormatRange
hdc As Long
hdcTarget As Long
rc As Rect
rcPage As Rect
chrg As CharRange
End Type
Private Const WM_USER As Long = &H400
Private Const EM_FORMATRANGE As Long = WM_USER + 57
Private Const EM_SETTARGETDEVICE As Long = WM_USER + 72
Private Const PHYSICALOFFSETX As Long = 112
Private Const PHYSICALOFFSETY As Long = 113
Private Declare Function GetDeviceCaps Lib "gdi32" ( _
ByVal hdc As Long, ByVal nIndex As Long) As Long
ChDrive App.Path
Directorio = App.Path
If Len(Directorio) > 3 Then
Directorio = Directorio & ""
End If
End Sub
1"
2"
3"
4"
5"
End Sub
Private Sub Command2_Click()
'Eliminacion de todos los elementos seleccionados
Dim Resp As Long
Resp = SendMessageLong(List1.hwnd, &H185&, False, -1)
End Sub
End Sub
otra forma:
Insertar tres TextBox, cambiar la propiedad KeyPreview del formulario a True y
escribir el siguiente cdigo:
Private Sub Form_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
SendKeys "{tab}"
KeyAscii = 0
End If
End Sub
I = Len(Text1.Text)
Text1.SelStart = I
End Sub
Pulse Insertar
Caption -> Name -> MnuIndex
Index -> 0
Pulse Aceptar
Escribir el siguiente cdigo en el formulario:
Private ultElem As Integer
Private Sub Form_Load()
ultElem = 0
End Sub
Private Sub MnuQuitar_Click()
Unload MnuIndex(ultElem)
ultElem = ultElem - 1
If ultElem = 0 Then
MnuQuitar.Enabled = False
End If
End Sub
Private Sub MnuSalir_Click()
End
End Sub
Private Sub MnuAadir_Click()
ultElem = ultElem + 1
Load MnuIndex(ultElem)
MnuIndex(ultElem).Caption = "Menu -> " + Str(ultElem)
MnuQuitar.Enabled = True
End Sub
If bit = 1 Then
Text1.Text = "Resolucion de 1 bit / 2 colores"
ElseIf bit = 4 Then
Text1.Text = "Resolucion de 4 bits / 16 colores"
End If
ElseIf col = 8 Then
Text1.Text = "Resolucion de 8 bits / 256 colores"
ElseIf col = 16 Then
Text1.Text = "Resolucion de 16 bits / 65000 colores"
Else
Text1.Text = "Resolucion de 16 M colores"
End If
largo = GetDeviceCaps(Form1.hdc, 8)
alto = GetDeviceCaps(Form1.hdc, 10)
Text1.Text = Text1.Text & " " & largo & "x" & alto & " pixels"
End Sub
--------------------------------------------------------------------------------
+ "Kb" + vbCrLf
+ "Kb" + vbCrLf
+ "Kb" + vbCrLf
+ "Kb" + vbCrLf +
dwPlatformId As Long
szCSDVersion As String * 128
End Type
Type MEMORYSTATUS
dwLength As Long
dwMemoryLoad As Long
dwTotalPhys As Long
dwAvailPhys As Long
dwTotalPageFile As Long
dwAvailPageFile As Long
dwTotalVirtual As Long
dwAvailVirtual As Long
End Type
Declare Function GetVersionEx Lib "kernel32"
Alias "GetVersionExA" (LpVersionInformation
As OSVERSIONINFO) As Long
Declare Sub GlobalMemoryStatus Lib "kernel32"
(lpBuffer As MEMORYSTATUS)
Declare Sub GetSystemInfo Lib "kernel32"
(lpSystemInfo As SYSTEM_INFO)
Public
Public
Public
Public
Public
Const
Const
Const
Const
Const
PROCESSOR_INTEL_386 = 386
PROCESSOR_INTEL_486 = 486
PROCESSOR_INTEL_PENTIUM = 586
PROCESSOR_MIPS_R4000 = 4000
PROCESSOR_ALPHA_21064 = 21064
strOrg = Space$(256)
lngLen = Len(strOrg)
x = RegQueryValueEx(hKey, "RegisteredOrganization", 0, lngType,
ByVal strOrg, lngLen)
If x = 0 And lngType = REG_SZ And lngLen > 1 Then
strOrg = Left$(strOrg, lngLen - 1)
Else
strOrg = "Unknown"
End If
Label1.Caption = "Usuario: " & strUser
Label2.Caption = "Empresa: " & strOrg
x = RegCloseKey(hKey)
End Sub
Usar:
Move (Screen.Width - Width) 2, (Screen.Height - Height) 2
En vez de:
Form1.Left = Screen.Width - Width 2
Form1.Top = Screen.Height - Height 2
--------------------------------------------------------------------------------
Llamada: Espera(5)
Sub Espera(Segundos As Single)
Dim ComienzoSeg As Single
Dim FinSeg As Single
ComienzoSeg = Timer
FinSeg = ComienzoSeg + Segundos
Do While FinSeg > Timer
DoEvents
If ComienzoSeg > Timer Then
FinSeg = FinSeg - 24 * 60 * 60
End If
Loop
End Sub
-------------------------------------------------------------------------------Editor de texto:
Cortar texto:
Clipboard.SetText Text1.SelText
Text1.SelText = ""
Text1.SetFocus
Deshacer texto: (Nota: esta operacin slo es eficaz con el control Rich
TextBox).
En un mdulo copie esta lnea:
Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal _
hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Long) As
Long
Esta es la instruccin de la funcin deshacer:
UndoResultado = SendMessage(Text1.hwnd, &HC7, 0&, 0&
If UndoResultado = -1 Then
Beep
MsgBox "Error al intentar recuperar.", 20, "Deshacer texto"
End If
hWndInsertAfter
As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As
Long,_
ByVal wFlags As Long) As Long
Global Ventana As Long
Global Const Muestra = &H40
Global Const Oculta = &H80
En un formulario ponga dos botones y escriba el cdigo correspondiente
a cada uno de ellos:
'Oculta la barra de tareas
Private Sub Command1_Click()
Ventana = FindWindow("Shell_traywnd", ""
Call SetWindowPos(Ventana, 0, 0, 0, 0, 0, Oculta)
End Sub
'Muestra la barra de tareas
Private Sub Command2_Click()
Call SetWindowPos(Ventana, 0, 0, 0, 0, 0, Muestra)
End Sub
NumC = Len(Texto.Text)
If NumC > Linea Then
NumB = NumC Linea
For I = 0 To NumB
Texto.SelStart = (Linea * I)
Texto.SelLength = Linea
Bloque = Texto.SelText
Printer.Print Bloque
Next I
Else
Printer.Print Texto.Text
End If
Printer.EndDoc
End Sub
--------------------------------------------------------------------------------
End If
End Sub
Escribir en "Prueba.Ini":
Private Sub Form_Unload(Cancel As Integer)
Dim I As Integer
Dim Est As String
Est = "Ejemplo - Apartado"
I = WritePrivateProfileString("Ejemplo", "Nombre", Est, "Ejemplo.ini"
End Sub
(Nota: si I=0 quiere decir que no existe Informacin en la lnea de fichero Ini a
la
que hacemos referencia. El fichero "Ejemplo.Ini" se crear automticamente).
Barra (HScroll1.Value)
End Sub
En el evento Paint del formulario, escribir:
Private Sub Form_Paint()
Barra (HScroll1.Value)
End Sub
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
formulario ms y un mdulo.
Pegue el siguiente cdigo en el
mdulo:
Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal
hWndNewParent As Long) As Long
Peguar el siguiente cdigo en el formulario principal:
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Unload Form2
End Sub
Private Sub Command1_Click()
Dim ret As Integer
If doshow = False Then
ret = SetParent(Form2.hWnd, Form1.hWnd)
Form2.Left = 0
Form2.Top = 0
Form2.Show
doshow = True
Else
Form2.Hide
doshow = False
End If
End Sub
End Sub
Trucos Breves 2
...
' Cierro
DB.Close
' Libero la memoria
Set DB = Nothing