|
122
|
Programación / Programación Visual Basic / Re: Evitar la seleccion de la camara web
|
en: 7 Abril 2016, 19:05 pm
|
Mi teoría es que la función llama a capCreateCaptureWindowA para obtener el handle (hwnd) y posteriormente se manda el mensaje para conectar pero el paso de uno al otro es demasiado rápido, casi simultáneo y se intenta conectar ANTES de haber recibido el handle o preparar el dispositivo, yo que se . Una solución podría ser crear una espera entre un proceso y el otro Por ejemplo: Do hHwnd = capCreateCaptureWindowA(strDevice, WS_VISIBLE Or WS_CHILD, 0, 0, 640, 480, Picture1.hwnd, 0) DoEvents Loop While hwnd = 0
O mejor: '//... Private 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 '//Conecta la cámara Private Sub ConectarCamara() '//Activa la webcam hHwnd = capCreateCaptureWindowA(strDevice, WS_VISIBLE Or WS_CHILD, 0, 0, 640, 480, Picture1.hWnd, 0) Espera (2) '///<---Esperar dos segundos antes de conectar Dim Retry As Boolean, I As Integer For I = 1 To 10 '//Hace diez intentos para conectar Retry = SendMessage(hHwnd, WM_CAP_DRIVER_CONNECT, IndexDevice, 0) If Retry = True Then SendMessage hHwnd, WM_CAP_SET_SCALE, False, 0 SendMessage hHwnd, WM_CAP_SET_PREVIEWRATE, 66, 0 SendMessage hHwnd, WM_CAP_SET_PREVIEW, True, 0 SetWindowPos hHwnd, HWND_BOTTOM, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight, _ SWP_NOMOVE Or SWP_NOZORDER cmdGuardar.Enabled = True cmdDesconectar.Enabled = True cmdConectar.Enabled = False Exit For End If Next I If Retry = False Then DestroyWindow hHwnd cmdGuardar.Enabled = False End If End Sub '//...
Me he basado en las respuestas de este otro usuario que tenía el mismo problema: http://stackoverflow.com/questions/10721085/webcam-video-source-dialog-comes-up...
2 down vote Finally I Found a solution for this. The problem happens in Windows 7 / 8
First you need this API function
Private Declare Function GetTickCount Lib "kernel32" () As Long Then... after you call capCreateCaptureWindowA() you have to wait 1 second processing events, (note: sleep don't work the same)
IniTime = GetTickCount() While GetTickCount() < (IniTime + 1000) DoEvents Wend then you call WM_CAP_DRIVER_CONNECT (maybe a couple of times).. and THAT's IT ... no more video source dialog
'...
With this solution it works perfect. The GetTickCount() waiting for events worked along with calling the function until it returned true.
Private Sub PreviewVideo(ByVal pbCtrl As PictureBox) hWnd = capCreateCaptureWindowA(VideoSource, WS_VISIBLE Or WS_CHILD, 0, 0, 0, 0, pbCtrl.Handle.ToInt64, 0) Dim IniTime As Long = GetTickCount() While GetTickCount() < (IniTime + 1000) Application.DoEvents() End While Dim OKAnswer As Boolean = False For xretries As Integer = 1 To 10 ' I'll give you Only 10 tries to connect, otherwise I AM LEAVING MICROSOFT! OKAnswer = SendMessage(hWnd, WM_CAP_DRIVER_CONNECT, VideoSource, 0) If OKAnswer Then Exit For End If Next If okanswer Then SendMessage(hWnd, WM_CAP_SET_SCALE, True, 0) SendMessage(hWnd, WM_CAP_SET_PREVIEWRATE, 30, 0) SendMessage(hWnd, WM_CAP_SET_PREVIEW, True, 0) SetWindowPos(hWnd, HWND_BOTTOM, 0, 0, pbCtrl.Width, pbCtrl.Height, SWP_NOMOVE Or SWP_NOZORDER) Else DestroyWindow(hWnd) End If End Sub
Claro que esto es en Net
|
|
|
123
|
Programación / .NET (C#, VB.NET, ASP) / Re: Tabla html con net
|
en: 7 Abril 2016, 16:29 pm
|
Gracias Elektro Ahora mismo estaba buscando ejemplos en g'u'gle. Me has ahorrado el trabajo, o gran parte. s2s
(Aunque aquí podríamos tener el problema que ya comentamos... con system.web.dll)
|
|
|
124
|
Programación / .NET (C#, VB.NET, ASP) / Re: Pregunta Boba / como pasar registros desde un listbox a variables
|
en: 7 Abril 2016, 15:42 pm
|
Lo que no entiendo es por qué no usas este otro código que te pasó Elektro y que modifiqué para 6 números y para que no hubieran correlativos. Todas las combinaciones: Dim intCol As New List(Of Integer)({1, 2, 3, 4, 5, 6, 7, 8, 9, 10}.OfType(Of Integer)) Dim pairsCol As IEnumerable(Of String) = Nothing pairsCol = From value1 As Integer In intCol From value2 As Integer In intCol From value3 As Integer In intCol From value4 As Integer In intCol From value5 As Integer In intCol Select String.Join(Environment.NewLine, ( From value6 As Integer In intCol Where (value1 <> value2) AndAlso (value1 <> value3) AndAlso (value1 <> value4) AndAlso (value1 <> value5) AndAlso (value1 <> value6) AndAlso (value2 <> value3) AndAlso (value2 <> value4) AndAlso (value2 <> value5) AndAlso (value2 <> value6) AndAlso (value3 <> value4) AndAlso (value3 <> value5) AndAlso (value3 <> value6) AndAlso (value4 <> value5) AndAlso (value4 <> value6) AndAlso (value5 <> value6) AndAlso (value2 > value1) AndAlso (value3 > value2) AndAlso (value4 > value3) AndAlso (value5 > value4) AndAlso (value6 > value5) Select String.Format("{0:00} {1:00} {2:00} {3:00} {4:00} {5:00}", value1, value2, value3, value4, value5, value6))) For Each pairs As String In pairsCol For Each line As String In pairs.Split({Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries) ListBox1.Items.Add(line) Next line Next pairs
Combinaciones SIN todos los números correlativos Dim intCol As New List(Of Integer)({1, 2, 3, 4, 5, 6, 7, 8, 9, 10}.OfType(Of Integer)) Dim pairsCol As IEnumerable(Of String) = Nothing pairsCol = From value1 As Integer In intCol From value2 As Integer In intCol From value3 As Integer In intCol From value4 As Integer In intCol From value5 As Integer In intCol Select String.Join(Environment.NewLine, ( From value6 As Integer In intCol Where (value1 <> value2) AndAlso (value1 <> value3) AndAlso (value1 <> value4) AndAlso (value1 <> value5) AndAlso (value1 <> value6) AndAlso (value2 <> value3) AndAlso (value2 <> value4) AndAlso (value2 <> value5) AndAlso (value2 <> value6) AndAlso (value3 <> value4) AndAlso (value3 <> value5) AndAlso (value3 <> value6) AndAlso (value4 <> value5) AndAlso (value4 <> value6) AndAlso (value5 <> value6) AndAlso (value2 > value1) AndAlso (value3 > value2) AndAlso (value4 > value3) AndAlso (value5 > value4) AndAlso (value6 > value5) Select String.Format("{0:00} {1:00} {2:00} {3:00} {4:00} {5:00}", value1, value2, value3, value4, value5, value6))) For Each pairs As String In pairsCol For Each line As String In pairs.Split({Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries) Dim Pattern As String = " " Dim Digito() As String Digito = System.Text.RegularExpressions.Regex.Split(line, Pattern) If CInt(Digito(1)) <> CInt(Digito(0)) + 1 Or CInt(Digito(2)) <> CInt(Digito(1)) + 1 Or CInt(Digito(3)) <> CInt(Digito(2)) + 1 Or CInt(Digito(4)) <> CInt(Digito(3)) + 1 Or CInt(Digito(5)) <> CInt(Digito(4)) + 1 Then ListBox1.Items.Add(line) End If Next line Next pairs
Pero no me queda claro como pasar cada Item a Integer. Este ejemplo, al final va obteniendo los números y crea una array cuyos items son los números de una combinación pero no se como se podría crear otro array con cada array ?¿?¿?¿ Dim intCol As New List(Of Integer)({1, 2, 3, 4, 5, 6, 7, 8, 9, 10}.OfType(Of Integer)) Dim pairsCol As IEnumerable(Of String) = Nothing pairsCol = From value1 As Integer In intCol From value2 As Integer In intCol From value3 As Integer In intCol From value4 As Integer In intCol From value5 As Integer In intCol Select String.Join(Environment.NewLine, ( From value6 As Integer In intCol Where (value1 <> value2) AndAlso (value1 <> value3) AndAlso (value1 <> value4) AndAlso (value1 <> value5) AndAlso (value1 <> value6) AndAlso (value2 <> value3) AndAlso (value2 <> value4) AndAlso (value2 <> value5) AndAlso (value2 <> value6) AndAlso (value3 <> value4) AndAlso (value3 <> value5) AndAlso (value3 <> value6) AndAlso (value4 <> value5) AndAlso (value4 <> value6) AndAlso (value5 <> value6) AndAlso (value2 > value1) AndAlso (value3 > value2) AndAlso (value4 > value3) AndAlso (value5 > value4) AndAlso (value6 > value5) Select String.Format("{0:00} {1:00} {2:00} {3:00} {4:00} {5:00}", value1, value2, value3, value4, value5, value6))) For Each pairs As String In pairsCol For Each line As String In pairs.Split({Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries) Dim Pattern As String = " " Dim Digito() As String Digito = System.Text.RegularExpressions.Regex.Split(line, Pattern) If CInt(Digito(1)) <> CInt(Digito(0)) + 1 Or CInt(Digito(2)) <> CInt(Digito(1)) + 1 Or CInt(Digito(3)) <> CInt(Digito(2)) + 1 Or CInt(Digito(4)) <> CInt(Digito(3)) + 1 Or CInt(Digito(5)) <> CInt(Digito(4)) + 1 Then ListBox1.Items.Add(line) End If Next line Next pairs '//Esto solo crea un array con la última combinación. '//En realidad lo hace con todas pero solo queda registrada la última '//¿Habría que hacer una colección de arrays? Dim NuevaLista As New List(Of String)(ListBox1.Items.OfType(Of String)) Dim int32Col As IEnumerable(Of Integer) = Nothing For Each item As String In NuevaLista int32Col = From Elemento As String In item.Split(" "c) Select CInt(Elemento) Next 'Los números de la última combinación MessageBox.Show(int32Col(0).ToString) MessageBox.Show(int32Col(1).ToString) MessageBox.Show(int32Col(2).ToString) MessageBox.Show(int32Col(3).ToString) MessageBox.Show(int32Col(4).ToString) MessageBox.Show(int32Col(5).ToString)
FALTABA UN: (value5 <> value6) AndAlso Ya lo he puesto
|
|
|
125
|
Programación / .NET (C#, VB.NET, ASP) / Tabla html con net
|
en: 7 Abril 2016, 14:38 pm
|
Hola ¿Hay alguna clase o función en Net para crear tablas Html?. Mi idea es crear una tabla HTML a partir de datos de un datagridview o ListView. Lo que yo he hecho por ahora es algo como lo siguiente: Dim builder As New System.Text.StringBuilder With builder .AppendLine("<table border=""1"" style=""border-collapse: collapse;"">") .AppendLine("<caption>Leyenda</caption>") .AppendLine("<tbody>") .AppendLine("<tr>") .AppendLine(String.Format("<td>{0}</td>", "Celda1")) .AppendLine(String.Format("<td>{0}</td>", "Celda2")) .AppendLine("</tr>") .AppendLine("<tr>") .AppendLine(String.Format("<td>{0}</td>", "Celda3")) .AppendLine(String.Format("<td>{0}</td>", "Celda4")) .AppendLine("</tr>") .AppendLine("</tbody>") .AppendLine("</table>") End With
Pero es muy tedioso
He encontrado algo que puede ser lo que busco. HtmlTable Classdel system.web.dll Imports System.Web.UI.HtmlControls Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim i As Integer Dim j As Integer Dim Table1 As HtmlTable Dim row As HtmlTableRow Dim cell As HtmlTableCell '//... End Sub End Class
|
|
|
127
|
Programación / .NET (C#, VB.NET, ASP) / Re: Pregunta Boba / como pasar registros desde un listbox a variables
|
en: 7 Abril 2016, 13:40 pm
|
No se, como no sea que quites los espacios a "AA BB CC DD..." y quede "AABBCCDD". Pero entonces no aceptaría Integer porque saldrían números muy grandes como 102030444546 y no se acepta como Integer, si no como Double. ListBox1.Items.Add("01 02 03 04 05 06") ListBox1.Items.Add("10 20 30 44 45 46") ListBox1.Items.Add("12 22 34 45 56 65") ListBox1.Items.Add("12 22 34 45 56 65") Dim Pattern As String = " " Dim Digito() As String '//Mete los Items del ListBox en ClearList Dim ClearList As New List(Of String)(ListBox1.Items.OfType(Of String)) For Each Item As String In ClearList Digito = System.Text.RegularExpressions.Regex.Split(Item, Pattern) If CInt(Digito(1)) = CInt(Digito(0)) + 1 And CInt(Digito(2)) = CInt(Digito(1)) + 1 And CInt(Digito(3)) = CInt(Digito(2)) + 1 And CInt(Digito(4)) = CInt(Digito(3)) + 1 And CInt(Digito(5)) = CInt(Digito(4)) + 1 Then ListBox1.Items.Remove(Item) '<-----Borra un Item del ListBox End If Next ClearList.Clear() '//Borra ClearList ClearList.AddRange(ListBox1.Items.OfType(Of String)) '//Consigue la nueva lista del ListBox Dim NuevaLista As New List(Of Double) For Each Item As String In ClearList NuevaLista.Add(Item.Replace(" ", Nothing)) Next MessageBox.Show(NuevaLista(0).ToString) MessageBox.Show(NuevaLista(1).ToString)
Rectifico mi comentario "no se puede meter cadenas string a integer", por si alguien me regaña... A ver si el string es un número, entonce sí: Dim Cadena as string = "12345" Dim Numero as Integer = Cadena
también con el singo "-" delante indicando negatividad. Dim Cadena As String = "-12345" Dim Numero As Integer = Cadena
Pero si tiene carácteres distintos a un número tal como Espacio, coma, "x", "&" o letras por ejemplo pues entonces creo que no. A no ser que combiertas la cadena de texto a byte o algo así, no se, no he probado.
|
|
|
129
|
Programación / Programación Visual Basic / Re: Consola por pipe crashea en windows 8 y versiones adelantadas
|
en: 7 Abril 2016, 13:00 pm
|
Jajajaja, en VB6 o en cualquier otro lenguaje se usan las mismas funciones... Pero vamos que si insistes y tienes mucho interés lo programo.
Saludos.
El problema no es que tenga las mismas funciones o no. El problema está en saber interpretar el código ASM y saber lo suficiente en VB para pasar de uno a otro. Y además concretamente lo que pide illuminat3d. Pienso yo vamos XD. No es pos fastidiar.
|
|
|
130
|
Programación / .NET (C#, VB.NET, ASP) / Re: Pregunta Boba / como pasar registros desde un listbox a variables
|
en: 7 Abril 2016, 12:52 pm
|
Repito. No puedes meter cadenas de texto 'string' en integer. De hecho, según ese código (que me suena un poco ) ya tienes el ejemplo de como meter el ListBox en una variable... Dim ClearList As New List(Of String)(ListBox1.Items.OfType(Of String))
Lo que hace el código, es meter la lista pura del ListBox (que son cadenas string) en la variable ClearList que es un List(of T) que es un array. Luego en el For Each repasa cada Item del ClearList y si cumple las condiciones borra los Items del ListBox que las cumpla. Ahora, si quieres meterlo en una variable, llamada por ejemplo 'NuevaLista', tan solo lo has de meter otra vez como antes: Dim NuevaLista As New List(Of String)(ListBox1.Items.OfType(Of String)) Y ya lo tienes metido. Pero como String, claro. Porque algo como esto --> "01 02 03 04 05 06" es string e incluso Object, pero no integer ListBox1.Items.Add("01 02 03 04 05 06") ListBox1.Items.Add("10 20 30 44 45 46") ListBox1.Items.Add("12 22 34 45 56 65") ListBox1.Items.Add("12 22 34 45 56 65") Dim Pattern As String = " " Dim Digito() As String '//Mete los Items del ListBox en ClearList Dim ClearList As New List(Of String)(ListBox1.Items.OfType(Of String)) For Each Item As String In ClearList Digito = System.Text.RegularExpressions.Regex.Split(Item, Pattern) If CInt(Digito(1)) = CInt(Digito(0)) + 1 And CInt(Digito(2)) = CInt(Digito(1)) + 1 And CInt(Digito(3)) = CInt(Digito(2)) + 1 And CInt(Digito(4)) = CInt(Digito(3)) + 1 And CInt(Digito(5)) = CInt(Digito(4)) + 1 Then ListBox1.Items.Remove(Item) '<-----Borra un Item del ListBox End If Next '//Mete la nueva lista en NewList Dim NuevaLista As New List(Of String)(ListBox1.Items.OfType(Of String)) NuevaLista = NuevaLista.Distinct.ToList '//Quita Items repetidos MessageBox.Show(NuevaLista(0).ToString) MessageBox.Show(NuevaLista(1).ToString)
Pero como te comenté no soy experto en NET, pero por lo que sé, yo lo veo así. s2s
había un condición repetida dos veces, ya lo he quitado : CInt(Digito(5)) = CInt(Digito(4)) + 1 Bueno, no es solo que estuviera repetido.. es que faltaba uno, el : CInt(Digito(4)) = CInt(Digito(3)) + 1 ya que supongo que es para quitar combinaciones con todos los números correlativos
|
|
|
|
|
|
|