473,473 Members | 2,032 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

is it correct way

kirubagari
158 New Member
Expand|Select|Wrap|Line Numbers
  1. private Sub cmdscan_Click()
  2.  
  3.   Const a As Byte = 4
  4.   Const b As Byte = &HFF
  5.   Dim I As Long
  6.   Dim AnyChanged As Boolean
  7.   Dim changeMade As Boolean
  8.   Dim value As Byte
  9.   'Dim x
  10.   'Dim tmp As String
  11.  
  12.   For I = 49 To 100 Step 6
  13.     AnyChanged = False
  14.    rich1.text= ; "Before : "; HexByte2Char(arrByte(I)); " "; HexByte2Char(arrByte(I + 1)); " "; HexByte2Char(arrByte(I + 2)); _ vbnewline
  15.     " "; HexByte2Char(arrByte(I + 3)); " "; HexByte2Char(arrByte(I + 4)); " "; HexByte2Char(arrByte(I + 5))
  16.    ' Print HexByte2Char(I)
  17.  
  18.     If arrByte(I) <> a Then
  19.       arrByte(I) = a
  20.       value = a
  21.       changeMade = True
  22.  
  23.     End If
  24.     If arrByte(I + 1) <> b Then
  25.       arrByte(I + 1) = b
  26.       changeMade = True
  27.     End If
  28.     If changeMade Then
  29.       AnyChanged = True
  30.       rich1.text="After  : "; HexByte2Char(arrByte(I)); " "; HexByte2Char(arrByte(I + 1)); " "; HexByte2Char(arrByte(I + 2)); _
  31.       " "; HexByte2Char(arrByte(I + 3)); " "; HexByte2Char(arrByte(I + 4)); " "; HexByte2Char(arrByte(I + 5)); _vbnewline
  32.       "  <--- Corrected"
  33.     End If
  34.     Debug.Print
  35.   Next
  36.  
  37. End Sub

is it way to display it in richbox.debug.print i used rich1.text="After..............

or put rich1.text=rich1.text& HexByte2Char(arrByte(I)); " "; HexByte2Char(arrByte(I + 1)); " "; HexByte2Char(arrByte(I + 2)); _ vbnewline

is it the way

u said i can open the file in binary mode and display the array back to file.



mHandle = FreeFile
Open "a:\bonding.bin " For Binary As mHandle
how to put back into file.Sorry again because im asking a lot question.im asking question for simple task aslo.sory killer32
Jul 13 '07 #1
5 1136
Killer42
8,435 Recognized Expert Expert
Let's see...

To put text in a variable, or a property, you cannot use the semicolon (;) to concatenate things. That is part of the Print statement. You need to use an ampersand (&) to join strings together.

As you will also see, placing a value into a variable or property replaces whatever was there before. So if you want to add onto the end, you need to concatenate (join) the existing value and the new part, and place the results back there.

As for writing data back to a file in binary mode, it's pretty simple. I'll throw together a simple little piece of code which will read an entire file into an array, close the file, then open the file again and write it back. (This iwll be based on the file-reading sample in the VB Articles area).

Caution: This code has not been tested. Use it with great care. If it's not correct, it could destroy the file that you tell it to process. (Assuming it does work, you should not see any effect, since the file is rewritten with the exact same data - though I suppose the last-updated date/time would change.)

To use it, just add a new code module to a VB project, and copy/paste the entire thing into it. Note, if you find that the line numbers get copied, just hit the Reply button, and copy the code from the reply window.

Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2.  
  3. Public Sub ReWrite_File(ByVal FileName As String)
  4.   Dim FileNo As Long, FileSize As Long
  5.   Dim Buffer() As Byte
  6.  
  7.  
  8.   ' PART 1: Read the file.
  9.  
  10.   FileNo = FreeFile ' Get next available file number.
  11.   Open FileName For Binary Access Read Shared As #FileNo
  12.   FileSize = LOF(FileNo) ' Determine how large the file is (in bytes).
  13.   ReDim Buffer(1 To FileSize) ' Set our buffer to that length.
  14.  
  15.   ' The size of the Buffer determines how many bytes are read...
  16.   Get #FileNo, , Buffer() ' Grab the entire file's data into the array
  17.   Close #FileNo
  18.  
  19.  
  20.   ' PART 2
  21.   ' If you plan to change the data, this is where it would happen.
  22.  
  23.   Beep
  24.  
  25.  
  26.  
  27.  
  28.   ' PART 3: Write the file back.
  29.  
  30.   If MsgBox("Write data back to the file?", vbYesNo) = vbYes Then
  31.     FileNo = FreeFile ' Get next available file number.
  32.     Open FileName For Binary Access Write Lock Write As #FileNo
  33.     ' The size of the Buffer determines how many bytes are written...
  34.     Put #FileNo, , Buffer() ' Grab the entire file's data into the array
  35.     Close #FileNo
  36.   End If
  37.  
  38. End Sub
Jul 13 '07 #2
kirubagari
158 New Member
Private Sub Command1_Click()

Open "a:\bonding.bin " For Binary As mHandle

Call ReWrite_File

End Sub

is it way to read the file and use that function
Jul 13 '07 #3
kirubagari
158 New Member
Expand|Select|Wrap|Line Numbers
  1. rich1.Text = rich1.Text & "Before : " & HexByte2Char(arrByte(I)) & " "
  2.            & HexByte2Char(arrByte(I + 1))" "& HexByte2Char(arrByte(I + 2));
  3.            " "& HexByte2Char(arrByte(I + 3))& " "& HexByte2Char(arrByte(I + 4))& " "&  HexByte2Char(arrByte(I + 5))
Jul 13 '07 #4
Killer42
8,435 Recognized Expert Expert
Expand|Select|Wrap|Line Numbers
  1. rich1.Text = rich1.Text & "Before : " & HexByte2Char(arrByte(I)) & " "
  2.            & HexByte2Char(arrByte(I + 1))" "& HexByte2Char(arrByte(I + 2));
  3.            " "& HexByte2Char(arrByte(I + 3))& " "& HexByte2Char(arrByte(I + 4))& " "&  HexByte2Char(arrByte(I + 5))
Yes, that looks about right. Try it, and see how it goes.

Of course, since this is actually spread over three lines, it would need continuation characters (_), but hopefully you're already familiar with splitting up lines like that.
Jul 13 '07 #5
Killer42
8,435 Recognized Expert Expert
Private Sub Command1_Click()

Open "a:\bonding.bin " For Binary As mHandle

Call ReWrite_File

End Sub

is it way to read the file and use that function
Well, I suppose it's a bit different if you already have the file open. Here's a modified copy of the routine which assumes the file is already open, and that you want to leave it that way. Note, I'm not sure it can be done, as you may need to use different options on the Open statement to open it for reading and writing. But you can try this (on an unimportant file, in case it stuffs up) and see what happens.

Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2.  
  3. Public Sub ReWrite_Open_File(ByVal FileNo As Long)
  4.   Dim FileSize As Long, Buffer() As Byte
  5.  
  6.   ' PART 1: Read the file.
  7.  
  8.   FileSize = LOF(FileNo) ' Determine how large the file is (in bytes).
  9.   ReDim Buffer(1 To FileSize) ' Set our buffer to that length.
  10.   Get #FileNo, 1, Buffer() ' Grab the entire file's data into the array
  11.  
  12.   ' PART 2
  13.   ' If you plan to change the data, this is where it would happen.
  14.   Beep
  15.  
  16.  
  17.   ' PART 3: Write the file back.
  18.  
  19.   If MsgBox("Write data back to the file?", vbYesNo) = vbYes Then
  20.     Put #FileNo, 1, Buffer() ' Write the data back to the file.
  21.   End If
  22. End Sub
You realise, I hope, that this routine doesn't actually do anything useful. It's just intended as a demonstration of techniques used in transferring information back and forth between a file and a byte array.
Jul 13 '07 #6

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

Similar topics

6
by: David Opstad | last post by:
I have a question about text rendering I'm hoping someone here can answer. Is there a way of doing linguistically correct rendering of Unicode strings in Python? In simple cases like Latin or...
0
by: Sarah Tegtmeier | last post by:
Hi I have a question about the correct use of the attribute xsi:schemaLocation. My programm has to process XML files where the value of this attribute causes some problems. The programm is...
1
by: Richard Golebiowski | last post by:
I have been trying to figure this out for quite some time and cannot find any examples in VB.Net or in VB that work correctly. I am working on an application where I want the user to be able to...
14
by: john.burton.email | last post by:
I've done some extensive searching and can't seem to find an answer to this - Is it correct to using "using" with templates, for example: using std::vector; Or do I need to specify the type...
6
by: Rob Thorpe | last post by:
Given the code:- r = sscanf (s, "%lf", x); What is the correct output if the string s is simply "-" ? If "-" is considered the beginning of a number, that has been cut-short then the...
5
by: blackg | last post by:
Input string not in correct format -------------------------------------------------------------------------------- I am trying to view a picture from a table. I am getting this error Input string...
2
by: thisis | last post by:
Hi All, I need the PUBS.mdb for pulling images: PUBS.mdb must have the table: pub_info tbl_pub_info : has 3 fields Data_Type : ok Data_Type : ok
0
by: sehguh | last post by:
Hiya Folks, I am Currently using windows xp. Also using Visual Web Developer 2005 and Microsoft Sql server 2005. The main page consists of an aspx page and a master page. The page also...
3
lee123
by: lee123 | last post by:
I have a problem getting the correct to count +1 every time I get an answer right and the incorrect is the same. I have two lbl's named number1 and number2 which produces a Rnd# in each lbl. ...
10
by: onetruelove | last post by:
I want to creat a post like this blog: http://onlinetoefltest.blogspot.com/2007/08/level-c-lesson-1.html When you chose all the answers and click show answer a msg box will appear and tells how...
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,...
1
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...
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,...
0
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...
0
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 ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.