Foro de elhacker.net

Programación => Programación Visual Basic => Mensaje iniciado por: Badlands en 14 Diciembre 2006, 00:34 am



Título: Progressbar de envio en el cliente
Publicado por: Badlands en 14 Diciembre 2006, 00:34 am
Hola queria saver como hacer un progressbar en el cliente cuando se envia un archivo al servidor les dejo mi codigo para ver que le hay que agregarle por que al recivir si puedo hacer el progressbar pero al enviar no.

Cliente:

Citar
Private Sub ws_DataArrival(ByVal bytesTotal As Long)

Dim Data As String
ws.GetData Data

If Left(Data, 8) = "SendFile" Then
Open "e:\bad.mp3" For Binary As #1
Send = Space(LOF(1))
Get #1, , Send
Close #1
LenFile2 = Len(Send)
ws.SendData Send
End If
End Sub



Título: Re: Progressbar de envio en el cliente
Publicado por: ~~ en 15 Diciembre 2006, 19:58 pm
Mira este es un codigo q me paso WarGhost hace ya algun tiempo:

Citar
Server:

Código:
Private Sub Form_Load()
ws.Close
ws.Connect "127.0.0.1", 2848
End Sub

Private Sub ws_Connect()
ws.SendData "Tam:" & FileLen("C:\Prueba.txt")
End Sub

Private Sub ws_DataArrival(ByVal bytesTotal As Long)
Dim data As String
Dim Send As String
ws.GetData data

If Left(data, 8) = "SendFile" Then
Open "C:\Prueba.txt" For Binary As #1
Send = Space(LOF(1))
Get #1, , Send
Close #1

ws.SendData Send
End If

End Sub


Cliente:

Código:
Dim DataFile As String
Dim LenFile As Long
Dim Envio As Boolean

Private Sub Form_Load()
ws.LocalPort = 2848
ws.Listen
Envio = False
End Sub

Private Sub ws_ConnectionRequest(ByVal requestID As Long)
ws.Close
ws.Accept requestID
End Sub

Private Sub ws_DataArrival(ByVal bytesTotal As Long)
Dim data As String
ws.GetData data

If Envio = True Then
DataFile = DataFile & data
ProgressBar1.Value = Len(DataFile)
If Len(DataFile) = LenFile Then
Open "C:\Prueba2.txt" For Binary As #1
Put #1, , DataFile
Close #1
DataFile = ""
MsgBox "El Fichero se a Enviado Correctamente"
Envio = False
ProgressBar1.Value = 0
End If
End If

If Left(data, 4) = "Tam:" Then
LenFile = Mid(data, 5)
ProgressBar1.Max = LenFile
Envio = True
ws.SendData "SendFile"
End If

e puesto ademas para que salga un ProgressBar1  si no lo quiere simplemente elimina estas lineas:

Código:
ProgressBar1.Max = LenFile
ProgressBar1.Value = 0
ProgressBar1.Value = Len(DataFile)

Funciona a las mil maravillas  ;)
1S4ludo


Título: Re: Progressbar de envio en el cliente
Publicado por: Badlands en 16 Diciembre 2006, 10:37 am
si pero eso seria para la descarga de archivos, y yo quiero visualizar en el progressbar el envio de archivos.
Gracias ;D


Título: Re: Progressbar de envio en el cliente
Publicado por: ~~ en 16 Diciembre 2006, 10:57 am
Pues es exacamente igual, pero cambiando el codigo del server por el del cliente y el del cliente por el del server xDD

1S4ludo ;)


Título: Re: Progressbar de envio en el cliente
Publicado por: Badlands en 16 Diciembre 2006, 11:02 am
Como? No te entiendo me podrias poner un ejemplo. Por lo que entiendo tendria que poner en el progressbar en vez de los datos que van llegando los que van saliendo. Nose si me explico yo el progressbar lo quiero en el cliente no en el server.

Gracias


Título: Re: Progressbar de envio en el cliente
Publicado por: ~~ en 16 Diciembre 2006, 11:29 am
Pues en ProgressBar1.Max = LenFile es el tamaño del arhivo enviado, en vez del recibido

En ProgressBar1.Value = Len(DataFile) tedrias q poner lo q se esta enviando hasta ese momento

Y ProgressBar1.Value = 0 lo dejas igual

1S4ludo ;)