Visual Basic - Ayuda

Life is soft - evento anual de software empresarial
 
Vista:

Ayuda

Publicado por Henry (1 intervención) el 06/03/2012 23:17:02
Hola soy casi nulo de VB hasta ahora comenzado, y buscando veo un articulo de algo que especificamente necesito.

Sin embargo hago los text, boton, form etc como dice pero cuando pedo el codigo y VB valida cuando genero el EXE me da un error, agradezco si alguien puede ayudarme a corregir el codigo del ejemplo.

El ejemplo esta en este url:

http://www.recursosvisualbasic.com.ar/htm/trucos-codigofuente-visual-basic/79.htm

Y el codigo es:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
Private Sub Command1_Click()
 
    'Propiedades para el control inet ( AccessType y URL )
    With Inet1
        .AccessType = icUseDefault
        'Indicamos el url del archivo
        .URL = Trim(Text1.Text)
        'Indicamos que vamos a descargar o recuperar un archivo desde una url
        .Execute , "GET"
    End With
End Sub
 
Private Sub Form_Load()
 
    Command1.Caption = " Descargar "
    Me.Caption = " Ejemplo del control Inet para " & _
                 "descargar un fichero con progreso"
 
End Sub
 
 
Private Sub Inet1_StateChanged(ByVal State As Integer)
 
On Error GoTo Err_Sub
 
    Dim tempArray() As Byte ' Un array para grabar los datos en un archivo
    Dim bDone As Boolean
    'Para el tamaño del archivo en bytes que se usa para el array
    Dim filesize As Long
    ' Acá almacenamos los datos
    Dim vtData As Variant
 
    Select Case State
 
        Case icResponseCompleted
            bDone = False
            'Para saber el tamaño del fichero en bytes
            filesize = Inet1.GetHeader("Content-length")
            'Creamos y abrimos un nuevo archivo en modo binario
            Open Text2.Text 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
 
            With ProgressBar1
                .Value = 0
                .Max = filesize
            End With
 
            Do While Not bDone
                'Almacenamos en un array el contenido del archivo que se va leyendo
                tempArray = vtData
                'Escribimos los datos en el archivo
                Put #1, , tempArray
                'Leemos  datos de a 1 kb (1024 bytes)
                vtData = Inet1.GetChunk(1024, icByteArray)
 
                DoEvents
                'Aumentamos la barra de progreso
                ProgressBar1.Value = ProgressBar1.Value + (Len(vtData) * 2)
 
                If Len(vtData) = 0 Then
                    bDone = True
                End If
            Loop
 
        Close #1
 
        MsgBox "Archivo descargado correctamente", vbInformation
        ProgressBar1.Value = 0
    End Select
 
Exit Sub
 
Err_Sub:
    MsgBox Err.Description, vbCritical
    On Error Resume Next
    Inet1.Cancel
    ProgressBar1.Value = 0
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