Probably loop and error handling issue - URGENT!

Posted on 2003-02-20
Medium Priority
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.

'' 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)

MsgBox "Done", vbInformation
Exit Sub


''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", "")
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


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

** 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
Question by:englishman
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3

Expert Comment

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
'No more data, exit
    Exit Sub
End If
bytedata() = Inet1.OpenURL(strUrl)
y = y + 1

End Sub

Author Comment

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


Author Comment

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.


Author Comment

ID: 8144561
I'm requesting the deletion of this question.

Accepted Solution

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

Community Support Moderator @Experts Exchange

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month11 days, 10 hours left to enroll

752 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