- 04 FF 79 04 3B 04 04 FF -7A 04 3B 04 04 FF 7B 04
-
3B 04 04 FF 7C 04 3B 04 -04 FF 7D 04 3B 04 04 FF
-
7E 04 3B 04 7F 04 3B 04 -04 FF 80 04 3B 04 04 FF
-
81 04 3B 04 04 FF 82 04 -3B 04 04 FF 83 04 3B 04
The data is missing between 04 7F.If i want insert 04 FF between 04 7F.how i can make it?
I want to check from byte 49 to mfilesize.Here i would like to do insertion.After every 5 value the trend is 04 FF.But the data is missing over there.
I want to make the thing look like this - 04 FF 79 04 3B 04 04 FF -7A 04 3B 04 04 FF 7B 04----line 1
-
3B 04 04 FF 7C 04 3B 04 -04 FF 7D 04 3B 04 04 FF-----line2
-
7E 04 3B 04 04 FF 7F 04 -3B 04 04 FF 80 04 3B 04---------line 3
-
04 FF 81 04 3B 04 04 FF -82 04 3B 04 04 FF 83 04 ----------line 4
u can see line 3 i add 04 FF between 04 7F.how i can do it using vb?
16 2027
First, please use a message title which reflects the actual question you are asking. When people are looking through the list for questions that they may be able to answer, or would also like to know about, "Help Me On This" is not going to attract any attention. You are just shooting yourself in the foot, and making the forum less useful for the rest of us.
Anyway...
Here's a function I've just written (have not tested it, so use it at your own risk) to insert a new byte value into an existing byte array at the specified position. It should be some help in this case... - Public Function InsertByte(pmArray() As Byte, pmPosition As Long, ByVal pmNewValue As Byte)
-
' Function to insert 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
Thanks Killer42.its Realy Helpful
- Public Function InsertByte(pmArray() As Byte, pmPosition As Long, ByVal pmNewValue As Byte)
-
' Function to insert a new byte value into a byte array.
-
Dim ArrayStart As Long, ArrayEnd 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
-
Next
-
pmArray(pmPosition) = pmNewValue
-
End Function
-
-
-
-
-
-
-
-
Private command 1 _click ()
-
Const a As Byte = 4
-
Const b As Byte = &HFF
-
Dim I As Long
-
Dim AnyChanged As Boolean
-
-
-
For I = 49 To mFileSize - 6 Step 6
-
changeMade = False
-
-
Debug.Print "Before : "; HexByte2Char(arrByte(I)); " "; HexByte2Char(arrByte(I + 1)); " "; HexByte2Char(arrByte(I + 2)); _
-
" "; HexByte2Char(arrByte(I + 3)); " "; HexByte2Char(arrByte(I + 4)); " "; HexByte2Char(arrByte(I + 5)) " "
-
-
-
If arrByte(I) <> a Then
-
arrByte(I) = a
-
changeMade = True
-
End If
-
If arrByte(I + 1) <> b Then
-
arrByte(I + 1) = b
-
changeMade = True
-
End If
-
-
-
If changeMade Then
-
AnyChanged = True
-
If changeMade Then
-
AnyChanged = True
-
Debug.Print "After : "; HexByte2Char(arrByte(I)); " "; HexByte2Char(arrByte(I + 1)); " "; HexByte2Char(arrByte(I + 2)); _
-
" "; HexByte2Char(arrByte(I + 3)); " "; HexByte2Char(arrByte(I + 4)); " "; HexByte2Char(arrByte(I+5)); " "
-
-
End If
-
Debug.Print
-
Next
How i can use the above function to call the insert byte function?Here i just wana insert do wana replace .No idea .Can u explain how i can do this?
It goes at the point in your logic where you have decided you want to insert something into your array.
By the way, I see you have another post asking how to delete something out of a byte array. I'd suggest you pick apart the insert routine I wrote, and modify it to work as a delete. This should be quite simple, really.
Public Function InsertByte(pmArray() As Byte, pmPosition As Long, ByVal pmNewValue As Byte)
' Function to insert 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
please explain what this coding doing?i cant undersatand what actualy this coding is doing
Ok, my code had a couple of little bugs, which I've now corrected (I highlighted the corrections in your message).
All it does is take an array of bytes, and insert another one at the requested position.
Here's a sample program which should help to illustrate it. It creates a byte array, places the word "Hello" in it (ASCII values of the letters), then calls that Sub to insert an "A" in the third position. It displays the size and contents of the array, before and after.
To run this, just create a new project, add a module, set the startup object to Sub Main, add a copy of the original InsertByte routine, and paste in this code... - Public Sub Main()
-
-
Dim b() As Byte
-
-
ReDim b(1 To 5)
-
b(1) = 72 ' ASCII code for "H"
-
b(2) = 101 ' ASCII code for "e"
-
b(3) = 108 ' ASCII code for "l"
-
b(4) = 108 ' ASCII code for "l"
-
b(5) = 111 ' ASCII code for "o"
-
ShowArrayContents b
-
InsertByte b, 3, 65 ' Insert ASCII code for "A" at position 3.
-
ShowArrayContents b
-
-
End Sub
-
-
-
Private Sub ShowArrayContents(ByteArray() As Byte)
-
-
Dim L As Long, U As Long ' Lower/Upper bounds of the array
-
Dim S As Long ' S = Size of array (total number of elements)
-
Dim I As Long ' Loop counter.
-
-
L = LBound(ByteArray)
-
U = UBound(ByteArray)
-
S = U - L + 1
-
-
Debug.Print "["; Format(S); "]";
-
For I = L To U
-
Debug.Print Chr$(ByteArray(I));
-
Next
-
Debug.Print
-
-
End Sub
If you want to know what the InsertByte routine does in more detail, just follow it through, statement by statement. But you don't actually need to understand it in order to use it. You can treat it as what's generally referred to as a "black box". It's just a box that takes some input and produces some output - you don't actually need to know what's inside the box.
- Option Explicit
-
Public Sub Main()
-
-
Dim b() As Byte
-
ReDim b(1 To 10)
-
b(1) = 72 ' ASCII code for "H"
-
b(2) = 101 ' ASCII code for "e"
-
b(3) = 108 ' ASCII code for "l"
-
b(4) = 108 ' ASCII code for "l"
-
b(5) = 111 ' ASCII code for "o"
-
b(6) = 112
-
b(7) = 113
-
b(8) = 115
-
b(9) = 116
-
b(10) = 117
-
ShowArrayContents b
-
InsertByte b, 11, 65 ' Insert ASCII code for "A" at position 3.
-
ShowArrayContents b
-
-
End Sub
-
-
-
Private Sub ShowArrayContents(ByteArray() As Byte)
-
-
Dim L As Long, U As Long ' Lower/Upper bounds of the array
-
Dim S As Long ' S = Size of array (total number of elements)
-
Dim I As Long ' Loop counter.
-
L = LBound(ByteArray)
-
U = UBound(ByteArray)
-
S = U - L + 1
-
Debug.Print "["; Format(S); "]";
-
For I = L To U
-
Debug.Print Chr$(ByteArray(I));
-
Next
-
Debug.Print
-
-
End Sub
-
-
Public Function InsertByte(pmArray() As Byte, pmPosition As Long, ByVal pmNewValue As Byte)
-
' Function to insert 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
I can understand now what the function is doing.This function already specify that insertion will happen in the 3rd place.How if we dont no the insertion will be happen at which place.We ourself finding the correct place to do insertion.This function only read until byte 10.How if i wana read until eof and figure out the place to do insertion.Let say for eg
04 FF 79 04 3B 04 04 FF- 7A 04 3B 04 04 FF 7B 04
3B 04 04 FF 7C 04 3B 04- 04 FF 7D 04 3B 04 04 FF
7E 04 3B 04 7F 04 3B 04 - 04 FF 80 04 3B 04 04 FF
Here 04 FF is missing betwen 04 7F and I would like to insert the 04 FF values and i do no how to maniplate the eg coding that you give
Sorry, but I think you need to work out for yourself the logic of what you want to do. Then we can help with the coding. If you can explain in enough detail where you need to insert these bytesm then the code will more or less take care of itself.
The point of that InsertByte routine is to make the process easier. Once you work out where you want to insert a byte, you can just call that routine to do it.
P.S. When posting source code, please use CODE tags as outlined in the Posting Guidelines.
-
-
Public Function InsertByte(pmArray() As Byte, pmPosition As Long, ByVal pmNewValue As Byte)
-
' Function to insert 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
-
-
-
-
Const a As Byte = 4
-
Const b As Byte = &HFF
-
Dim I As Long
-
Dim AnyChanged As Boolean
-
Dim changeMade As Boolean
-
-
For I = 49 To mfilesize - 6 Step 6
-
AnyChanged = False
-
Debug.Print "Before : "; HexByte2Char(arrByte(I)); " "; HexByte2Char(arrByte(I + 1)); " "; HexByte2Char(arrByte(I + 2)); _
-
" "; HexByte2Char(arrByte(I + 3)); " "; HexByte2Char(arrByte(I + 4)); " "; HexByte2Char(arrByte(I + 5))
-
-
-
If arrByte(I) <> a Then
-
insert mfilesize, 6, a step 6
-
changeMade = True
-
End If
-
If arrByte(I + 1) <> b Then
-
insert mfilesize , 7, b step 7
-
changeMade = True
-
End If
-
If changeMade Then
-
AnyChanged = True
-
Debug.Print "After : "; HexByte2Char(arrByte(I)); " "; HexByte2Char(arrByte(I + 1)); " "; HexByte2Char(arrByte(I + 2)); _
-
" "; HexByte2Char(arrByte(I + 3)); " "; HexByte2Char(arrByte(I + 4)); " "; HexByte2Char(arrByte(I + 5)); _
-
""
-
End If
-
Debug.Print
-
is it correct way.im using the insert function.So am i using it correctly?
I would say you're probably getting quite close to what you want.
But lines 42 and 46 look wrong. I assume they are intended to call the InsertByte routine, in which case the name and parameters are both wrong. The parameters is accepts are as follows: - The array into which a byte is to be inserted,
- The position in the array to insert the new value, and
- The value to be inserted.
In the case of line 42 for example, that would be:
A couple of other things to consider... - My apologies. I really should have made InsertByte a Sub, rather than a Function, since it doesn't return anything. Probably doesn't matter much, though.
- If you think about it, each time you call InsertByte, the array will get one byte longer. But your variable mfilesize will still be the same.
You can add 1 to mfilesize each time, but the For loop will still finish too early.
Hm...
I tell you what. I finally have a little time on my hands, so I'll try a quick rewrite to allow for the expansion of the array. Note, I won't include the InsertByte sub here, as it's just a waste of space. We'll assume you already have it. You should be able to paste this into a new code module in VB, then just copy in the other functions required, like HexByte2Char and InsertByte.
Also, note that I went back through some earlier posts and pulled together info top try and make this the complete "fix an open file" routine. You will probably still need to adjust things a bit. I have not tested this at all. - Option Explicit
-
-
Dim arrByte() As Byte
-
Dim mFileSize As Long
-
Dim ChangeMade As Boolean
-
-
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
-
-
' This little array will be used to hold the "before" values,
-
' so we can display them.
-
Dim HoldByte(1 To 6) As Byte
-
-
-
' PART 1: Read the file into a Byte array
-
' =======================================
-
-
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
-
-
-
' PART 2: Scan the array for dropped bytes and insert them
-
' ========================================================
-
-
I = 49
-
' Note, not using a FOR loop, as the end-point may shift during processing.
-
Do Until I >= mFileSize
-
' 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
-
-
' Check for missing bytes and insert.
-
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(arrayByte, I, I + 5)
-
Debug.Print
-
End If
-
-
I = I + 6
-
Loop
-
-
-
-
' PART 3: If data was changed, write it back to the file
-
' ======================================================
-
-
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
-
End Sub
-
-
-
Private Function FormattedByteArray(parmArray() As Byte, Start As Long, Finish As Long) As String
-
' Format bytes [Start] to [Finish] from a byte array, as
-
' two hex digits each with spaces between.
-
-
Dim I As Long
-
For I = Start To Finish
-
' Add each byte to the string, followed by a space.
-
FormattedByteArray = FormattedByteArray & HexByte2Char(parmArray(I)) & " "
-
Next
-
FormattedByteArray = RTrim(FormattedByteArray) ' Trim off the last space.
-
-
End Function
-
-
thanks killer42.Thanks alot for ur guidance
can i call the rewrite function like this - private command 1( )click
-
-
rewrite_open_file
-
-
end sub
-
why it giving the error the argument isnot optional
can i call the rewrite function like this - private command 1( )click
-
rewrite_open_file
-
end sub
-
why it giving the error the argument isnot optional
The error is quite self-explanatory. The rewrite_open_file routine requires an argument, and you didn't supply one. In this particular case, it expects the number of the currently open file.
Hang on, I'll have a go at rewriting it again so you can just call it. Better still, I'll set it up to accept a filename as an argument. So you can say Rewrite_File "A:\aaa.txt" or whatever.
Give me ten minutes...
Ok, more like 40 minutes. Anyway, here is my little trial project. I have compiled it, but haven't actually tried it out on any files yet. Be careful, as it could destroy any file you use it on.
killer42 ,the insertion part is success.Thanks alot.U are helping me alot.Thank you very much for ur guidance.Thanks alot sir
killer42 ,the insertion part is success.Thanks alot.U are helping me alot.Thank you very much for ur guidance.Thanks alot sir
Glad to hear it helped. :)
And perhaps more importantly, I hope you've picked up some programming tips that will help you resolve further problems.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Jack |
last post by:
I have a text file of data in a file (add2db.txt) where the entries are
already entered on separate lines in the following form:
INSERT INTO `reviews` VALUES("", "Tony's", "Lunch", "Great...
|
by: Niraj |
last post by:
Hi,
I am trying to do bulk insert of binary data (array of bytes) in an
Oracle table. The data type of the table is BLOB. I am using Oracle
Objects for OLE (OO4O) in C++.
The binary data that I...
|
by: mprocopio |
last post by:
Fellow JavaScripters,
I am looking for code or implementation ideas for converting an integer
variable to a four-byte array. I'm porting some of my code from C#,
where I make use of their...
|
by: Chris Fink |
last post by:
I have setup an Oracle table which contains a blob field. How do I insert
data into this field using C# and ADO.net?
|
by: SSP |
last post by:
Dear ASP.NETers,
How would I insert multiple rows of data from a web form?
Are there any tute's and stuff around. Couldn't find any myself.
Thanks in advance.
SSP
|
by: minlar |
last post by:
Hello,everyone:
what the value of the variables in the next programe:
{ int x=35;
char str;
strcpy(str,"www.google.com");}
what's the value of x and strlen(str)?
any help is welcome, and I am...
|
by: james |
last post by:
Hi,
I am trying to insert a record into a database table, one field of which is
a byte array.
Using the below:
Byte imgArr;
.... <code to put image into imgArr>
|
by: Gregor =?UTF-8?B?S292YcSN?= |
last post by:
Hi!
I'm using JDBC to connect to DB2. I have a binary data (array of bytes) and
want to save them.
Is it possible to write an INSERT statement to do this:
INSERT INTO TABLE (ID, BYTES)...
|
by: venkatagmail |
last post by:
I have problem understanding pass by value and pass by reference and
want to how how they are or appear in the memory:
I had to get my basics right again. I create an array and try all
possible...
|
by: Seongsu Lee |
last post by:
Hi,
I have a dictionary with million keys. Each value in the
dictionary has a list with up to thousand integers.
Follow is a simple example with 5 keys.
dict = {1: ,
2: ,
900000: ,
900001:...
|
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...
|
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,...
|
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...
|
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...
|
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...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |