Visual Basic - mediante inet

Life is soft - evento anual de software empresarial
 
Vista:

mediante inet

Publicado por noelia (120 intervenciones) el 09/06/2005 19:03:23
buenas:
mediante un control inet descargo un archivo de internet como puedo hacer para saber la velocidad de descarga???
El codigo es:

Private Sub LaVolpeButton1_Click()

On Error GoTo yata:

LaVolpeButton2.Enabled = True
LaVolpeButton1.Enabled = False
Inet1.AccessType = icUseDefault
Inet1.URL = Text1
Inet1.Execute , "GET" 'Indicamos que vamos a descargar o recuperar un _
archivo desde una url
Exit Sub:
yata:

End Sub
Private Sub Inet1_StateChanged(ByVal State As Integer)
fun = 2
Dim porcen As Double
Dim vtData As Variant 'acá almacenamos los datos
Dim filesize As Long, contenttype As String, filesaze As Long, regla As Long
'extraemos de la ruta entera solo el nombre del archivo
extencion = "." & Right(Inet1.URL, Len(Inet1.URL) - InStrRev(Inet1.URL, "."))

Select Case State
Case icResponseCompleted
bDone = False
Dim tempArray() As Byte ' Un array para grabar los datos en un archivo
'Para saber el tamaño del fichero en bytes
filesize = Inet1.GetHeader("Content-length")

'Establecemos el Max del = a al tamaño del archivo

contenttype = Inet1.GetHeader("Content-type")

CommonDialog1.Filter = "ZIP(*.zip)|*.zip"
CommonDialog1.ShowSave
nomArchivo = CommonDialog1.FileName

contenttype = Inet1.GetHeader("Content-type")


'Creamos y abrimos un nuevo archivo en modo binario
On Error GoTo lop:

nomArchivo = CommonDialog1.FileName

'Creamos y abrimos un nuevo archivo en modo binario
Open nomArchivo For Binary As #1
' Leemos de a 1 Kbytes. El segundo parámetro indica _
el tipo de fichero. Tipo texto o tipo Binario, en este caso _
binario
vtData = Inet1.GetChunk(1024, icByteArray)

DoEvents
'Si el tamaño del fichero es 0 ponemos bDone en True para que no _
entre en el bucle
If Len(vtData) = 0 Then
bDone = True
End If
Shape2.Width = 0
porcen = 1
Do While Not bDone
'Almacenamos en un array el contenido del archivo
tempArray = vtData
'Escribimos el archivo en disco
Put #1, , tempArray
'Incrementamos el porcentaje
porcen = porcen + Len(vtData) * 2 * 100 / filesize
'Lo mostramos en el label
Label1 = Int(porcen) & " %"

'Incrementamos el ancho del shape
Shape2.Width = Int(porcen) * Shape1.Width / 100
filesaze = FileLen(CommonDialog1.FileName)
regla = porcen * filesize / 100
Label2.Caption = "Descargado " & regla & " Bytes de " & filesize & " Bytes"

' Leemos de pedazos de a 1 kb (1024 bytes)
vtData = Inet1.GetChunk(1024, icByteArray)
DoEvents
If Len(vtData) = 0 Then
bDone = True
LaVolpeButton2.Enabled = False
LaVolpeButton1.Enabled = True
End If
Loop

Close #1
fun = 0

Label2.Caption = "descarga finalizada"
LaVolpeButton2.Enabled = True
LaVolpeButton1.Enabled = False
LaVolpeButton2.Caption = "Salir"
Shape2.Width = Shape1.Width
Label1 = "100%"
LaVolpeButton3.Enabled = True
End Select


Exit Sub
lop:
End Sub
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder