473,394 Members | 2,063 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,394 software developers and data experts.

Is it correct ?

kirubagari
158 100+
Expand|Select|Wrap|Line Numbers
  1. Private Sub stop_Click()
  2.  
  3. UserWantsOut = True
  4. End If
Is it the correct way of stoping the process in the middle?

I put a new module and put this public function inside that.

Public UserWantsOut As Boolean



then I put the aborted by user and finished statement in the after next statement, is it correct?

Expand|Select|Wrap|Line Numbers
  1. For i = 49 To 5500 Step 6
  2.  
  3.   rich1.SelStart = Len(rich1.Text)
  4.  
  5.   rich1.SelText = "Before : " & HexByte2Char(arrByte(i)) & _
  6.       " " & HexByte2Char(arrByte(i + 1)) & " " _
  7.       & HexByte2Char(arrByte(i + 2)) & " " _
  8.       & HexByte2Char(arrByte(i + 3)) & " " _
  9.       & HexByte2Char(arrByte(i + 4)) & " " _
  10.       & HexByte2Char(arrByte(i + 5)) _
  11.       & vbNewLine
  12.  
  13.   If arrByte(i) <> a Then
  14.     arrByte(i) = a
  15.     changeMade = True
  16.   End If
  17.  
  18.   If arrByte(i + 1) <> b Then
  19.     arrByte(i + 1) = b
  20.     changeMade = True
  21.   End If
  22.   If changeMade Then
  23.     AnyChanged = True
  24.     rich1.SelText = "After : " & HexByte2Char(arrByte(i)) & _
  25.         " " & HexByte2Char(arrByte(i + 1)) & " " _
  26.         & HexByte2Char(arrByte(i + 2)) & " " _
  27.         & HexByte2Char(arrByte(i + 3)) & " " _
  28.         & HexByte2Char(arrByte(i + 4)) & " " _
  29.         & HexByte2Char(arrByte(i + 5)) _
  30.         & " <--- Corrected" _
  31.         & vbNewLine
  32.  
  33.   End If
  34.  
  35. Next
  36.  
  37.  
  38.  
  39. If UserWantsOut Then
  40.   MsgBox "Aborted by user!"
  41. Else
  42.   MsgBox "Finished!"
  43. End If
  44.  
  45.  
  46. End If
  47.  
  48. End Sub
Jul 23 '07 #1
1 966
Killer42
8,435 Expert 8TB
...Is it the correct way of stoping the process in the middle? ...
I'd say you're getting very close. Just a couple of points...
  • UserWantsOut is the name of a variable, not a function.
  • You haven't put in the code to exit from the FOR loop if UserWantsOut is set to True.
  • Maybe just incomplete copy/paste to the message here, but you appear to have an extra End If just before the End Sub.



Just on a side note (nothing to do with getting this to work), you can make use of functions to make your code more compact and easier to read. For example, in this case I would create a function to return a string showing the specified number of bytes from the array, formatted the way you want, starting at the specified position in the array.

For example...
Expand|Select|Wrap|Line Numbers
  1. Public Function FormattedBytes(ByVal StartingPoint As Long, ByVal HowMany As Long) As String
  2.   Dim I As Long
  3.   For I = StartingPoint To StartingPoint + HowMany - 1
  4.     If I > StartingPoint Then
  5.       FormattedBytes = FormattedBytes & " " ' Insert spaces between entries.
  6.     End If
  7.     FormattedBytes = FormattedBytes & _
  8.         HexByte2Char(arrByte(I))
  9.   Next
  10. End Function
That way, in your code you can do something like this...
Expand|Select|Wrap|Line Numbers
  1. rich1.SelText = "After : " & FormattedBytes(i, 6) & " <--- Corrected" & vbNewLine
instead of...
Expand|Select|Wrap|Line Numbers
  1. rich1.SelText = "After : " & HexByte2Char(arrByte(i)) & _
  2.     " " & HexByte2Char(arrByte(i + 1)) _
  3.     " " & HexByte2Char(arrByte(i + 2)) _
  4.     " " & HexByte2Char(arrByte(i + 3)) _
  5.     " " & HexByte2Char(arrByte(i + 4)) _
  6.     " " & HexByte2Char(arrByte(i + 5)) _
  7.     & " <--- Corrected" _
  8.     & vbNewLine
Same functionality, much less code. This is what makes VB (and other programming languages) so great. You can extend it with your own functions and commands.

(Note though, for this to work you would need to make the array arrByte public, just like the UserWantsOut variable. So you might want to leave this in the "possible enhancements to consider later" basket.)
Jul 23 '07 #2

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
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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
jinu1996
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...

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.