PDA

View Full Version : Need VB Help



kanarde
12-27-01, 12:44 AM
Ok, I am trying to make an auto-updater for my program (http://www.nitrousonline.net/nvf). My major problem right now is downloading the updates.

Heres what I have so far:

<START OF CODE>
'-------------------------------------------------------------------------------
Private Sub Command1_Click()
Inet1.URL = "http://www.blah.com/update.exe" 'some address
bar.Value = 0 'Progress Bar
Inet1.Execute , "GET"
End Sub

'-------------------------------------------------------------------------------

Private Sub Inet1_StateChanged(ByVal State As Integer)
Dim vtData As Variant, DocSize As Long
Select Case State
Case icResponseReceived
If DocSize = 0 Then
If Len(Inet1.GetHeader("Content-Length")) > 0 Then
DocSize = CLng(Inet1.GetHeader("Content-Length"))
Text1.Text = DocSize

bar.Max = DocSize + 1024
End If
End If
Case icResponseCompleted
Dim intFile
intFile = FreeFile()
' Open a file to write to.
Open "c:\windows\desktop\agent.exe" For Binary Access Write As #intFile

' Get the first chunk. NOTE: specify a Byte
' array (icByteArray) to retrieve a binary file.
vtData = Inet1.GetChunk(1024, icByteArray)
bar.Value = bar.Value + 1024
Do While LenB(vtData) > 0
DoEvents
On Error Resume Next
bar.Value = bar.Value + 1024
lblP.Caption = Round((bar.Value / bar.Max) * 100) & "%"
Put #intFile, , vtData
' Get next chunk.
vtData = Inet1.GetChunk(1024, icByteArray)
Loop
Put #intFile, , vtData
Close #intFile

Case icConnecting
lblStat.Caption = "Connecting..."
Case icConnected
lblStat.Caption = "Connected"
Case icDisconnecting
lblStat.Caption = "Disconnecting..."
Case icDisconnected
lblStat.Caption = "Disconnected"
End Select
End Sub
'-------------------------------------------------------------------------------
<END OF CODE>

The problem is when I use the "put" statement. It adds extra information about the Variant 'vtData'.

I took the download code strait from msdn.

Any help out there?

Stu
12-28-01, 04:09 PM
I'm a little confused... Why are you using a HTTP connection to download a file? Wouldn't FTP be more appropriate?

Also, as to getting code from MSDN, you might want to see if VBnet (http://www.mvps.org/vbnet/index.html) has what you need before going to MSDN--I've found that their code is much more flexible than the examples on MSDN.

kanarde
12-28-01, 09:43 PM
I am using HTTP because I don't have a FTP server to put the files on.

VBnet is a nice site, but I finally figured it out.

I changed the put statement to this:

For i = 0 To 1023
bit = vtData(i)
Put #intFile, , bit
Next i

Where "bit" is a Byte var.

Works great now, thx anyway Stu :)