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. - Public Function DeleteByte(pmArray() As Byte, pmPosition As Long, ByVal pmNewValue As Byte)
-
' Function to delete a new byte value into a byte array.
-
Dim ArrayStart As Long, ArrayEnd As Long
-
Dim I As Long
-
ArrayStart = LBound(pmArray)
-
ArrayEnd = UBound(pmArray) -1
-
' Expand array to make room for the new value.
-
ReDim Preserve pmArray(ArrayStart To ArrayEnd)
-
' If requested position is outside the array, just stick it
-
' at the start or end as appropriate.
-
If pmPosition < ArrayStart Then
-
pmPosition = ArrayStart
-
End If
-
If pmPosition > ArrayEnd Then
-
pmPosition = ArrayEnd
-
End If
-
' Unless adding to the end of the array,
-
' push everything across to make room.
-
If pmPosition < ArrayEnd Then
-
For I = ArrayEnd To pmPosition -1 Step -1
-
pmArray(I) = pmArray(I - 1)
-
Next
-
End If
-
pmArray(pmPosition) = pmNewValue
-
End Function
Aug 9 '07
36 3511 - public function delete( )
-
-
Dim strLookFor As String, strChangeTo As String
-
strChangeTo = Chr$(&H4) & Chr$(&HFF)
-
strLookFor = strChangeTo & strChangeTo
-
strFile = Replace(strFile, strLookFor, strChangeTo)
-
-
end sub
-
-
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....an d do replacement..
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... - Option Explicit
-
DefLng A-Z
-
-
Private strFileData As String, strOriginalData As String
-
-
Public Function ZapDuplicates(ByVal strFileName As String, strLookFor As String, strChangeTo As String) As Boolean
-
' Returned value indicates whether the file was actually changed.
-
Dim FileNo As Long
-
FileNo = FreeFile
-
Open strFileName For Binary Access Read Shared As #FileNo
-
strFileData = Space$(LOF(FileNo))
-
Get #FileNo, , strFileData
-
Close #FileNo
-
strOriginalData = strFileData
-
-
strFileData = Replace(strFileData, strLookFor, strChangeTo)
-
If strOriginalData <> strFileData Then
-
If MsgBox("Data changed - rewrite file?", vbQuestion + vbYesNo) = vbYes Then
-
Open strFileName For Output Access Write Lock Write As #FileNo
-
Print #FileNo, strFileData;
-
Close #FileNo
-
ZapDuplicates = True
-
End If
-
End If
-
strOriginalData = ""
-
strFileData = ""
-
End Function
I hope you will think carefully about the parameters. If you plug in the actual string "04 FF" I'll be disappointed.
- Private Sub CMDFIND_Click()
-
-
If lblFileSpec.Caption = "" Then
-
Exit Sub
-
End If
-
txbSearch.Text = "04FF04FF"
-
picHexDisp.SetFocus
-
doHexSearch
-
End Sub
-
-
-
Private Sub doHexSearch()
-
On Error Resume Next
-
Dim HexCtn As Integer
-
Dim I, J
-
Dim mMatch As Boolean
-
Dim foundStartPos As Long
-
Screen.MousePointer = vbHourglass
-
HexCtn = Len(txbSearch.Text) / 2
-
ReDim arrHexByte(1 To HexCtn)
-
For I = 1 To HexCtn
-
arrHexByte(I) = CByte("&h" & (Mid(txbSearch.Text, (I * 2 - 1), 2)))
-
Next I
-
foundStartPos = prevFoundPos + 1
-
For I = foundStartPos To (UBound(arrByte) - (HexCtn - 1))
-
If arrByte(I) = arrHexByte(1) Then
-
mMatch = True
-
' Compare rest bytes
-
For J = 1 To (HexCtn - 1)
-
If arrByte(I + J) <> arrHexByte(1 + J) Then
-
mMatch = False
-
Exit For
-
End If
-
Next J
-
If mMatch = True Then
-
Dim k
-
foundStartPos = I
-
prevFoundPos = I
-
k = (foundStartPos + 1) / CLng(mPageSize)
-
k = NoFraction(k)
-
pageStart = k * mPageSize + 1
-
pageEnd = pageStart + mPageSize - 1
-
If pageEnd > mFileSize Then pageEnd = mFileSize
-
k = foundStartPos + (HexCtn - 1)
-
If k > pageEnd Then k = pageEnd
-
updEditByte
-
ShowPage True, foundStartPos, k, &HFFFF00, vbRed
-
Screen.MousePointer = vbDefault
-
Exit Sub
-
End If
-
End If
-
Next I
-
Screen.MousePointer = vbDefault
-
prevFoundPos = 0
-
MsgBox txbSearch.Text & vbCrLf & vbCrLf & "Searched to end."
-
End Sub
-
-
-
Function NoFraction(ByVal inVal As Variant) As Long
-
Dim X As Integer
-
Dim tmp As String
-
Dim k As Long
-
tmp = CStr(inVal)
-
X = InStr(tmp, ".")
-
If X > 0 Then
-
tmp = Left(tmp, X - 1)
-
End If
-
k = Val(tmp)
-
NoFraction = k
-
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?
The function that I provided in my last post will find and replace all occurrences of the string in the file, not just one.
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
-
-
-
-
-
-
Option Explicit
-
DefLng A-Z
-
-
Private strFileData As String, strOriginalData As String
-
-
Public Function ZapDuplicates(ByVal strFileName As String, strLookFor As String, strChangeTo As String) As Boolean
-
' Returned value indicates whether the file was actually changed.
-
Dim FileNo As Long
-
FileNo = FreeFile
-
Open strFileName For Binary Access Read Shared As #FileNo
-
strFileData = Space$(LOF(FileNo))
-
Get #FileNo, , strFileData
-
Close #FileNo
-
strOriginalData = strFileData
-
-
strFileData = Replace(strFileData, strLookFor, strChangeTo)
-
If strOriginalData <> strFileData Then
-
If MsgBox("Data changed - rewrite file?", vbQuestion + vbYesNo) = vbYes Then
-
Open strFileName For Output Access Write Lock Write As #FileNo
-
Print #FileNo, strFileData;
-
Close #FileNo
-
ZapDuplicates = True
-
End If
-
End If
-
strOriginalData = ""
-
strFileData = ""
-
End Function
-
-
private command1_click( )
-
-
call Function ZapDuplicates(a:\bonding.bin,04 FF 04 FF,04 FF)
-
-
end sub
-
-
-
i do no wheather im doing rite or not...Am i rite?
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,0 4 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.
- Private Sub Command2_Click() Dim i As String
-
Dim b As String
-
Dim m As String
-
Dim strLookFor As String
-
Dim strFileName As String
-
Dim strChangeTo As String
-
strChangeTo = Chr$(&H4) & Chr$(&HFF)
-
strChangeTo = i
-
strLookFor = strChangeTo & strChangeTo
-
strLookFor = b
-
strFileName = "a:/bonding.bin"
-
strFileName = m
-
Call ZapDuplicates(m, b, i)
-
End Sub
-
am i doing rite in passing the parameter?
Try this... - Private Sub Command2_Click()
-
' Dim i As String
-
' Dim b As String
-
' Dim m As String
-
Dim strLookFor As String
-
Dim strFileName As String
-
Dim strChangeTo As String
-
strChangeTo = Chr$(&H4) & Chr$(&HFF)
-
' strChangeTo = i <-- What is this for?
-
strLookFor = strChangeTo & strChangeTo
-
' strLookFor = b <-- What is this for?
-
strFileName = "a:\bonding.bin"
-
' strFileName = m <-- What is this for?
-
Call ZapDuplicates(strFileName, strLookFor, strChangeTo)
-
End Sub
-
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.)
-
-
-
Private Sub Command1_click()
-
Dim mHandle
-
mHandle = FreeFile
-
Open "a:\bonding.bin" For Binary Access Read Write Lock Write As mHandle
-
ReWrite_Open_File mHandle
-
End Sub
-
-
Public Function ZapDuplicates(ByVal strFilename As String, strLookFor As String, strChangeTo As String) As Boolean
-
' Returned value indicates whether the file was actually changed.
-
Dim FileNo As Long
-
FileNo = FreeFile
-
Open strFilename For Binary Access Read Shared As #FileNo
-
strFileData = Space$(LOF(FileNo))
-
Get #FileNo, , strFileData
-
Close #FileNo
-
strOriginalData = strFileData
-
strFileData = Replace(strFileData, strLookFor, strChangeTo)
-
If strOriginalData <> strFileData Then
-
If MsgBox("Data changed - rewrite file?", vbQuestion + vbYesNo) = vbYes Then
-
Open strFilename For Output Access Write Lock Write As #FileNo
-
Print #FileNo, strFileData;
-
Close #FileNo
-
ZapDuplicates = True
-
End If
-
End If
-
strOriginalData = ""
-
strFileData = ""
-
End Function
-
-
-
-
Public Sub ReWrite_Open_File(ByVal FileNo As Long)
-
-
Const a As Byte = 4
-
Const b As Byte = &HFF
-
Dim i As Long
-
Dim AnyChanged As Boolean
-
Dim J As Long
-
Dim strLookFor As String
-
Dim strChangeTo As String
-
Dim strFilename As String
-
' This little array will be used to hold the "before" values,
-
' so we can display them.
-
Dim HoldByte(1 To 6) As Byte
-
-
mFileSize = LOF(FileNo) ' Determine how large the file is (in bytes).
-
ReDim Buffer(1 To mFileSize) ' Set our buffer to that length.
-
Get #FileNo, 1, arrByte ' Grab the entire file's data into the array
-
-
-
-
i = 49
-
' Note, not using a FOR loop, as the end-point may shift during processing.
-
Do Until i >= mFileSize - 6
-
' Make a copy of this chunk of data, so we can display the
-
' "before" version after changing it.
-
For J = 1 To 6
-
HoldByte(J) = arrByte(i + J - 1)
-
Next
-
AnyChanged = False
-
-
-
If arrByte(i) <> a Then
-
InsertByte arrByte, i, a ' Identified a missing byte. Insert it.
-
mFileSize = mFileSize + 1 ' Reflect the addition of 1 byte to the array.
-
changemade = True
-
End If
-
If arrByte(i + 1) <> b Then
-
InsertByte arrByte, i + 1, b
-
mFileSize = mFileSize + 1 ' Reflect the addition of 1 byte to the array.
-
changemade = True
-
End If
-
' If we changed this chunk of data, report the change.
-
If changemade Then
-
AnyChanged = True
-
' This demonstrates how useful user-defined functions can be...
-
' Note, since we are reporting only the parts actually changed, you might
-
' want to try putting it in a RichTextBox again; the performance should be
-
' somewhat improved. (You could use a plain TextBox, too).
-
Debug.Print "Before ("; Format(i, "000000"); ") : "; FormattedByteArray(HoldByte, 1, 6)
-
Debug.Print "After ("; Format(i, "000000"); ") : "; FormattedByteArray(arrByte, i, i + 5)
-
Debug.Print
-
End If
-
i = i + 6
-
Loop
-
-
If AnyChanged Then
-
If MsgBox("Write data back to the file?", vbYesNo) = vbYes Then
-
Put #FileNo, 1, arrByte() ' Write the data back to the file.
-
End If
-
End If
-
-
strChangeTo = Chr$(&H4) & Chr$(&HFF)
-
-
strLookFor = strChangeTo & strChangeTo
-
-
strFilename = "a:\bonding.bin"
-
-
Call ZapDuplicates(strFilename, strLookFor, strChangeTo)
-
-
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 .
Sign in to post your reply or Sign up for a free account.
Similar topics |
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 primitive
int *array = new int;
|
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 nice and working allocation deallocation
routines. However, I don't want to loose the nice extras of new operator,
like - constructor calling, typecasting the result, keeping the array size,
etc.
For another bunch of reasons, outside this scope I...
|
by: jeff |
last post by:
how do you convert form byte to Int32 while retaining the binary
value of the byte array
|
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 the process exits, but I am having
trouble
I have written a Finalizer on the object that actually generates the
bitmaps, as well as implementing IDisposable. The finalizer gets called, I
then call Dispose on each of the bitmaps it the object has...
|
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 will prove
useful.
structure MyStruct
{
// this is a complicated struct declaration in the sense
| |
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.
|
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 a temp array and
delete afterwards if necessary but since I'm actually working in a nested
situation this could get a little messy. I guess I could set there values to
null and remove them afterwards?
Thanks,
Jon
|
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 04 FF - EC 03 37 04 04 FF EB 03....line 3
There is repeating data in the above value.How i can delete the repeating value.When i check it out from byte 49 to mfile size there is repeating data 04 FF.How i can use vb to delete the repetating...
|
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 implement operator new/delete I can't see a way to
indicate, on delete, how many objects must be destroyed (or how big
the space is) - alternatively I can't figure out what are the alignment
requirements so that the implementation, after calling my...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |