|
111
|
Programación / Programación Visual Basic / Re: contar saltos de linea RichTextBox VB
|
en: 6 Abril 2007, 01:22 am
|
creo que el problema es el contador "i" si tienes un salto de linea en la posicion 3 al entrar al ciclo te va a mandar 3 veces el mensaje. lo que debes hacer es mover tu contador al encontar un salto de linea, tú código quedaría asi: Dim sText, sFnd Dim lPos Dim cont As Integer
cont = 1 'Texto en el cual se va a buscar, puede ser un cuadro de texto o cualquier String. sText = RichTextBox1.Text sFnd = vbCrLf 'Texto buscado.
NumText = Len(RichTextBox1.Text) For i = 1 To NumText lPos = InStr(i, sText, sFnd) If lPos > 0 Then Call MsgBox("La cadena se encontró en la posición " & lPos, vbExclamation)
'Aqui mueves "i" despues del salto de linea encontrado i = lpos+2
Else Call MsgBox("No se encontró la cadena") End If 'cont = cont + 1 Next i
|
|
|
112
|
Programación / Programación Visual Basic / Re: Papel continuo personalizado XP
|
en: 21 Marzo 2007, 00:54 am
|
Al establecer las propiedades Height o Width de una impresora se establece automáticamente vbPRPSUser en PaperSize. creo que lo que debes hacer es esto: Printer.ScaleMode = vbTwips printer.Width = 23 * 567 ' 1 cm = 567 twips printer.Heigth = 13.9 * 567
|
|
|
113
|
Programación / Programación Visual Basic / Re: acces y vb
|
en: 13 Marzo 2007, 21:11 pm
|
bueno estoy aprendiendo a utilizar el visual basic y lo que necesito en este momento es como puedo yo buscar desde vb un registro de x persona desde una base de datos en acces
yo empezaria por saber algo sobre las cositas que tendría que utilizar xD http://foro.elhacker.net/index.php/topic,127987.0.htmlCoincido con "hans el topo", primero deberías leerte un manual o la ayuda del VB y en un caso extremo usar la opción de búscar (porque de BD ya se ha hablado un monton), pero para que este post no se desperdicie hay te va un poco de ayuda: 'Primero declaras variables Dim BD as database Dim TB as recrodset
'habres la BD set BD = workspaces(0).Opendatabase("c:\tararara\BD")
'Haces la búsqueda set TB = BD.OpenRecordSet("SELECT * FROM Tabla WHERE Nombre = '" & nombrequeestasbuscando & "';")
'Si lo encuentra lo muestra if TB.RecordCount > 0 Then 'si son varios registros aqui puedes hacer un bucle Text1.Text = TB!Campo1 Text2.Text = TB!Campo2 Text3.Text = TB!Campo3 Text4.Text = TB!Campo4.... end if
'Cierras la tabla y BD TB.Close BD.Close
'Liberas memoria Set TB = nothing Set BD = NOthing
[/close]
|
|
|
117
|
Programación / Programación Visual Basic / Re: Estoy muy confundido y tengo mucha impotencia!!
|
en: 29 Enero 2007, 23:52 pm
|
sabes la verdad yo me sentía igual, estaba en el nivel superior y cual fue mi sorpresa que mi maestro de !!!!! VB NO SABIA VISUAL BASIC ¡¡¡¡¡¡Cuando estaba por terminar la escuela me toco hacer un sistema de control de inventario y punto de venta para una Refaccionaría porque esa era mi proyecto de residencia, la aplicación tenia que funcionar al 100%. Lo que hice fue que me agarre un buen libro de programación y me empece a meter en foros, navegue y navegue por internet y al final me salio un muy buen programa (bueno para mi lo es). Creo que eso me sirvio más que la escuela, asi que no le traumes con eso y empieza a bajarte manuales y sobre todo PREGUNTA nunca te quedes callado. por suerte hay foros como este en el que te encuentras un mundo de gente dispuesta a ayudarte!!
Saludos!!
|
|
|
119
|
Programación / Programación Visual Basic / Re: Cambiar de ventana
|
en: 26 Enero 2007, 23:01 pm
|
me encontre un ejemplo de como listar las ventas: el ejemplo ocupa un Listview, un PictureBox, un ImgeList y un commadButton. en un módulo pones: Option Explicit
'Udt '############## Type ProcData HwndWin As Long captionWin As String Estado As String Left As Long Top As Long Right As Long Bottom As Long End Type
Type POINTAPI x As Long y As Long End Type
Type RECT Left As Long Top As Long Right As Long Bottom As Long End Type
Type WINDOWPLACEMENT length As Long flags As Long showCmd As Long ptMinPosition As POINTAPI ptMaxPosition As POINTAPI rcNormalPosition As RECT End Type 'Declaraciones Api '################# Declare Function DrawCaption Lib "user32" (ByVal hwnd As Long, ByVal hDC As Long, _ pcRect As RECT, ByVal un As Long) As Long Declare Function SetRect Lib "user32" (lpRect As RECT, ByVal X1 As Long, ByVal Y1 _ As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long Declare Function IsWindowVisible Lib "user32" (ByVal hwnd As Long) As Long Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Any, ByVal _ lParam As Long) As Long Declare Function GetWindowPlacement Lib "user32" (ByVal hwnd As Long, lpwndpl As _ WINDOWPLACEMENT) As Long Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" _ (ByVal hwnd As Long, ByVal lpString As String, _ ByVal cch As Long) As Long
'Variables '##########
Public Valores() As ProcData Public nProcesos As Integer
'Función que enumera las ventanas de windows
Public Function Listar_Ventanas(ByVal Handle As Long, _ ByVal lParam As Long) As Boolean
Dim infoWin As WINDOWPLACEMENT
Dim buffer As String * 256 Dim l As Long
nProcesos = nProcesos + 1 'redimensiona el vector ReDim Preserve Valores(1 To nProcesos) With Valores(nProcesos) .HwndWin = Handle
' Recupera el título de la ventana l = GetWindowText(Handle, buffer, Len(buffer)) 'Remplaza los Nulos .captionWin = Replace(buffer, Chr(0), vbNullString) infoWin.length = Len(infoWin) Call GetWindowPlacement(Handle, infoWin) 'Guarda el estado de la ventana Select Case infoWin.showCmd Case 1 .Estado = "Normal" Case 2 .Estado = "Minimizado" Case 3 .Estado = "Maximizado" End Select 'Guarda la posición de la ventana .Left = infoWin.rcNormalPosition.Left .Top = infoWin.rcNormalPosition.Top .Right = infoWin.rcNormalPosition.Right .Bottom = infoWin.rcNormalPosition.Bottom End With ' Continúa buscando las demás ventanas Listar_Ventanas = 1 End Function
y en un form: Option Explicit
Const SWP_HIDEWINDOW = &H80 Const SWP_SHOWWINDOW = &H40 Private Sub Command1_Click() Erase Valores nProcesos = 0 'Llama a Enumwindows para listar las ventanas y obtener la información EnumWindows AddressOf Listar_Ventanas, 0 cargar End Sub
Sub cargar()
Dim i As Integer Dim LItem As ListItem 'variable para los subitems del listview
ListView1.ListItems.Clear For i = 1 To nProcesos With Valores(i) If .captionWin <> "Program Manager" And .captionWin <> vbNullString _ And .captionWin <> "Project1" Then ' Si la ventana es visible If IsWindowVisible(.HwndWin) Then 'Obtiene el ícono de la ventana Call Obtener_Icono(.HwndWin) 'Agrega el Item y subitems al ListView Set LItem = ListView1.ListItems.Add(, , .captionWin, , _ ImageList1.ListImages.Count) LItem.SubItems(1) = .HwndWin LItem.SubItems(2) = .Estado LItem.SubItems(3) = .Left LItem.SubItems(4) = .Right LItem.SubItems(5) = .Top LItem.SubItems(6) = .Bottom End If End If End With Next
End Sub
'Sub que obtiene el ícono de la ventana y luego lo coloca en el Listview Private Sub Obtener_Icono(h As Long) 'Variable Rect para usar con el API setRect y Drawcaption Dim rec As RECT
With Picture1 'Limpia el Picturebox .Cls .Picture = Nothing Call SetRect(rec, 5, 7, 10, 10) 'Dibuja el icono en el picture pasandole al api el _ hwnd de la ventana Call DrawCaption(h, .hDC, rec, 4) .Refresh Set .Picture = Picture1.Image
End With ' Almacena la imagen en el ImageList ImageList1.ListImages.Add , , Picture:=Picture1 ' Si el ImageList no está inicializado se enlaza al ListView If ListView1.SmallIcons Is Nothing Then Set ListView1.SmallIcons = ImageList1 End If End Sub
Private Sub Form_Load() With ListView1 'vista de reporte .View = lvwReport 'Columnas .ColumnHeaders.Add , , " Título de la ventana " .ColumnHeaders.Add , , " HWND " .ColumnHeaders.Add , , " Estado " .ColumnHeaders.Add , , " Left " .ColumnHeaders.Add , , " Right " .ColumnHeaders.Add , , " Top " .ColumnHeaders.Add , , " Bottom " .ColumnHeaders(1).Width = 4000 .ColumnHeaders(2).Width = 1000 .ColumnHeaders(3).Width = 1200 .ColumnHeaders(4).Width = 700 .ColumnHeaders(5).Width = 800 .ColumnHeaders(6).Width = 800 .ColumnHeaders(7).Width = 800 End With
'Propiedades para el Picture invisible en el cual se dibuja _ el icono de la ventana mediante el Api DrawCaption With Picture1 .ScaleMode = vbPixels .Width = 260 .Height = 260 .AutoRedraw = True .BorderStyle = 0 .BackColor = ListView1.BackColor .Visible = False End With
Me.Caption = " Información de ventanas de windows " Command1.Caption = " Listar ventanas "
End Sub
con esto vas a lograr hacer una lista de las ventanas que tienes abiertas, y puedes usar la API ShowWindow para traer alguna al frente: ejemplo: Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long Const SW_SHOWNORMAL = 1 Const WM_CLOSE = &H10 Const gcClassnameMSWord = "OpusApp" Const gcClassnameMSExcel = "XLMAIN" Const gcClassnameMSIExplorer = "IEFrame" Const gcClassnameMSVBasic = "wndclass_desked_gsk" Const gcClassnameNotePad = "Notepad" Const gcClassnameMyVBApp = "ThunderForm" Private Sub Form_Load() Dim WinWnd As Long, Ret As String, RetVal As Long, lpClassName As String Ret = InputBox("Nombre de la ventana:" + vbcrlf + "Nota: el nombre debe ser exacto") 'Búsca la ventana WinWnd = FindWindow(vbNullString, Ret) If WinWnd = 0 Then MsgBox "No sé pudo encontrar la ventana": Exit Sub 'Muestra la ventana ShowWindow WinWnd, SW_SHOWNORMAL End Sub [code]
espero y te sirva de algo [/code]
|
|
|
|
|
|
|