Any way to do it better?

VB Code:
  1. Private Function CheckForFile(FileName) As Boolean
  2. 'Check if file exists
  3. CheckForFile = (Dir(FileName) <> "")
  4. End Function
  5.  
  6. Private Sub Patch()
  7. On Error GoTo err
  8. Dim intLocalVer As Integer
  9. Dim b() As Byte
  10. Dim intRemoteVer As Integer
  11. Dim strRemoteVer As String
  12. Dim doUpdate As Boolean
  13.  
  14. '1. Open the local version file and read in the number
  15.  
  16. Open App.Path & "\curversion.dat" For Input As #1
  17. intLocalVer = CInt(Input(LOF(1), 1))
  18. Close 1
  19.  
  20. '2. Download the remote version file and read in the number
  21. ' Note: This is all one line:
  22. Text1.Text = "Connecting..."
  23. b() = InetUpdate.OpenURL("http://www.ofpnam.com/hammy/comref/remotever.dat", 1)
  24. Text1.Text = "Connecting..." & vbNewLine & "Connected"
  25. Text1.Text = "Connecting..." & vbNewLine & "Connected" & vbNewLine & "Checking for updates..."
  26. strRemoteVer = ""
  27.  
  28. For t = 0 To UBound(b)
  29. strRemoteVer = strRemoteVer + Chr(b(t))
  30. Next
  31.  
  32. intRemoteVer = Int(strRemoteVer)
  33.  
  34. '3. Compare numbers
  35.  
  36. If intRemoteVer > intLocalVer Then
  37. 'Note: This is all one line:
  38.     Text1.Text = "Connecting..." & vbNewLine & "Connected" & vbNewLine & "Checking for updates..." & vbNewLine & "Update available"
  39.     Text1.SelStart = Len(Text1.Text)
  40.     upd = MsgBox("New version available, would you like to update it now? " & vbNewLine & "Please be patient, This may take a few minutes depending on connection speed.", vbYesNo Or vbQuestion)
  41.     If upd = vbYes Then
  42.         doUpdate = True
  43.     End If
  44.     If upd = vbNo Then
  45.         doUpdate = False
  46.         Text1.Text = "Connecting..." & vbNewLine & "Connected" & vbNewLine & "Checking for updates..." & vbNewLine & "Update available" & vbNewLine & "Canceled"
  47.         Text1.SelStart = Len(Text1.Text)
  48.         'Pause 2
  49.     End If
  50. Else
  51.     'MsgBox "You have the most recent version of this program."
  52.     Text1.Text = "Connecting..." & vbNewLine & "Connected" & vbNewLine & "Checking for updates..." & vbNewLine & "You have the most recent version!"
  53.     Text1.SelStart = Len(Text1.Text)
  54.     'Pause 2
  55.     doUpdate = False
  56. End If
  57.  
  58. '4. If doupdate = True, then download the latest program exe from the site
  59.  
  60. If doUpdate Then
  61. 'Note: This is all one line:
  62. Text1.Text = "Connecting..." & vbNewLine & "Connected" & vbNewLine & "Checking for updates..." & vbNewLine & "Update available" & vbNewLine & "Downloading..."
  63. Text1.SelStart = Len(Text1.Text)
  64.  
  65. b() = InetUpdate.OpenURL("http://www.ofpnam.com/hammy/comref/1200.exe", 1)
  66. Open App.Path & "\1200.exe" For Binary Access Write As #1
  67. Put #1, , b()
  68. Close 1
  69.  
  70. b() = InetUpdate.OpenURL("http://www.ofpnam.com/hammy/comref/1200r.txt", 1)
  71.             Open App.Path & "\1200r.txt" For Binary As #1
  72.             Put #1, , b()
  73.             Close #1
  74.            
  75. Text1.Text = "Connecting..." & vbNewLine & "Connected" & vbNewLine & "Checking for updates..." & vbNewLine & "Update available" & vbNewLine & "Downloading..." & vbNewLine & "Download Complete!" & vbNewLine & "Installing..."
  76.             Text1.SelStart = Len(Text1.Text)
  77.             'Name App.Path & "\ComRef.exe" As App.Path & "\OComRef.exe"
  78.             Kill App.Path & "\ComRef.exe"
  79.             'Kill App.Path & "\ComRef.exe"
  80.             If CheckForFile(App.Path & "\Readme.doc") Then
  81.                 Kill App.Path & "\Readme.doc"
  82.             Else
  83.                 Kill App.Path & "\Readme.txt"
  84.             End If
  85.             Name App.Path & "\1200r.txt" As App.Path & "\Readme.doc"
  86.             Name App.Path & "\1200.exe" As App.Path & "\ComRef.exe"
  87.             'Kill App.Path & "\OComRef.exe"
  88.  
  89. 'Now save the current version into the local version file
  90.  
  91. Open App.Path & "\curversion.dat" For Output As #1
  92. Print #1, strRemoteVer
  93. Close 1
  94.  
  95. Text1.Text = "Connecting..." & vbNewLine & "Connected" & vbNewLine & "Checking for updates..." & vbNewLine & "Update available" & vbNewLine & "Downloading..." & vbNewLine & "Download Complete!" & vbNewLine & "Installing..." & vbNewLine & "Installation Complete!" & vbNewLine & "Update was successful"
  96.             Text1.SelStart = Len(Text1.Text)
  97.  
  98. End If
  99. err:
  100. If err.Number = 13 Then
  101.     MsgBox "Error connecting, please make sure you are connected to the internet.", vbCritical
  102.     Text1.Text = "Connecting..." & vbNewLine & "Could not connect to server"
  103. 'Else
  104.     'MsgBox err.Number & vbNewLine & err.Description
  105. End If
  106.  
  107. If err.Number = 53 Then
  108.     MsgBox "Error finding files" & vbNewLine & "Please make sure the files: ComRef.exe, Update.exe, Readme.txt Or Readme.doc, and curversion.dat are in the same directory", vbCritical
  109. End If
  110. End Sub
  111.  
  112. Public Sub Form_Unload(cancel As Integer)
  113. On Error GoTo weeee:
  114.     Shell App.Path & "\ComRef", vbNormalFocus
  115.     GoTo end2
  116. weeee:
  117.     MsgBox "Could not find ComRef.exe, Update may have not been successful"
  118.     GoTo end2
  119. end2:
  120.     Dim frm As Form
  121.  
  122.     For Each frm In Forms
  123.  
  124.         Unload frm
  125.  
  126.         Set frm = Nothing
  127.  
  128.     Next
  129.  
  130. End Sub
  131.  
  132. Private Sub Timer1_Timer()
  133. Patch
  134. Timer1.Enabled = False
  135. End Sub