473,396 Members | 2,026 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

can anyone help me speed up my code?

zerok666
Hi, i am making a secure file deletion program. It works great, but it is extreamly slow. Any help will be appreciated.

Expand|Select|Wrap|Line Numbers
  1.  Private Sub Command1_Click()
  2. On Error Resume Next
  3. q = ""
  4.  
  5. Dim file As String
  6. CD.ShowOpen
  7. If CD.FileName = "" Then End
  8. file = CD.FileName
  9. Open file For Binary As #1
  10. tem = LOF(1)
  11.  
  12. Dim bytarray() As Byte
  13. ReDim bytarray(1 To tem)
  14.  
  15. Get 1, 1, bytarray
  16. q = ""
  17. Form1.Hide
  18.  
  19. For b = 1 To Combo1.Text
  20. For i = 1 To tem
  21. mrand = Int(Rnd * (250))
  22. bytarray(i) = Chr(mrand)
  23. Next i
  24. For g = 1 To tem
  25. Put 1, g, bytarray(g)
  26. Next g
  27. Next b
  28.  
  29. Close #1
  30.  
  31. Kill file
  32.  
  33. MsgBox "Delete is complete", vbOKOnly, "Done!"
  34.  
  35. End
  36. End Sub
  37.  
Sep 5 '10 #1
4 1235
Guido Geurs
767 Expert 512MB
Is it possible to attach your program?
Q1 : what is q ?
Q2 : what is tem ? ...
Sep 5 '10 #2
Tem is the lof dictated in line 10 and for q, I forgot to remove it from the code.
Attached Files
File Type: zip del file.zip (12.6 KB, 64 views)
Sep 5 '10 #3
Guido Geurs
767 Expert 512MB
Yours is working ????
This is the modification of Your code=

Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2.  
  3. Private Sub Command1_Click()
  4. Dim BYTEARRAY() As Byte
  5. Dim TEM As Long
  6. Dim LOOPS As Integer
  7. Dim BYTES As Long
  8. Dim MRAND As Integer
  9. '§ Select the file
  10.    On Error GoTo No_File
  11.    With CD
  12.       .CancelError = True
  13.       .ShowOpen
  14. '§ Open the file
  15.       On Error Resume Next
  16.       Open .FileName For Binary As #1
  17.          '§ put file in array
  18.          TEM = LOF(1)
  19.          ReDim BYTEARRAY(1 To TEM)
  20.          Get 1, 1, BYTEARRAY
  21.          '§ Rewrite bytes
  22.          For LOOPS = 1 To Combo1.Text
  23.             For BYTES = 1 To TEM
  24.                MRAND = Int(Rnd * (250))
  25.                BYTEARRAY(BYTES) = MRAND
  26.                Put 1, BYTES, BYTEARRAY(BYTES)
  27.             Next
  28.             Label2 = LOOPS & " times rewritten"
  29.             Label2.Refresh
  30.          Next
  31.       Close #1
  32. '§ Delete file
  33.       Kill .FileName
  34.    End With
  35.    MsgBox "Delete is complete", vbOKOnly, "Done!"
  36. No_File:
  37. End Sub
  38.  
  39. Private Sub Form_Load()
  40. Dim COUNTER As Integer
  41. '§ Fill list
  42.    For COUNTER = 0 To 90 Step 10
  43.       If COUNTER > 0 Then Combo1.AddItem COUNTER
  44.    Next
  45. End Sub
  46.  
But I have a lot of questions with Your approach:

Q1: why rewriting the bytes more than once ?
If You disable the line "Kill .Filename", you will see if You open the file (still present) all the bytes are changed.
So once is enough.

Q2: Why randomize the bytes ? if you enter only a character (like 100 for "d"), all the chars in the fill will be the same !( check with "Kill .Filename" off.

So here is the solution:

Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2.  
  3. Private Sub Command1_Click()
  4. Dim BYTEARRAY() As Byte
  5. Dim TEM As Long
  6. Dim BYTESidx As Long
  7. '§ Select the file
  8.    On Error GoTo No_File
  9.    With CD
  10.       .CancelError = True
  11.       .ShowOpen
  12. '§ Open the file
  13.       On Error GoTo No_File
  14.       Open .FileName For Binary As #1
  15.          '§ put file in array
  16.          TEM = LOF(1)
  17.          ReDim BYTEARRAY(1 To TEM)
  18.          Get 1, 1, BYTEARRAY
  19.          '§ Rewrite bytes
  20.          For BYTESidx = 1 To TEM
  21.             BYTEARRAY(BYTESidx) = 100 '="d"
  22.          Next
  23.          Put 1, 1, BYTEARRAY
  24.       Close #1
  25. '§ Delete file
  26.       Kill .FileName
  27.    End With
  28.    MsgBox "Delete is complete", vbOKOnly, "Done!"
  29. Exit Sub
  30. No_File:
  31.    MsgBox "No file selected"
  32. End Sub
  33.  
Attached Files
File Type: zip can anyone help me speed up my code DELETE ALL.zip (4.1 KB, 55 views)
Sep 6 '10 #4
if they are overwritten once, than data can still be recovered. i am trying to have no data recovery.
Sep 11 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Mike | last post by:
I got the code below from an earlier post but I can't get it to work (I get an error on the "for (i=0; i<a.length; i++)" line) Anyone have code that works for cookies with keys? > Anyone...
2
by: August Derleth | last post by:
Cause I made such a hash of my first attempt, and in an effort to provide PORTABLE code to solve the problem, I submit this solution to convert to and from BCD values stored in longs. This should...
9
by: Hayato Iriumi | last post by:
Hello, I hear some hypes about creating code to generate C# or VB .NET code, that is, code generation (sounds straight forward enough). I haven't really seen how it's done in real world. I'm...
28
by: MLH | last post by:
The largest integer A97 can deal with is 2,147,483,647, as I understand it from HELP. I would be content to represent larger integers as strings. For example, "2147483648" would suit me fine. I...
0
by: HK | last post by:
I'm wanting to get rid of a hardware load balancer and just use the Windows 2003 software load balancing with 2003 Server Web Edition. I'm wondering if anyone here uploads ASP.NET code to 2 or...
3
by: Inny | last post by:
Im not sure how to implement this script, it should pop the blank window only if someone clicks veiw source in the context menu or the toolbatr. help? <html> <head> <SCRIPT> <!--...
9
by: jacob navia | last post by:
Hi I am incorporating 128 Bit integer code into lcc-win and it would be nice to have some code to test this feature. Has anyone here code that uses 128 bit integers? Thanks in advance ...
14
by: MrDeej | last post by:
Hello guys. I have a SQL table which uses ODBC from Access. I have a relatively large table with 850 000 rows. Today i tried to update a field in the table from NULL to a textvalue. I clocked...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.