I wrote a simple image capture from url program what capture image from th net urls what read from a csv.
I use a for looping but if the url isn't response or I want't to cancel it I don't knoe how can i solve it?!
I use a for looping but if the url isn't response or I want't to cancel it I don't knoe how can i solve it?!
B4X:
Sub Globals
Dim Buffer(0) As byte
Dim curNr
Dim beforeNumber
Dim afterNumber
End Sub
Sub App_Start
pgBar.New1("frmmyCapture",20,200,200,20)
fgFilePictureCsv.New1
Fginputbox.New1
frmmyCapture.Show
fgFilePictureCsv.DialogTitel="Capture Image File"
fgFilePictureCsv.SearchPattern="*.csv"
If fgFilePictureCsv.ShowDialog(AppPath)=True Then
csvFile=fgFilePictureCsv.SelectedItem(0)
tblCap.LoadCSV(csvFile,",",False,True)
pgBar.Maximum=tblCap.RowCount-1
tblFail.AddCol(cString,"Fail",50,False)
beforeNumber=Fginputbox.Input("Please give the url and the add. before number","Before Number","")
afterNumber=Fginputbox.Input("Please give the extension and the add. after number","After Number","")
Else
frmmyCapture.Close
End If
End Sub
Sub DownLoad
For i=0 To tblCap.RowCount-1
curNr=tblCap.Cell("Column1",i)
url=beforeNumber&curNr&afterNumber
DownLoadFile(AppPath & "\images\"&curNr&afterNumber,url)
pgBar.Value=i
Next
If tblFail.RowCount>0 Then
tblFail.SaveCSV("FailedImage.csv",",",False)
End If
Msgbox("End Of Capturing")
End Sub
Sub DownLoadFile (LocalFile,URL)
Request.New1(URL)
Response.New1
ErrorLabel (errHandler)
Response.Value = Request.GetResponse
Reader.New1(Response.GetStream,True)
FileOpen(c1,LocalFile,cRandom)
Writer.New1(c1,False)
Dim buffer(4096) As byte
count = Reader.ReadBytes(buffer(),4096)
Do While count > 0
Writer.WriteBytes2(buffer(),0,count)
count = Reader.ReadBytes(buffer(),4096)
Loop
FileClose(c1)
Response.Close
frmmyCapture.Image=LocalFile
Return
ErrHandler:
Response.Close
tblFail.AddRow(curNr)
End Sub
Sub btnProcess_Click
Download
End Sub