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> - Dim test1 As Decimal
-
Dim test2 As Decimal
-
Dim test3 As Decimal
-
test1 = xtboxNum1.Text.Length
-
test2 = xtboxNum2.Text.Length
-
test3 = xtboxNum3.Text.Length
-
If test1.Equals(0) Or test2.Equals(0) Or test3.Equals(0) Then
-
MessageBox.Show("One or more numbers are not filled in!")
-
End If
-
End Sub
3 2585
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> -
Dim test1 As Decimal
-
Dim test2 As Decimal
-
Dim test3 As Decimal
-
test1 = xtboxNum1.Text.Length
-
test2 = xtboxNum2.Text.Length
-
test3 = xtboxNum3.Text.Length
-
If test1.Equals(0) Or test2.Equals(0) Or test3.Equals(0) Then
-
MessageBox.Show("One or more numbers are not filled in!")
-
End If
-
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?
should bring you back to the button, if that's the case.
In a bit!
Dököll
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?
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? -
Public Class Form1
-
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
-
End Sub
-
-
Private Sub TestForNumbers()
-
Dim test1 As Integer
-
Dim test2 As Integer
-
Dim test3 As Integer
-
test1 = xtboxNum1.Text.Length
-
test2 = xtboxNum2.Text.Length
-
test3 = xtboxNum3.Text.Length
-
If test1.Equals(0) Or test2.Equals(0) Or test3.Equals(0) Then
-
MessageBox.Show("One or more numbers are not filled in!")
-
Me.Show()
-
End If
-
End Sub
-
-
Private Function GetMax(ByVal num1 As String, ByVal num2 As String, ByVal num3 As String) As String
-
-
Decimal.TryParse(Me.xtboxNum1.Text, num1)
-
Decimal.TryParse(Me.xtboxNum2.Text, num2)
-
Decimal.TryParse(Me.xtboxNum3.Text, num3)
-
Dim arrayNumbers() As Decimal = {num1, num2, num3}
-
Dim max As Decimal = arrayNumbers(0)
-
For number As Integer = 1 To arrayNumbers.Length - 1
-
If arrayNumbers(number) > max Then
-
max = arrayNumbers(number)
-
End If
-
Next number
-
Return max
-
End Function
-
-
Private Sub xbutGetMax_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles xbutGetMax.Click
-
-
Call TestForNumbers()
-
Dim max1 As Decimal
-
Dim num1 As String = Me.xtboxNum1.Text
-
Dim num2 As String = Me.xtboxNum2.Text
-
Dim num3 As String = Me.xtboxNum3.Text
-
max1 = GetMax(CDec(num1), CDec(num2), CDec num3))
-
Me.xlabMax.Text = "The largest number is " & max1 & ""
-
-
End Sub
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... - If TestForNumbers() Then
-
' Do the GetMax stuff.
-
End If
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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
|
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...
|
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: 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: 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,...
|
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: 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...
| |