?
Solved

Probably loop and error handling issue - URGENT!

Posted on 2003-02-20
5
Medium Priority
?
139 Views
Last Modified: 2010-05-18
Hi all.
I'm am encrypting credit card information online into a binary file which is downloaded and decrypted locally.
The general scene is that I create a file online for each day that an order is made on my web site. When a second and third order is made, another file is made for each day. The file names go: todaysdate.dat for the first order then: "todaysdate_1.dat", "todaysdate_2.dat", "todaysdate_3.dat" etc for more orders on that day.
I hope the annotations make things clear - if not, please ask.
Cheers.


'' Define a few variables

intFile = FreeFile()
dayscovered = Me.dayscovered
fromdate = Format(Date - dayscovered, "dd/mm/yyyy")
fromdate = Replace(fromdate, "/", "_")
todate = Format(Date - 1, "dd/mm/yyyy")
todate = Replace(todate, "/", "_")

'' Create file name for local file to be saved.

FileName = "C:\" & fromdate & "_to_" & todate & ".txt"

'' Get file names which may have been created online

For x = 1 To dayscovered
stringtoadd = ""
datestring = Format(Date - x, "dd/mm/yyyy")
myfiledate = Replace(datestring, "/", "_") & ".dat"

'' So, my file names are 19_02_03.dat, 18_02_2003.dat, 17_02_2003.dat etc

strUrl = "https://www.verysecureservers.co.uk/mypath/" & myfiledate
Inet1.RequestTimeout = 20

'' The web server responds with a 404 error page when no page is found.
'' The local machine sees this as successful hit.
'' But when the .dat file is found, a type mismatch error occurs so there is data to grab.

On Error GoTo grabdata
bytedata() = Inet1.OpenURL(strUrl)

Next
MsgBox "Done", vbInformation
Exit Sub

grabdata:

''Open binary file and text file to stick decrypted info in.

bytedata() = Inet1.OpenURL(strUrl, icByteArray)
Open FileName For Append As intFile

'' Send to decrypt routine and add to new text file on local machine.

stringtoadd = Decrypt(bytedata) & vbCrLf
Debug.Print stringtoadd
Print #intFile, stringtoadd;
Close #intFile

'' Now, online, a new file is created for each order that is made.
'' The files names are: 19_2_2003.dat (for the first order of the day)
'' followed by 19_2_2003_1.dat, 19_2_2003_2.dat, 19_2_2003_3.dat etc.

Dim y As Integer
y = 1
myfiledate = Replace(myfiledate, ".dat", "")
Do
strUrl = "https://www.verysecureservers.co.uk/mypath/" & "_" & y & myfiledate & ".dat"
Inet1.RequestTimeout = 20

'' Now this is where I am getting stuck.

'' If there there is an error opening the url in non-binary mode, grab the data,
'' then come back and try again.
'' If there is no error, I know there is no data and I can
'' move on to the next day back at the beginning.

** On No Error GoTo nomoredata ** ' this doesn't work!

On Error GoTo grabmoredata

bytedata() = Inet1.OpenURL(strUrl)
y = y + 1
Loop

grabmoredata:

bytedata() = Inet1.OpenURL(strUrl, icByteArray)
Open FileName For Append As intFile
stringtoadd = Decrypt(bytedata)
Print #intFile, stringtoadd;
Close #intFile
Resume Next

nomoredata:
** I don't know what to put here **

End Sub

Function Decrypt(bytedata() As Byte) As String
Dim strMyKey As String
Dim strMyMessage As String
strMyKey = "mypass"
strMyMessage = StrConv(bytedata, vbUnicode)
Decrypt = RC4(strMyMessage, strMyKey)
End Function
0
Comment
Question by:englishman
  • 3
5 Comments
 
LVL 3

Expert Comment

by:speke
ID: 7986826

I suggest you rewrite the end as follows:

On Error Resume Next

If Err.Number <> 0 Then
'if there is an error read data
    bytedata() = Inet1.OpenURL(strUrl, icByteArray)
    Open FileName For Append As intFile
    stringtoadd = Decrypt(bytedata)
    Print #intFile, stringtoadd;
    Close #intFile
    Err.Clear
Else
'No more data, exit
    Exit Sub
End If
bytedata() = Inet1.OpenURL(strUrl)
y = y + 1
Loop

End Sub
0
 
LVL 2

Author Comment

by:englishman
ID: 7986865
ok - just trying it ... but I don't want to Exit Sub, I want to go back inside the loop just after the line:
For x = 1 To dayscovered

Cheers
0
 
LVL 2

Author Comment

by:englishman
ID: 7987560
ok, I've hit a problem.

Your "On Error Resume Next" doesn't work because it is already nested inside another error handler.

Suggestions?
0
 
LVL 2

Author Comment

by:englishman
ID: 8144561
I'm requesting the deletion of this question.
Cheers
0
 

Accepted Solution

by:
SpideyMod earned 0 total points
ID: 8144591
PAQ'd and all 150 points refunded.

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

600 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question