Advertisement
testingpastebin00

Untitled

Sep 4th, 2023
495
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Declare Function OpenClipboard Lib "User32" (ByVal hwnd As Long) As Long
  2. Declare Function EmptyClipboard Lib "User32" () As Long
  3. Declare Function CloseClipboard Lib "User32" () As Long
  4. Declare Function SetClipboardData Lib "User32" (ByVal wFormat As Long, ByVal hMem As Long) As Long
  5. Declare Function GlobalAlloc Lib "Kernel32" (ByVal wFlags As Long, ByVal dwBytes As Long) As Long
  6. Declare Function GlobalLock Lib "Kernel32" (ByVal hMem As Long) As Long
  7. Declare Function GlobalUnlock Lib "Kernel32" (ByVal hMem As Long) As Long
  8. Declare Sub CopyMemory Lib "Kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
  9.  
  10. Sub BucleInfinito()
  11.     Dim textoAleatorio As String
  12.    
  13.     Do
  14.         ' Genera una palabra de 5 caracteres aleatorios
  15.        textoAleatorio = GenerarTextoAleatorio(5)
  16.        
  17.         ' Coloca el texto aleatorio en el portapapeles
  18.        CopiarAlPortapapeles textoAleatorio
  19.        
  20.         ' Espera un segundo antes de continuar
  21.        Application.Wait Now + TimeValue("00:00:01")
  22.     Loop
  23. End Sub
  24.  
  25. Function GenerarTextoAleatorio(ByVal Longitud As Integer) As String
  26.     Dim caracteres As String
  27.     Dim i As Integer
  28.    
  29.     ' Define los caracteres permitidos para el texto aleatorio
  30.    caracteres = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  31.    
  32.     ' Genera el texto aleatorio
  33.    Randomize
  34.     For i = 1 To Longitud
  35.         GenerarTextoAleatorio = GenerarTextoAleatorio & Mid(caracteres, Int((Len(caracteres) * Rnd) + 1), 1)
  36.     Next i
  37. End Function
  38.  
  39. Sub CopiarAlPortapapeles(ByVal Texto As String)
  40.     Dim hGlobalMemory As Long
  41.     Dim lpGlobalMemory As Long
  42.     Dim RetVal As Long
  43.    
  44.     ' Abre el portapapeles
  45.    OpenClipboard 0&
  46.    
  47.     ' Borra el contenido actual del portapapeles
  48.    EmptyClipboard
  49.    
  50.     ' Obtén un identificador de memoria global para el texto
  51.    hGlobalMemory = GlobalAlloc(&H2, Len(Texto) + 1)
  52.    
  53.     ' Bloquea la memoria global y copia el texto en ella
  54.    lpGlobalMemory = GlobalLock(hGlobalMemory)
  55.     CopyMemory ByVal lpGlobalMemory, ByVal StrPtr(Texto), Len(Texto)
  56.     GlobalUnlock hGlobalMemory
  57.    
  58.     ' Coloca la memoria global en el portapapeles
  59.    RetVal = SetClipboardData(&H1, hGlobalMemory)
  60.    
  61.     ' Cierra el portapapeles
  62.    CloseClipboard
  63. End Sub
  64.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement