473,385 Members | 1,856 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,385 software developers and data experts.

delete value in array of byte

kirubagari
158 100+
How about the deletion function.i just modify the insert function to delete function.is it correct.actualy i would like to delete if 04 FF 04 FF (got repeating value) i would like to delete one of the 04 FF.So can i use the function that i modify .The same thing i wana do as insert function but i wana delete this time the condition is if there is repeating value as i mentioned just now.




Expand|Select|Wrap|Line Numbers
  1. Public Function DeleteByte(pmArray() As Byte, pmPosition As Long, ByVal pmNewValue As Byte)
  2. ' Function to delete a new byte value into a byte array.
  3. Dim ArrayStart As Long, ArrayEnd As Long
  4. Dim I As Long
  5. ArrayStart = LBound(pmArray)
  6. ArrayEnd = UBound(pmArray) -1
  7. ' Expand array to make room for the new value.
  8. ReDim Preserve pmArray(ArrayStart To ArrayEnd)
  9. ' If requested position is outside the array, just stick it
  10. ' at the start or end as appropriate.
  11. If pmPosition < ArrayStart Then
  12. pmPosition = ArrayStart
  13. End If
  14. If pmPosition > ArrayEnd Then
  15. pmPosition = ArrayEnd
  16. End If
  17. ' Unless adding to the end of the array,
  18. ' push everything across to make room.
  19. If pmPosition < ArrayEnd Then
  20. For I = ArrayEnd To pmPosition -1 Step -1
  21. pmArray(I) = pmArray(I - 1)
  22. Next
  23. End If
  24. pmArray(pmPosition) = pmNewValue
  25. End Function
Aug 9 '07 #1
36 3439
Killer42
8,435 Expert 8TB
I don't think the code is quite right. But before we get into the code, I'd like you to try and state fairly simply, the method to be used. In other words, can you describe to me, in a fairly simple overview, how you would go about removing a value from the middle of an array?

Turning it into code is quite simple, and we'll get that done quite quickly. But first you have to understand what you're trying to code.

I'll give you a hint. It's not the same sort of process as inserting. If you start by shortening the array, you've just thrown away whatever was at the end of it.
Aug 9 '07 #2
kirubagari
158 100+
Actualy are u saying that it is not possible to delete the byte in the middle of array.My problem is now

Expand|Select|Wrap|Line Numbers
  1.  04 FF 89 67 87 90 89 04 FF 04 FF 
  2. 89 65 67 78 93 78 78 89 84 67 04
  3.  

i wana delete one of the repeating 04 FF in the array of byte.is it possible in vb?
Aug 9 '07 #3
kirubagari
158 100+
Actualy when i insert one i have delete one of the 04 FF value in my program

The arrangement of array sometime like 04 FF 04 FF.So when i insert one 04 FF,i should delete one 04 FF.so i have to find the position where should i delete,sowhen there is repeating value like 04 FF 04 FF ,so i wana delete 1 of the 04 FF.So i have to check until EOF to find out the location to be deleted.So i think it will be explain problem more clear.
Aug 9 '07 #4
Killer42
8,435 Expert 8TB
Certainly it's possible to remove a value from the middle of an array. I'd just like you to think about how you would go about removing one from somewhere in the middle.

You might try thinking of the array as a row of boxes, or something similar. What would be the steps involved in taking one out of the middle and not leaving a gap? If you can explain that in detail, you will be very close to writing the code for it.

(Note, here I'm just talking about the actual removal of a byte. This has nothing to do with deciding what byte to remove.)
Aug 9 '07 #5
kirubagari
158 100+
Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. 04 FF F2 03 37 04 04 FF- F1 03 37 04 04 FF F0 03
  4. 37 04 04 FF EF 03 37 04 - 04 FF 04 FF EE 03 37 04
  5. 04 FF ED 03 37 04 04 FF- EC 03 37 04 04 FF EB 03
  6.  
  7.  
For eg i wana find out where the repeating value of 04 FF 04 FF occur,then i wana delete one of the 04 FF
then i wana merge the array.


Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. 04 FF F2 03 37 04 04 FF - F1 03 37 04 04 FF F0 03
  4. 37 04 04 FF EF 03 37 04 - 04 FF EE 03 37 04 04 FF
  5. ED 03 37 04 04 FF EC 03 - 37 04 04 FF EB 03 89 67
  6.  
  7.  
  8.  
This is i wana do after the insertion and do deletion also.How to start?Wana check until EOF and do deletion as the location where there is repeating structure
Aug 10 '07 #6
Killer42
8,435 Expert 8TB
You keep jumping ahead. I'm still trying to get you to spell out how you would go about removing a byte from an array. Let's get working tools before we try to use them, huh?
Aug 10 '07 #7
kirubagari
158 100+
sir so how if u give a function that delete byte from array as u give me as insertion function.Like delete a value from array of byte as starting so that i can understand more[/font]
Aug 10 '07 #8
kirubagari
158 100+
how to delete a value from a byte of array.like HELLO.i wana delete the 2nd value.How i can do in vb
Aug 10 '07 #9
Killer42
8,435 Expert 8TB
how to delete a value from a byte of array.like HELLO.i wana delete the 2nd value.How i can do in vb
Now that I think about if further, if you are just looking to replace duplicated strings, I think it will be much simpler to work with a string. You probably won't need the "delete a byte" routine.

Let's assume, for the sake of argument, that you have read your file into string variable strText, instead of a byte array. I think the Replace() function might do the fix for you, all in one go, like so...

Expand|Select|Wrap|Line Numbers
  1. Dim strLookFor As String, strChangeTo As String
  2. strChangeTo = Chr$(&H04) & Chr$(&HFF)
  3. strLookFor = strChangeTo & strChangeTo
  4. strFile = Replace(strFile, strLookFor, strChangeTo)
Aug 10 '07 #10
kirubagari
158 100+
Expand|Select|Wrap|Line Numbers
  1.  public function delete( ) 
  2.  
  3. Dim strLookFor As String, strChangeTo As String
  4. strChangeTo = Chr$(&H4) & Chr$(&HFF)
  5. strLookFor = strChangeTo & strChangeTo
  6. strFile = Replace(strFile, strLookFor, strChangeTo)
  7.  
  8. end sub
  9.  
  10.  
Can i used the function.It can do deletion is it.....is it deleting the repeating value.can i call the function as i did in the insertion part....open the binary file and check it out until EOF to check whether there is repeating structure....and do replacement..
Aug 10 '07 #11
Killer42
8,435 Expert 8TB
Here's a code module containing a function which I think will do the trick. You need to call it, passing the file name, the string to look for (04 FF 04 FF) and the string to replace it with (04 FF). Hopefully, it will do the rest. I haven't tested it, though...

Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2. DefLng A-Z
  3.  
  4. Private strFileData As String, strOriginalData As String
  5.  
  6. Public Function ZapDuplicates(ByVal strFileName As String, strLookFor As String, strChangeTo As String) As Boolean
  7.   ' Returned value indicates whether the file was actually changed.
  8.   Dim FileNo As Long
  9.   FileNo = FreeFile
  10.   Open strFileName For Binary Access Read Shared As #FileNo
  11.   strFileData = Space$(LOF(FileNo))
  12.   Get #FileNo, , strFileData
  13.   Close #FileNo
  14.   strOriginalData = strFileData
  15.  
  16.   strFileData = Replace(strFileData, strLookFor, strChangeTo)
  17.   If strOriginalData <> strFileData Then
  18.     If MsgBox("Data changed - rewrite file?", vbQuestion + vbYesNo) = vbYes Then
  19.       Open strFileName For Output Access Write Lock Write As #FileNo
  20.       Print #FileNo, strFileData;
  21.       Close #FileNo
  22.       ZapDuplicates = True
  23.     End If
  24.   End If
  25.   strOriginalData = ""
  26.   strFileData = ""
  27. End Function
I hope you will think carefully about the parameters. If you plug in the actual string "04 FF" I'll be disappointed.
Aug 10 '07 #12
kirubagari
158 100+
Expand|Select|Wrap|Line Numbers
  1.  Private Sub CMDFIND_Click() 
  2.  
  3.   If lblFileSpec.Caption = "" Then
  4.     Exit Sub
  5.   End If
  6.   txbSearch.Text = "04FF04FF"
  7.   picHexDisp.SetFocus
  8.   doHexSearch
  9. End Sub
  10.  
  11.  
  12. Private Sub doHexSearch()
  13.   On Error Resume Next
  14.   Dim HexCtn As Integer
  15.   Dim I, J
  16.   Dim mMatch As Boolean
  17.   Dim foundStartPos As Long
  18.   Screen.MousePointer = vbHourglass
  19.   HexCtn = Len(txbSearch.Text) / 2
  20.   ReDim arrHexByte(1 To HexCtn)
  21.   For I = 1 To HexCtn
  22.     arrHexByte(I) = CByte("&h" & (Mid(txbSearch.Text, (I * 2 - 1), 2)))
  23.   Next I
  24.   foundStartPos = prevFoundPos + 1
  25.   For I = foundStartPos To (UBound(arrByte) - (HexCtn - 1))
  26.     If arrByte(I) = arrHexByte(1) Then
  27.       mMatch = True
  28.       ' Compare rest bytes
  29.       For J = 1 To (HexCtn - 1)
  30.         If arrByte(I + J) <> arrHexByte(1 + J) Then
  31.           mMatch = False
  32.           Exit For
  33.         End If
  34.       Next J
  35.       If mMatch = True Then
  36.         Dim k
  37.         foundStartPos = I
  38.         prevFoundPos = I
  39.         k = (foundStartPos + 1) / CLng(mPageSize)
  40.         k = NoFraction(k)
  41.         pageStart = k * mPageSize + 1
  42.         pageEnd = pageStart + mPageSize - 1
  43.         If pageEnd > mFileSize Then pageEnd = mFileSize
  44.         k = foundStartPos + (HexCtn - 1)
  45.         If k > pageEnd Then k = pageEnd
  46.         updEditByte
  47.         ShowPage True, foundStartPos, k, &HFFFF00, vbRed
  48.         Screen.MousePointer = vbDefault
  49.         Exit Sub
  50.       End If
  51.     End If
  52.   Next I
  53.   Screen.MousePointer = vbDefault
  54.   prevFoundPos = 0
  55.   MsgBox txbSearch.Text & vbCrLf & vbCrLf & "Searched to end."
  56. End Sub
  57.  
  58.  
  59. Function NoFraction(ByVal inVal As Variant) As Long
  60.   Dim X As Integer
  61.   Dim tmp As String
  62.   Dim k As Long
  63.   tmp = CStr(inVal)
  64.   X = InStr(tmp, ".")
  65.   If X > 0 Then
  66.     tmp = Left(tmp, X - 1)
  67.   End If
  68.   k = Val(tmp)
  69.   NoFraction = k
  70. End Function
This is the function that I did to find out the string 04 FF 04 FF.So assign it to text box and when I click the FIND button it find from beginning of file until end. So is it correct way and give me some comments how I can enhance it on how it can find out the value without I click each time as find next value. So when I find out the value may be I can use the function that you give previously as making 04 FF 04 FF To 04 FF. Need your help?
Aug 13 '07 #13
Killer42
8,435 Expert 8TB
The function that I provided in my last post will find and replace all occurrences of the string in the file, not just one.
Aug 13 '07 #14
kirubagari
158 100+
sir am i doing rite sir.So can i use the function to find the string and use the function that u give to replace it
Aug 13 '07 #15
kirubagari
158 100+
Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3.  
  4.  
  5.  
  6. Option Explicit
  7. DefLng A-Z
  8.  
  9. Private strFileData As String, strOriginalData As String
  10.  
  11. Public Function ZapDuplicates(ByVal strFileName As String, strLookFor As String, strChangeTo As String) As Boolean
  12. ' Returned value indicates whether the file was actually changed.
  13. Dim FileNo As Long
  14. FileNo = FreeFile
  15. Open strFileName For Binary Access Read Shared As #FileNo
  16. strFileData = Space$(LOF(FileNo))
  17. Get #FileNo, , strFileData
  18. Close #FileNo
  19. strOriginalData = strFileData
  20.  
  21. strFileData = Replace(strFileData, strLookFor, strChangeTo)
  22. If strOriginalData <> strFileData Then
  23. If MsgBox("Data changed - rewrite file?", vbQuestion + vbYesNo) = vbYes Then
  24. Open strFileName For Output Access Write Lock Write As #FileNo
  25. Print #FileNo, strFileData;
  26. Close #FileNo
  27. ZapDuplicates = True
  28. End If
  29. End If
  30. strOriginalData = ""
  31. strFileData = ""
  32. End Function 
  33.  
  34. private command1_click( )
  35.  
  36. call Function ZapDuplicates(a:\bonding.bin,04 FF 04 FF,04 FF)
  37.  
  38. end sub
  39.  
  40.  
  41.  

i do no wheather im doing rite or not...Am i rite?



Aug 13 '07 #16
Killer42
8,435 Expert 8TB
There's no need to create a function called Replace. The Replace function is built into VB.

Also, in this line...
call Function ZapDuplicates(a:\bonding.bin,04 FF 04 FF,04 FF)
your parameters just don't make any sense. The ZapDuplicates function expects three parameters, all strings. You should read the documentation and get familiar with the basics like how to pass a parameter to a function, and how to specify a string.
Aug 13 '07 #17
kirubagari
158 100+
Expand|Select|Wrap|Line Numbers
  1.  Private Sub Command2_Click() Dim i As String
  2. Dim b As String
  3. Dim m As String
  4. Dim strLookFor As String
  5. Dim strFileName As String
  6. Dim strChangeTo As String
  7. strChangeTo = Chr$(&H4) & Chr$(&HFF)
  8. strChangeTo = i
  9. strLookFor = strChangeTo & strChangeTo
  10. strLookFor = b
  11. strFileName = "a:/bonding.bin"
  12. strFileName = m
  13. Call ZapDuplicates(m, b, i)
  14. End Sub
  15.  

am i doing rite in passing the parameter?







Aug 13 '07 #18
Killer42
8,435 Expert 8TB
Try this...

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command2_Click()
  2.   ' Dim i As String
  3.   ' Dim b As String
  4.   ' Dim m As String
  5.   Dim strLookFor As String
  6.   Dim strFileName As String
  7.   Dim strChangeTo As String
  8.   strChangeTo = Chr$(&H4) & Chr$(&HFF)
  9.   ' strChangeTo = i  <-- What is this for?
  10.   strLookFor = strChangeTo & strChangeTo
  11.   ' strLookFor = b   <-- What is this for?
  12.   strFileName = "a:\bonding.bin"
  13.   ' strFileName = m  <-- What is this for?
  14.   Call ZapDuplicates(strFileName, strLookFor, strChangeTo)
  15. End Sub
  16.  
For some reason, you were placing values in strFileName, strLookFor and strChangeTo, then throwing them away by replacing them with empty strings from i, b and m. (Also, note I changed the slash to a backslash in the file name.)
Aug 13 '07 #19
kirubagari
158 100+
Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. Private Sub Command1_click()
  4. Dim mHandle
  5. mHandle = FreeFile
  6. Open "a:\bonding.bin" For Binary Access Read Write Lock Write As mHandle
  7. ReWrite_Open_File mHandle
  8. End Sub
  9.  
  10. Public Function ZapDuplicates(ByVal strFilename As String, strLookFor As String, strChangeTo As String) As Boolean
  11. ' Returned value indicates whether the file was actually changed.
  12. Dim FileNo As Long
  13. FileNo = FreeFile
  14. Open strFilename For Binary Access Read Shared As #FileNo
  15. strFileData = Space$(LOF(FileNo))
  16. Get #FileNo, , strFileData
  17. Close #FileNo
  18. strOriginalData = strFileData
  19. strFileData = Replace(strFileData, strLookFor, strChangeTo)
  20. If strOriginalData <> strFileData Then
  21. If MsgBox("Data changed - rewrite file?", vbQuestion + vbYesNo) = vbYes Then
  22. Open strFilename For Output Access Write Lock Write As #FileNo
  23. Print #FileNo, strFileData;
  24. Close #FileNo
  25. ZapDuplicates = True
  26. End If
  27. End If
  28. strOriginalData = ""
  29. strFileData = ""
  30. End Function
  31.  
  32.  
  33.  
  34. Public Sub ReWrite_Open_File(ByVal FileNo As Long)
  35.  
  36. Const a As Byte = 4
  37. Const b As Byte = &HFF
  38. Dim i As Long
  39. Dim AnyChanged As Boolean
  40. Dim J As Long
  41. Dim strLookFor As String
  42. Dim strChangeTo As String
  43. Dim strFilename As String
  44. ' This little array will be used to hold the "before" values,
  45. ' so we can display them.
  46. Dim HoldByte(1 To 6) As Byte
  47.  
  48. mFileSize = LOF(FileNo) ' Determine how large the file is (in bytes).
  49. ReDim Buffer(1 To mFileSize) ' Set our buffer to that length.
  50. Get #FileNo, 1, arrByte ' Grab the entire file's data into the array
  51.  
  52.  
  53.  
  54. i = 49
  55. ' Note, not using a FOR loop, as the end-point may shift during processing.
  56. Do Until i >= mFileSize - 6
  57. ' Make a copy of this chunk of data, so we can display the
  58. ' "before" version after changing it.
  59. For J = 1 To 6
  60. HoldByte(J) = arrByte(i + J - 1)
  61. Next
  62. AnyChanged = False
  63.  
  64.  
  65. If arrByte(i) <> a Then
  66. InsertByte arrByte, i, a ' Identified a missing byte. Insert it.
  67. mFileSize = mFileSize + 1 ' Reflect the addition of 1 byte to the array.
  68. changemade = True
  69. End If
  70. If arrByte(i + 1) <> b Then
  71. InsertByte arrByte, i + 1, b
  72. mFileSize = mFileSize + 1 ' Reflect the addition of 1 byte to the array.
  73. changemade = True
  74. End If
  75. ' If we changed this chunk of data, report the change.
  76. If changemade Then
  77. AnyChanged = True
  78. ' This demonstrates how useful user-defined functions can be...
  79. ' Note, since we are reporting only the parts actually changed, you might
  80. ' want to try putting it in a RichTextBox again; the performance should be
  81. ' somewhat improved. (You could use a plain TextBox, too).
  82. Debug.Print "Before ("; Format(i, "000000"); ") : "; FormattedByteArray(HoldByte, 1, 6)
  83. Debug.Print "After ("; Format(i, "000000"); ") : "; FormattedByteArray(arrByte, i, i + 5)
  84. Debug.Print
  85. End If
  86. i = i + 6
  87. Loop
  88.  
  89. If AnyChanged Then
  90. If MsgBox("Write data back to the file?", vbYesNo) = vbYes Then
  91. Put #FileNo, 1, arrByte() ' Write the data back to the file.
  92. End If
  93. End If
  94.  
  95. strChangeTo = Chr$(&H4) & Chr$(&HFF)
  96.  
  97. strLookFor = strChangeTo & strChangeTo
  98.  
  99. strFilename = "a:\bonding.bin"
  100.  
  101. Call ZapDuplicates(strFilename, strLookFor, strChangeTo)
  102.  
  103.  
when i append the duplicate and rewrite function together it give the error saying that file already open....i wana do deletion rite after insertion .
Aug 14 '07 #20
Killer42
8,435 Expert 8TB
Just close the file before calling ZapDuplicates.
Aug 14 '07 #21
kirubagari
158 100+
Expand|Select|Wrap|Line Numbers
  1.  close #fileNo
  2. strChangeTo = Chr$(&H4) & Chr$(&HFF) 
  3.  
  4.  
  5. strLookFor = strChangeTo & strChangeTo
  6.  
  7. strFilename = "a:\bonding.bin"
  8.  
  9. Call ZapDuplicates(strFilename, strLookFor, strChangeTo)
  10.  
  11.  
  12.  
When i put the close #fileNo the output is not correct.When i do seperately it giving correct output.When i do together the 2 function the output is not correct.Why it is happening?
Aug 14 '07 #22
Killer42
8,435 Expert 8TB
At a guess, you are inserting bytes which are preventing you from finding the duplicates. Have you tried doing them the other way around? That is, first zap duplicates, then insert missing bytes.
Aug 14 '07 #23
kirubagari
158 100+
THANK YOU VERY MUCH SIR........the guidance that u give realy make the thing run correctlyREALY APPERICIATE SIR .U R REALY GREAT KILLER42.THANKS ALOT AGAIN FOR UR GUIDANCE AND THIS WEBSITE REALY GREAT
Aug 14 '07 #24
Killer42
8,435 Expert 8TB
Well, thanks. I guess it's nice to be appreciated sometimes. But we're usually glad to be able to help, around here.
Aug 14 '07 #25
kirubagari
158 100+
Expand|Select|Wrap|Line Numbers
  1.  Private Sub lblrewrite_Click() 
  2.  
  3. Dim strLookFor As String
  4. Dim strFileName As String
  5. Dim strChangeTo As String
  6. Dim mHandle
  7.  
  8. strChangeTo = Chr$(&H4) & Chr$(&HFF)
  9.  
  10. strLookFor = strChangeTo & strChangeTo
  11.  
  12. strFileName = "a:\bonding.bin"
  13.  
  14. Call ZapDuplicates(strFileName, strLookFor, strChangeTo)
  15.  
  16. mHandle = FreeFile
  17. Open "a:\bonding.bin" For Binary Access Read Write Lock Write As mHandle
  18. ReWrite_Open_File mHandle
  19. End Sub
  20.  
  21.  
  22. Public Function ZapDuplicates(ByVal strFileName As String, strLookFor As String, strChangeTo As String) As Boolean
  23. ' Returned value indicates whether the file was actually changed.
  24. Dim FileNo As Long
  25. FileNo = FreeFile
  26. Dim tmp
  27. Open strFileName For Binary Access Read Shared As #FileNo
  28. strFileData = Space$(LOF(FileNo))
  29. Get #FileNo, , strFileData
  30. Close #FileNo
  31. strOriginalData = strFileData
  32. strFileData = Replace(strFileData, strLookFor, strChangeTo)
  33. If strOriginalData <> strFileData Then
  34. tmp = MsgBox("Data changed - rewrite file?", vbQuestion + vbYesNo, "Data Changed")
  35. If tmp = vbYes Then
  36. MousePointer = vbHourglass
  37. Open strFileName For Output Access Write Lock Write As #FileNo
  38. Print #FileNo, strFileData;
  39. Close #FileNo
  40. ZapDuplicates = True
  41. ElseIf tmp = vbNo Then
  42. Unload Me
  43. End If
  44. End If
  45. strOriginalData = ""
  46. strFileData = ""
  47. End Function
  48.  
  49.  
  50.  
  51. Public Sub ReWrite_Open_File(ByVal FileNo As Long)
  52.  
  53. Const a As Byte = 4
  54. Const b As Byte = &HFF
  55. Dim I As Long
  56. Dim AnyChanged As Boolean
  57. Dim j As Long
  58. Dim strLookFor As String
  59. Dim strFileName As String
  60. Dim strChangeTo As String
  61. strChangeTo = Chr$(&H4) & Chr$(&HFF)
  62. ' This little array will be used to hold the "before" values,
  63. ' so we can display them.
  64. Dim HoldByte(1 To 6) As Byte
  65. ' PART 1: Read the file into a Byte array
  66. ' =======================================
  67. mFileSize = LOF(FileNo) ' Determine how large the file is (in bytes).
  68. ReDim Buffer(1 To mFileSize) ' Set our buffer to that length.
  69. Get #FileNo, 1, arrByte ' Grab the entire file's data into the array
  70.  
  71.  
  72. ' PART 2: Scan the array for dropped bytes and insert them
  73. ' ========================================================
  74. MousePointer = vbHourglass
  75. I = 49
  76. ' Note, not using a FOR loop, as the end-point may shift during processing.
  77. Do Until I >= mFileSize - 10
  78. ' Make a copy of this chunk of data, so we can display the
  79. ' "before" version after changing it.
  80. For j = 1 To 6
  81. HoldByte(j) = arrByte(I + j - 1)
  82. Next
  83. AnyChanged = False
  84.  
  85. ' Check for missing bytes and insert.
  86. If arrByte(I) <> a Then
  87. InsertByte arrByte, I, a ' Identified a missing byte. Insert it.
  88. mFileSize = mFileSize + 1 ' Reflect the addition of 1 byte to the array.
  89. changeMade = True
  90. End If
  91. If arrByte(I + 1) <> b Then
  92. InsertByte arrByte, I + 1, b
  93. mFileSize = mFileSize + 1 ' Reflect the addition of 1 byte to the array.
  94. changeMade = True
  95. End If
  96. ' If we changed this chunk of data, report the change.
  97. If changeMade Then
  98. AnyChanged = True
  99. ' This demonstrates how useful user-defined functions can be...
  100. ' Note, since we are reporting only the parts actually changed, you might
  101. ' want to try putting it in a RichTextBox again; the performance should be
  102. ' somewhat improved. (You could use a plain TextBox, too).
  103. Debug.Print "Before ("; Format(I, "000000"); ") : "; FormattedByteArray(HoldByte, 1, 6)
  104. Debug.Print "After ("; Format(I, "000000"); ") : "; FormattedByteArray(arrByte, I, I + 5)
  105. Debug.Print
  106. End If
  107. I = I + 6
  108. Loop
  109.  
  110. ' PART 3: If data was changed, write it back to the file
  111. ' ======================================================
  112. If AnyChanged Then
  113. If MsgBox("Write data back to the file?", vbYesNo, "DELETED DATA REPAIRER") = vbYes Then
  114. Put #FileNo, 1, arrByte() ' Write the data back to the file.
  115. Close #1
  116. MousePointer = vbDefault
  117. MsgBox "SCANNING AND REWRITING PROCESS FINISHED", vbOKOnly + vbInformation, "FINISHED"
  118. End If
  119. End If
  120.  
  121.  
  122.  
End Sub





I got problem with this code...please help me on how i can do insertion then deletion.This function is doing insertion to until end of file.But i wana do insertion of 04 FF followed by deletion of 04FF.How i can make this?

Before (292531) : D2 03 04 FF 12 04
After (292531) : 04 FF D2 03 04 FF

Before (292537) : 12 04 D2 03 04 FF
After (292537) : 04 FF 12 04 D2 03


When we insert 04 FF in front of D2 it become 04 FF D2 03 04 FF, The value will move after we insert the first value.After do the first insertion i wana do first deletion ......how i can do this?
Aug 30 '07 #26
Killer42
8,435 Expert 8TB
Sorry, very busy right now. I'll have to get back to you on this. Probably next week, as it looks like a busy weekend.
Aug 31 '07 #27
kirubagari
158 100+
killer 42 i need ur help
Sep 3 '07 #28
Killer42
8,435 Expert 8TB
killer 42 i need ur help
I apologise for the delay. The problem is that this one requires some thought. At the moment, I only have time to pop in briefly and bang out a couple of quick messages.

I hope you are still attempting to get this working yourself?
Sep 4 '07 #29
kirubagari
158 100+
ya i need ur giudanece on this.
Sep 4 '07 #30
kirubagari
158 100+
can u give mo some hidden how i can make this...
Sep 4 '07 #31
kirubagari
158 100+
Actually this is another deletion function. I do no how to do it.
I want to make 3 conditions like this
Expand|Select|Wrap|Line Numbers
  1.  
  2. 04 FF x 04 FF X X X X 04 FF X X X X or
  3. 04 FF x x 04 FF X X X X 04 FF X X X X or
  4. 04 FF x x x 04 FF X X X X04 FF X X X X
  5.  
x= any values

If the condition is correct I want to delete the highlighted values and move the values after the deleted values after correspond condition is reached.

How can I make this? I want to check the file until end of file and if the condition occurs I want to delete the values that highlight. How can I can that?

After delete I want to insert back the values at the corresponding place.

Actually the arrangement of the data in the file follows this trend

Expand|Select|Wrap|Line Numbers
  1.  04 FF X X X X 
  2. 04 FF X X X X
  3. 04 FF X X X X
  4. 04 FF X
  5. 04 FF X X X X 
  6. 04 FF X X X X 
  7. X X X 
  8. 04 FF X X X X 
  9.  
  10.  
I want to make the above thing like this

Expand|Select|Wrap|Line Numbers
  1.  04 FF X X X X
  2. 04 FF X X X X
  3. 04 FF X X X X
  4. (delete the value )
  5. 04 FF X X X X
  6. 04 FF X X X X
  7. 04 FF XX X X (put in front of X X X X)
  8. 04 FF X X X X
  9.  
This is the problem. When the data is corrupted and the data looks like this and after the repair look like above. Actually the data is arranged in 16 byte. The above is just eg. How can I make this?
Sep 4 '07 #32
Killer42
8,435 Expert 8TB
After reading through the final examples here, I think I'm getting a better idea of what you're after. With luck, I might be able to work it out for you by about this time tomorrow.
Sep 4 '07 #33
kirubagari
158 100+
killer 42 hopefully u can help me by today.thanks....
Sep 5 '07 #34
Killer42
8,435 Expert 8TB
I'm looking into this now. Hopefully will have something soon.
Sep 5 '07 #35
Killer42
8,435 Expert 8TB
Ok, here's what I've developed. In principle, I believe it should work. But it is entirely untested and thus should be treated with great caution.

I've written the routine from scratch. It reads in each byte in turn and tries to build up the 16 byte "field" starting with the two-byte "flag". If it doesn't find the flag it inserts it. If it does find the flag, but finds another one too soon (short record) then it discards the short one. Otherwise, it copies the entire "field" to an output buffer. Once it gets to the end, it checks the output buffer and if it's different to what we started with (and the user says Yes) then it overwrites the file.

That's the theory, anyway. As I said, it's not tested. In fact I've already jumped back into VB and corrected at least three bugs while I was typing this message.

The idea is that the data is made up of a series of :"fields", each of which starts with a "flag". The size of the field (16 in this case) and the flag (04FF in this case) can be specified as parameters to the function. Note that the length of the flag is included in the length of the field. That should mean that your data is made up of two flag bytes (04 FF) followed by 14 data bytes. If I've got that wrong, just adjust the FieldSize parameter you pass.
Attached Files
File Type: zip FileFixer.zip (3.0 KB, 128 views)
Sep 5 '07 #36
Killer42
8,435 Expert 8TB
I can't contain my curiosity any longer - did it work?
Sep 14 '07 #37

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

Similar topics

4
by: Shea Martin | last post by:
Which of the following do I use delete instead of just delete. //1.) // not sure about this one, as char is of size 1 char *str = new char; //2.) //not sure about this one, as it is a...
11
by: Jonan | last post by:
Hello, For several reasons I want to replace the built-in memory management with some custom built. The mem management itlsef is not subject to my question - it's ok to the point that I have...
19
by: jeff | last post by:
how do you convert form byte to Int32 while retaining the binary value of the byte array
8
by: Richard Arthur | last post by:
This is a weird problem. 1) I use MediaDet to save a bitmap in a temporary file. 2) I create a bitmap using that temporary file's name. 3) I use the bitmap. 4) I want to destroy the file when...
6
by: Aston Martin | last post by:
Hi All, ********************** My Situation ********************** I am working on project that involves passing a structure to unmanaged code from .Net world (well using C#). Perhaps an example...
9
by: Money | last post by:
If I allocate memory like this int *ptr = new int; Can I apply delete ptr; instead of delete ptr; since I am only allocating memory for 1 integer.
29
by: Jon Slaughter | last post by:
Is it safe to remove elements from an array that foreach is working on? (normally this is not the case but not sure in php) If so is there an efficient way to handle it? (I could add the indexes to...
1
kirubagari
by: kirubagari | last post by:
is it possible to do deletion in visual basic. 1.04 FF F2 03 37 04 04 FF - FF 03 37 04 04 FF F0 03.....line 1 2.37 04 04 FF EF 03 37 04 - 04 FF 04 FF EE 03 37 04.....line 2 3.04 FF ED 03 37 04...
13
by: Tristan Wibberley | last post by:
Hi I've got implementing overloaded operator new and delete pretty much down. Just got to meet the alignment requirements of the class on which the operator is overloaded. But how does one...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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,...

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.