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

Flow control does not stop after clicking OK in message box

I'm new to the VB programming world and am having a problem with flow control. In the code below I check 3 textboxes and display a messagebox if one or more are left blank. The problem lies in that I don't know how to stop the program flow after the user clicks the OK button on the message box. The program continues to run. I know that I am missing some piece of code to halt the flow. Thank you for any help with this problem. My email is <Removed by Moderator>

Expand|Select|Wrap|Line Numbers
  1. Dim test1 As Decimal  
  2.         Dim test2 As Decimal
  3.         Dim test3 As Decimal
  4.         test1 = xtboxNum1.Text.Length
  5.         test2 = xtboxNum2.Text.Length
  6.         test3 = xtboxNum3.Text.Length
  7.         If test1.Equals(0) Or test2.Equals(0) Or test3.Equals(0) Then
  8.                 MessageBox.Show("One or more numbers are not filled in!") 
  9.         End If
  10. End Sub
Nov 26 '07 #1
3 2585
Dököll
2,364 Expert 2GB
I'm new to the VB programming world and am having a problem with flow control. In the code below I check 3 textboxes and display a messagebox if one or more are left blank. The problem lies in that I don't know how to stop the program flow after the user clicks the OK button on the message box. The program continues to run. I know that I am missing some piece of code to halt the flow. Thank you for any help with this problem. My email is <Removed by Moderator>
Expand|Select|Wrap|Line Numbers
  1. Dim test1 As Decimal  
  2.         Dim test2 As Decimal
  3.         Dim test3 As Decimal
  4.         test1 = xtboxNum1.Text.Length
  5.         test2 = xtboxNum2.Text.Length
  6.         test3 = xtboxNum3.Text.Length
  7.         If test1.Equals(0) Or test2.Equals(0) Or test3.Equals(0) Then
  8.                 MessageBox.Show("One or more numbers are not filled in!") 
  9.         End If
  10. End Sub
Hello Lowrider!

Is this all of the code? It sounds like you should be able to stop the program once you click okay button. Does the program get fired with click of a button?

Expand|Select|Wrap|Line Numbers
  1. Unload Me
  2. YourForm.Show
  3.  
should bring you back to the button, if that's the case.

In a bit!

Dököll
Nov 26 '07 #2
Hello Lowrider!

Is this all of the code? It sounds like you should be able to stop the program once you click okay button. Does the program get fired with click of a button?
Expand|Select|Wrap|Line Numbers
  1. Unload Me
  2. YourForm.Show
  3.  
should bring you back to the button, if that's the case.
In a bit!
Dököll

Dököll, all the code is listed below. Yes a button click starts Private Sub xbutGetMax which calls Private Sub TestForNumbers(). I am trying to test each textbox for content and if an empty textbox is found the message box is displayed. At this point the user clicks OK and I want the program to stop, halt, pause, etc. while the user inputs the number in the empty textbox. The user then clicks the button Private Sub xbutGetMax again and the and the procedure begins again. Does this make sense? Can you help?



Expand|Select|Wrap|Line Numbers
  1. Public Class Form1
  2.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  3.     End Sub
  4.  
  5.        Private Sub TestForNumbers()
  6.         Dim test1 As Integer                 
  7.         Dim test2 As Integer
  8.         Dim test3 As Integer
  9.         test1 = xtboxNum1.Text.Length       
  10.         test2 = xtboxNum2.Text.Length
  11.         test3 = xtboxNum3.Text.Length
  12.         If test1.Equals(0) Or test2.Equals(0) Or test3.Equals(0) Then
  13.             MessageBox.Show("One or more numbers are not filled in!")
  14.             Me.Show()
  15.         End If
  16.     End Sub
  17.  
  18.     Private Function GetMax(ByVal num1 As String, ByVal num2 As String, ByVal num3 As String) As String
  19.  
  20.         Decimal.TryParse(Me.xtboxNum1.Text, num1)
  21.         Decimal.TryParse(Me.xtboxNum2.Text, num2)
  22.         Decimal.TryParse(Me.xtboxNum3.Text, num3)
  23.         Dim arrayNumbers() As Decimal = {num1, num2, num3}
  24.         Dim max As Decimal = arrayNumbers(0)
  25.         For number As Integer = 1 To arrayNumbers.Length - 1  
  26.             If arrayNumbers(number) > max Then
  27.                 max = arrayNumbers(number)
  28.             End If
  29.         Next number
  30.         Return max                                             
  31.     End Function
  32.  
  33.     Private Sub xbutGetMax_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles xbutGetMax.Click
  34.  
  35.         Call TestForNumbers()                              
  36.         Dim max1 As Decimal                                
  37.         Dim num1 As String = Me.xtboxNum1.Text
  38.         Dim num2 As String = Me.xtboxNum2.Text
  39.         Dim num3 As String = Me.xtboxNum3.Text
  40.         max1 = GetMax(CDec(num1), CDec(num2), CDec num3))                       
  41.         Me.xlabMax.Text = "The largest number is " & max1 & "" 
  42.  
  43.     End Sub 
Nov 26 '07 #3
Killer42
8,435 Expert 8TB
I'd suggest you change TestForNumbers from a Sub to a Function. Have it return True for OK, and False for not OK. Then your code can say something like...

Expand|Select|Wrap|Line Numbers
  1. If TestForNumbers() Then
  2.   ' Do the GetMax stuff.
  3. End If
Nov 26 '07 #4

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

Similar topics

8
by: C. Alexander | last post by:
Im running a small server that seems to work fine outside the IDE as an exe, but within the IDE, when I run the program for the first time, i can start/stop the host many times. But I end the...
11
by: Robert Bowen | last post by:
Hello all. I have been given mock-ups (in static HTML) of some pages for a site I am working on. The client would like these pages to look exactly as they do now. The problem is that the content is...
5
by: Miyra | last post by:
Hi. I'm working with an app that uses exceptions for control flow. These are code blocks where exceptions are thrown/caught regularly. A couple hundred exceptions occur per hour and they're caught...
9
by: Alvin Bruney [MVP] | last post by:
Exceptions must not be used to control program flow. I intend to show that this statement is flawed. In some instances, exceptions may be used to control program flow in ways that can lead to...
17
by: tshad | last post by:
Many (if not most) have said that code-behind is best if working in teams - which does seem logical. How do you deal with the flow of the work? I have someone who is good at designing, but...
5
by: Charles Law | last post by:
Sorry for reposting this question, but I did not get a single answer last time, and I'm sure you guys must have some thoughts on the matter. I have a user control which can be dragged and dropped...
10
by: Dennis D. | last post by:
Hello: There are a series of textboxes (x.text, y.text, z.text etc.) in which user input is expected. As: dtmX=CDate(x.text) dtmY=CDate(y.text) dtmZ=CDate(z.text) where x, y, and z.text...
7
by: Siv | last post by:
Hi, I have an MDI application that uses a generic "ShowPage" routine in a module that is called when I want to display a child form. The basic idea is that in the module I have declared each form...
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...
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...
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
isladogs
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 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.