|
171
|
Programación / Programación Visual Basic / Re: Como se redimensiona?¿ :S
|
en: 25 Octubre 2009, 11:48 am
|
hola xassiz, Leonardo Azpurua explica bastante bien como puedes hacerlo en http://social.msdn.microsoft.com/forums/es-ES/vbes/thread/86f62967-9763-4964-a220-671f89f01e53/Su idea consiste en guardar en una variable el alto y ancho del formulario, y en la propiedad tag de cada uno de los controles, su ancho. alto, tamaño de fuente y posición X e Y en el formulario. Cada vez que el formulario se redimensiona se calcula la proporcion en que ha variado, y se aplica a todos los controles. te pongo el código Dim xControl As Control Dim designHeight As Single, designWidth As Single
Private Sub Form_Load() designHeight = Me.Height designWidth = Me.Width
For Each xControl In Form1 xControl.Tag = xControl.Height & "/" & xControl.Width & "/" & xControl.Left & "/" & xControl.Top & "/" & xControl.FontSize Next End Sub
Private Sub Form_Resize() Dim factorH As Single, factorW As Single
factorH = Me.Height / designHeight factorW = Me.Width / designWidth For Each xControl In Form1 Call RescalarControl(factorH, factorW, xControl) Next End Sub
Public Sub RescalarControl(factorH As Single, factorW As Single, xControl As Control) Dim cTop As Single, cLeft As Single, cWidth As Single, cHeight As Single, cFont As Single Dim v() As String
v = Split(xControl.Tag, "/") cHeight = v(0) * factorH cWidth = v(1) * factorW cLeft = v(2) * factorW cTop = v(3) * factorH cFont = v(4) * factorH
With xControl .Top = cTop .Left = cLeft .Height = cHeight .Width = cWidth .Font.Size = cFont End With End Sub
Seguramente tendrás que hacer modificaciones porque no todos los controles tienen todas las propiedades (p.ej. un timer)...........así que no deja de ser un apaño
|
|
|
172
|
Programación / Programación Visual Basic / Re: Winsock y packet's?
|
en: 24 Octubre 2009, 11:12 am
|
hola _F3RN4_, tal vez podrías enviar el valor hexadecimal como un array de bytes Dim Array_Hex(3) As Byte Array_Hex(0) = CByte("&H" & "C1") Array_Hex(1) = CByte("&H" & "87") Array_Hex(2) = CByte("&H" & "37") Array_Hex(3) = CByte("&H" & "BF") Winsock1.SendData Array_Hex
saludos
|
|
|
173
|
Programación / Programación Visual Basic / Re: Eliminar archivo con un command desde el FilelistBox
|
en: 26 Septiembre 2009, 11:01 am
|
Perdon por el doble post pero siguen habiendo un par de errores. 1 por ejemplo cuando le asigno la ruta a la variable queda asi: Ruta = File1.path & File1.filename
O sea: C:\Miarhivo.ext Ese coda para borrar archivos dentro de una unidad sin estar dentro de una carpeta, funciona pero... si quiero borrar un archivo en otra ubicacion: "F:\mis archivos\blabla\redtube.ext" Ruta = File1.path & File1.filename
Esto devuelve: F:\mis archivos\blabla ---> (sin el signo "\" al final, eso da error, archivo no encontrado)
En total asi: F:\mis archivos\[b]blablaredtube.ext[/b] (sin el "\") y si hago esto: Ruta = File1.path & "\" & File1.filename
Ahi si funcionaria: F:\mis archivos\blabla\redtube.ext Como soluciono este problema de rutas?? 2 Estando bien la ruta, no me deja eliminar los archivos siendo que otros si elimina... mejor explico a este despues, ya es tarde aqui. Gracias de nuevo. Para el problema 1... If Right(File1.Path, 1) <> "\" Then ruta = File1.Path & "\" & File1.FileName Else ruta = File1.Path & File1.FileName End If
Saludos.
|
|
|
174
|
Programación / Programación Visual Basic / Re: Duda - Strings
|
en: 20 Septiembre 2009, 22:46 pm
|
hola dynyck, si los signos de puntuación son siempre los mismos, por ejemplo puntos, puedes separar las "frases" con la función split y después unir todas las frases pasadas por la función trim Private Sub Command1_Click() Dim frases() As String Dim i As Long 'separas las frases en un array frases = Split(Text1.Text, ".") For i = 0 To UBound(frases) 'añades las frases sin espacios más el punto y un espacio Text1.Text = Text1.Text & Trim(frases(i)) & ". " Next i 'quitas el ". " del final Text1.Text = Left(Text1.Text, Len(Text1.Text) - 2) End Sub
si tienes varios signos de puntuación distintos, puedes ir recorriendo todo el texto y comparar, para separar las frases a un array Private Sub Command1_Click() Dim frases() As String Dim i As Long Dim n_frases As Long n_frases = 1 ReDim Preserve frases(n_frases - 1) For i = 1 To Len(Text1.Text) frases(n_frases - 1) = frases(n_frases - 1) & Mid(Text1.Text, i, 1) 'añades los signos que quieras If Mid(Text1.Text, i, 1) = "." Or Mid(Text1.Text, i, 1) = "," Or Mid(Text1.Text, i, 1) = ";" then n_frases = n_frases + 1 ReDim Preserve frases(n_frases - 1) End If Next i For i = 0 To n_frases - 1 Text1.Text = Text1.Text & Trim(frases(i)) & " " Next i Text1.Text = Left(Text1.Text, Len(Text1.Text) - 1) End Sub
Además de la función trim tambien tienes ltrim y rtrim que igual te interesan más. Espero que te sirva, saludos.
|
|
|
175
|
Programación / Programación Visual Basic / Re: [SNIPPET] Get W$ Version {RtlGetVersion - Native API}
|
en: 18 Septiembre 2009, 23:50 pm
|
Muchas garcias por el aporte karcrack, como comentan por ahí, lo he probado en el win98 y no funciona................... falta la dll........... Con el mismo registro puedes saber si es NT o no(si falla no es NT ) , digo que es mejor por que en el registro ya esta escrito directamente que version del SO es entre otras cosas ( si es ultimate o home basic aparece en el registro por ejemplo ) Para ser mas expesifico en la clave : HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProductName gracias, me es muy útil
|
|
|
176
|
Programación / Programación Visual Basic / Re: Enumerar todos los archivos
|
en: 3 Septiembre 2009, 16:39 pm
|
hola, tambien puedes poner un control FileListBox, eliges la carpeta que quieres con file1.path, y recorres los archivos Dim i As Integer Private Sub Form_Load() 'eliges la carpeta File1.Path = InputBox("Escribe la ruta de la carpeta") 'y recorres los archivos del filelistbox If File1.ListCount <> 0 Then For i = 0 To File1.ListCount - 1 MsgBox File1.List(i) Next i Else MsgBox "no hay archivos" End If End Sub
saludos
|
|
|
179
|
Programación / Scripting / Re: duda con batch
|
en: 6 Julio 2009, 17:03 pm
|
hola, creo que lo puedes hacer, si en una cuenta de administrador abres la consola con click dcho. y ejecutar como....administrador Espero que te sirva. Saludos.
|
|
|
180
|
Programación / Programación Visual Basic / Re: CsocketMaster Array
|
en: 20 Junio 2009, 10:28 am
|
Hola locot3, lo primero que hay que hacer, al igual que con el csocketmaster es definirel csocket que vas a usar Dim WithEvents csocket1 As CSocketPlus
después hay que cargarlo Set csocket1 = New CSocketPlus
y por último vas añadiendo al array los elemetos que necesites este último codigo te añadiría al array el index 0 por el que preguntas, pero el index es de tipo variant y también podrías poner un string por ejemplo csocket1("nuevo_csocket") aunque está en inglés se entiende bastante bien las instrucciones que vienen con el módulo: CSocketPlus 1.2 readme file ===========================
NOTE: Before sending me a bug report you MUST try your code with Winsock Control first to check if there is something wrong with YOUR code and not with CSocketPlus. If you don't explicitly mention that your code works fine with Winsock Control your message will be ignored. I don't like to be rude but you can't imagine how many times people sent me buggy code blaming CSocketMaster.
*** What is CSocketPlus? ========================
CSocketPlus class is a Winsock control substitute that attempts to mimic it's behavior and interface to make it easy to implement. Unlike CSocketMaster, CSocketPlus has the ability to create sockets at runtime.
*** How do you use it? ======================
1) Add CSocketPlus.cls and modSocketPlus.bas to your project. 2) In a Form, Class or UserControl add this line in the declaration area for each socket array you want to use: Dim WithEvents NameOfArray As CSocketPlus
where 'NameOfArray' is any name you want for the socket array.
3) You need to create the object before you can use it. Add this line in a sub or funtion:
Set NameOfArray = New CSocketPlus
That's it.
*** Adding and removing sockets from the array ============================================== To add a socket to the array use ArrayAdd member function. You can use a long value or a string as an index to uniquely identify each socket from the array:
ie: NameOfArray.ArrayAdd 23 NameOfArray.ArrayAdd "Client"
Now you can work with your socket as usual, but you have to pass the index as the first argument:
ie: NameOfArray.Listen 23 NameOfArray.Connect "Client", "www.yahoo.com", 80
When an event is raised you can use Index argument to identify which socket generated the event.
To remove a socket from the array use ArrayRemove member function and pass the index as an argument:
ie: NameOfArray.ArrayRemove 23 NameOfArray.ArrayRemove "Client"
To count how many sockets you have in the array use ArrayCount function:
ie: MsgBox "My array has " & NameOfArray.ArrayCount & " sockets"
Finally, to find out if an index is used by the array use ArrayIndexInUse function:
ie: Msgbox "123 is an index: " & NameOfArray.ArrayIndexInUse(123)
*** About Indexes ================= As stated above you can use a long value or a string as an index for your socket. CSocketPlus doesn't recognize capital letters, so:
* "client" is equal to "Client" and "CLIENT" * "My first socket" is a valid index * "%-_-$&/()=" is a valid index * "" (empty string) is valid index * 0, -123 and 999999 are valid indexes * "one", "1", " 1" , "1 " and 1 are five different indexes * You can use the same index in two different arrays:
ie: FirstArray.ArrayAdd "client" : SecondArray.ArrayAdd "client"
* When you call ArrayAdd and don't pass an index the fuction finds an available long index for you and returns it with the function. This is not recommended because it could take too long.
ie: lngIndex = NameOfArray.ArrayAdd
*** New error codes =================== These are the new error codes generated by CSocketPlus:
Constant Value Description
sckWrongIndex 40027 Unsupported index type. This happens when you try to use a variable as an index other than long or string.
sckUsedIndex 40028 This index is already associated with an element of this array. This error is raised when you try to add two sockets with the same index.
sckMissingIndex 40029 Unknown index. This error is raised when you try to remove or work with an inexistent socket index.
*** Extra notes =============== A) Receiving a connection request from one array and accepting with another array is completely valid:
ie:
Private Sub FirstArray_ConnectionRequest(ByVal Index As Variant, ByVal requestID As Long)
SecondArray.ArrayAdd "server" SecondArray.Accept "server", requestID
end sub
B) Be careful if you are accustomed to use Winsock control. A line like this is valid with any of them:
Socket.Bind 80
When you use Winsock control that line means "bind my socket to port 80". But when you use CSocketPlus that line means "bind my socket with index number 80 to a free port".
C) When you call ArrayAdd the socket isn't created until you need it and it's destroyed when you call CloseSck or ArrayRemove.
D) Removing the debug logs from the class can speed up the work with large arrays in the IDE. This is not necessary when you compile your code.
*** Differences between CSocketPlus and Winsock control =======================================================
A) Winsock Close function is CloseSck in CSocketPlus. B) Winsock Close event is CloseSck in CSocketPlus. C) WndProc function is used to deliver system messages and you should not call it under any circumstance. D) There are some other differences I intentionally put in CSocketPlus that you shouldn't notice. If you find a major difference that you think shouldn't be there, please let me know.
*** Known issues ================
A) Msgbox Due to a VB behavior by desing running a project in the IDE that displays a message box created with Msgbox prevents events from occurring. If you really need to use message boxes then you can use MessageBox api instead. Note that this only happens in the IDE, when you compile your project all events are fired no matter what. For more info check this site: http://support.microsoft.com/default.aspx?scid=kb;en-us;178078
*** Why not use Winsock control? ================================
Bacause winsock it's a fixed non-modifiable control. Also it is known that Winsock has a memory leak. For more info check this site: http://support.microsoft.com/default.aspx?scid=kb;en-us;171843
*** Why use a class instead of a control? =========================================
Using a class instead of a control has some clear benefits. You have total encapsulation, and you could, for example, make a class (or control) that downloads files from internet just passing a URL without knowing how CSocketPlus works internally. You can modify CSocketPlus and add more fancy functions and events. Best of all: you don't have external dependencies.
*** What tha' heck is that subclassing stuff? =============================================
When you work with winsock you need to subclass a window to receive system's info from the socket. If you are familiar with the concept of subclassing on VB you should know that if you subclass a window and press then End button while in IDE you get a nice GPF and your system crashes. To solve this I use a code based on Paul Caton's WinSubHook2 that can be found at www.planet-source-code.com. If you wanna understand how my subclassing code works you have to understand his first. The asm code for the WndProc is in Subclass.asm file. This subclassing approach is not fully tested yet, so let me know if you get a GPF.
*** Do you need Subclass.asm file? ================================== No! This is just the source code for the WndProc used when subclassing. You can delete this file if you wish.
*** Why so many Debug logs? ===========================
That's for helping me (and you) to find any possible bug. If you get annoyed you can always erase them or comment them.
*** What's new on 1.2? ====================== * Fixed the bug that wouldn't free listening socket when the end button is pressed * Now the use of breakpoints doesn't stop the socket messages * Minor bugs.
*** Bug report ==============
If you have a question firs't check this site:
http://www.geocities.com/anshoku/
I will post FAQs to this page so I don't have to answer a question twice. If you don't find your answer there you can send me an email, but first read this:
A) If I consider that your question is answered on my page your email will be ignored. B) Make sure it's a bug! Maybe what you think it's a bug is normal winsock behavior. Use winsock control to check if the malfunction persists. C) I suppose you know how to work with winsock cause I will not teach you how to do it. So don't ask me something like 'how to make a connection?' or 'how can I make a chat prog?'. D) If you could send me some sample code to illustrate the bug, that would be great. E) Don't be a lamer, don't send spam or chain mails.
Emiliano Scavuzzo <anshoku@yahoo.com> Rosario, Argentina
|
|
|
|
|
|
|