473,806 Members | 2,525 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Flow control

Hello:

There are a series of textboxes (x.text, y.text, z.text etc.) in which user input is expected.
As:
dtmX=CDate(x.te xt)
dtmY=CDate(y.te xt)
dtmZ=CDate(z.te xt)

where x, y, and z.text must be in hh:mm format.

1. What is the best method for capturing hh:mm from a user? Ideally, I would like to use a control similar to the time input box in clock.exe, with the two up/down arrows that also uses the up/down keyboard keys, but without the seconds. What I don't want is the drop down calendar of the date timepicker with the single drop down arrow. How might that be accomplished?

2. I want the program to check for input errors (InvalidCastExc eption ex: input of 24 hours or more in the hours part) and return to the textbox for user correction if an exception is caught, but not to keep executing the program until that correction has been accomplished, and then to test the box again, and then continue execution if the input is acceptable.

Try
dtmX = CDate(x.Text)
Catch ic As InvalidCastExce ption
InputError()
Finally
txtX.Focus()
End Try

3. Using a Try/Catch/Finally the program will catch an input error in a textbox, but the program continues to execute beyond the subroutine, rather than returning to the textbox at position 1 and waiting for corrected input.

Should I use a do while or if loop or something similar to maintain flow control if I want the user to return to the box with the error for a user correction. Do I need a loop for each text box?

4. The Focus(), places the carat after the error instead at the beginning of the box (position 1). How do I get it to return to position 1, and return the box to the default condition prior to input?

5. Do I need to do a Try/Catch/Finally for each (of many) textboxes, or is there some simple way to iterate through them and stop only for an exception?
Thank You,
Dennis D.
--
http://www.dennisys.com/
Nov 21 '05 #1
10 1857
Dennis,
1. What is the best method for capturing hh:mm from a user?
You can use the DateTimePicker to enter the time values. To use a DateTime
picker to enter your times set the following properties:

Format = Custom
CustomFormat = "HH:mm" (for 24 hour:min)
ShowUpDown = True

2. I want the program to check for input errors
3...
4... I normally use the Validating event to check for valid input. The Validating
event is able to keep the cursor on the control in error. For a start on
using the Validating event see:

http://msdn.microsoft.com/library/de...ndowsForms.asp

5. Do I need to do a Try/Catch/Finally for each (of many) textboxes,
or is there some simple way to iterate through them and stop
only for an exception?


You can have a single Validating event handler handle many TextBoxes...

Hope this helps
Jay

"Dennis D." <te**@dennisys. com> wrote in message
news:OS******** ******@tk2msftn gp13.phx.gbl...
Hello:

There are a series of textboxes (x.text, y.text, z.text etc.) in which user
input is expected.
As:
dtmX=CDate(x.te xt)
dtmY=CDate(y.te xt)
dtmZ=CDate(z.te xt)

where x, y, and z.text must be in hh:mm format.

1. What is the best method for capturing hh:mm from a user? Ideally, I would
like to use a control similar to the time input box in clock.exe, with the
two up/down arrows that also uses the up/down keyboard keys, but without the
seconds. What I don't want is the drop down calendar of the date timepicker
with the single drop down arrow. How might that be accomplished?

2. I want the program to check for input errors (InvalidCastExc eption ex:
input of 24 hours or more in the hours part) and return to the textbox for
user correction if an exception is caught, but not to keep executing the
program until that correction has been accomplished, and then to test the
box again, and then continue execution if the input is acceptable.

Try
dtmX = CDate(x.Text)
Catch ic As InvalidCastExce ption
InputError()
Finally
txtX.Focus()
End Try

3. Using a Try/Catch/Finally the program will catch an input error in a
textbox, but the program continues to execute beyond the subroutine, rather
than returning to the textbox at position 1 and waiting for corrected input.

Should I use a do while or if loop or something similar to maintain flow
control if I want the user to return to the box with the error for a user
correction. Do I need a loop for each text box?

4. The Focus(), places the carat after the error instead at the beginning of
the box (position 1). How do I get it to return to position 1, and return
the box to the default condition prior to input?

5. Do I need to do a Try/Catch/Finally for each (of many) textboxes, or is
there some simple way to iterate through them and stop only for an
exception?
Thank You,
Dennis D.
--
http://www.dennisys.com/
Nov 21 '05 #2
Dennis,

All your answers on your questions are in it, although I did not take the solution you was proposing

I made it for your solution so you should try it. The sequence from the "if" is special done in that way. The Isdate acts as a mini trycatch block so the first time it is slow.

\\\
If x.Text.Length <> 5 _
OrElse x.Text.Substrin g(2, 1) <> ":" _
OrElse Not IsDate(x.Text) Then
MessageBox.Show ("the date is wrong")
x.Focus()
x.SelectionLeng th = 0
x.SelectionStar t = 0
Else
Dim dtmX As DateTime = CDate(x.Text)
End If
///

I hope this helps?

Cor
Nov 21 '05 #3

"Dennis D." <te**@dennisys. com> wrote

There are a series of textboxes (x.text, y.text, z.text etc.) in which user input is expected.
As:
dtmX=CDate(x.te xt)
dtmY=CDate(y.te xt)
dtmZ=CDate(z.te xt)

where x, y, and z.text must be in hh:mm format.
1. What is the best method for capturing hh:mm from a user?
Create a class that inherits from Textbox, and give it the functionality you need,
then use those in place of the original textboxes.
2. I want the program to check for input errors
I'd look into the validating event to handle validation....

3. Using a Try/Catch/Finally the program will catch an input error in a textbox,
Don't use a Try/Catch block for something you can easily test for. Try/Catch
is expensive, If/Then is not.
4. The Focus(), places the carat after the error instead at the beginning of the box (position 1). How do I get it to return to position 1, and return the box to the default condition prior to input?

Maybe you could just hide the caret and use judical use of highlighting
to indicate which part will be effected.
5. Do I need to do a Try/Catch/Finally for each (of many) textboxes,


Once you have that inherited control working, you can use it in
multiple places.

LFS

Nov 21 '05 #4
How "expensive is Try/Catch". I don't use it when I can use the If/then but
there are a lot of cases where I want to catch various types of errors.

"Larry Serflaten" wrote:

"Dennis D." <te**@dennisys. com> wrote

There are a series of textboxes (x.text, y.text, z.text etc.) in which user input is expected.
As:
dtmX=CDate(x.te xt)
dtmY=CDate(y.te xt)
dtmZ=CDate(z.te xt)

where x, y, and z.text must be in hh:mm format.
1. What is the best method for capturing hh:mm from a user?


Create a class that inherits from Textbox, and give it the functionality you need,
then use those in place of the original textboxes.
2. I want the program to check for input errors


I'd look into the validating event to handle validation....

3. Using a Try/Catch/Finally the program will catch an input error in a textbox,


Don't use a Try/Catch block for something you can easily test for. Try/Catch
is expensive, If/Then is not.
4. The Focus(), places the carat after the error instead at the beginning of the box (position 1). How do I get it to return

to position 1, and return the box to the default condition prior to input?

Maybe you could just hide the caret and use judical use of highlighting
to indicate which part will be effected.
5. Do I need to do a Try/Catch/Finally for each (of many) textboxes,


Once you have that inherited control working, you can use it in
multiple places.

LFS

Nov 21 '05 #5


"Larry Serflaten" wrote:

"Dennis D." <te**@dennisys. com> wrote

There are a series of textboxes (x.text, y.text, z.text etc.) in which user input is expected.
As:
dtmX=CDate(x.te xt)
dtmY=CDate(y.te xt)
dtmZ=CDate(z.te xt)

where x, y, and z.text must be in hh:mm format.
1. What is the best method for capturing hh:mm from a user?


Create a class that inherits from Textbox, and give it the functionality you need,
then use those in place of the original textboxes.
2. I want the program to check for input errors


I'd look into the validating event to handle validation....

3. Using a Try/Catch/Finally the program will catch an input error in a textbox,


Don't use a Try/Catch block for something you can easily test for. Try/Catch
is expensive, If/Then is not.
4. The Focus(), places the carat after the error instead at the beginning of the box (position 1). How do I get it to return

to position 1, and return the box to the default condition prior to input?

Maybe you could just hide the caret and use judical use of highlighting
to indicate which part will be effected.
5. Do I need to do a Try/Catch/Finally for each (of many) textboxes,


Once you have that inherited control working, you can use it in
multiple places.

LFS

Nov 21 '05 #6

"Dennis" <De****@discuss ions.microsoft. com> wrote
How "expensive is Try/Catch". I don't use it when I can use the If/then but
there are a lot of cases where I want to catch various types of errors.


That sounds OK, but you indicated that you would be using it to respond to
bad user input. I'd consider that routine type use that should avoid throwing and
catching exceptions. YMMV. Perhaps this will shed some light on the subject:

http://msdn.microsoft.com/library/de...Exceptions.asp

HTH
LFS
Nov 21 '05 #7
Larry,

Although I as well try to avoid the try and catch is there AFAIK an effect.
Only the first exception is slow.

By the way, that page you show is rare. The text is almost right however the
showed samples are wrong they don't show the finally.

And as I wrote in my sample answer, probably is the "IsDate" a mini Try
Catch block so sometimes there is no advantage at all avoiding that Try
Catch.

However I keep it there where it can by avoiding the Try and Catch and am
using the If because that gives direct control over the conditions I want to
test.

Just a little perception of mine in addition to your message.

Cor

"Larry Serflaten" <se*******@usin ternet.com>


"Dennis" <De****@discuss ions.microsoft. com> wrote
How "expensive is Try/Catch". I don't use it when I can use the If/then
but
there are a lot of cases where I want to catch various types of errors.


That sounds OK, but you indicated that you would be using it to respond to
bad user input. I'd consider that routine type use that should avoid
throwing and
catching exceptions. YMMV. Perhaps this will shed some light on the
subject:

http://msdn.microsoft.com/library/de...Exceptions.asp

HTH
LFS

Nov 21 '05 #8
"Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> wrote in message news:OV******** ******@TK2MSFTN GP11.phx.gbl...
Dennis,
1. What is the best method for capturing hh:mm from a user?


You can use the DateTimePicker to enter the time values. To use a DateTime
picker to enter your times set the following properties:

Format = Custom
CustomFormat = "HH:mm" (for 24 hour:min)
ShowUpDown = True


I am trying to capture a timespan, such as 00:15 for a 15 minute timespan. The Date TimePicker unfortunately does not allow 00 in the hours position, or it would be perfect.

In many applications, you can set an input filter: Phone: (nnn) nnn - nnnn where the ( ) and the - are not writable.
The input to the user looks something like (xxx) xxx - xxxx

In this case I want to use a textbox to get a string nn : nn where n is a numeric characters and the : colon is not writable.

To supply an hours format, I would like the first character to increment from 0 to 2, and the second character to increment from 0 to 9, but for the combination not to exceed 24, using the arrow keys on the keyboard, with the option to simply type in the numbers. To me this implies character level manipulation, and some keyboard translations, all of which are fairly advanced for a vb novice. I'm still learning about character and string manipulation in Visual Basic.

Is it possible to set an input filter in a textbox in visual basic, or do I need to use two textboxes to capture nn : nn?


Thank You,
Dennis D.
--
http://www.dennisys.com/
Nov 21 '05 #9
Dennis,
Please disable HTML formatting in your News Reader!
I am trying to capture a timespan, such as 00:15 for a 15 minute timespan.
The Date TimePicker unfortunately does not allow 00 in the hours position,
When you use CustomFormat = "HH:mm" the DateTimePicker allows 00 in the
hours! At least in VS.NET 2003 (.NET 1.1) it does!

Note the upper case HH & the lower case mm!

To get or set the "Time" value I normally use something like:

Public Property Time() As TimeSpan
Get
Return Me.DateTimePick er1.Value.TimeO fDay
End Get
Set(ByVal value As TimeSpan)
Me.DateTimePick er1.Value = Me.DateTimePick er1.MinDate.Add (value)
End Set
End Property

Optionally you could try:
Return
Me.DateTimePick er1.Value.Subtr act(Me.DateTime Picker1.MinDate )

For Time.Get to allow entry of "Days" also...
Are you using VS.NET 2002 or VS.NET 2005? If you are using VS.NET 2002, then
I strongly recommend you upgrade. If you are using VS.NET 2005, then I would
strongly recommend you report the bug.
In many applications, you can set an input filter:
Phone: (nnn) nnn - nnnn where the ( ) and the - are not writable.
The input to the user looks something like (xxx) xxx - xxxx I understand you will need to wait for VS.NET 2005 for the masked edit
control. VS.NET 2005 (aka Whidbey, due out later in 2005) is currently in
beta, for details see:
http://lab.msdn.microsoft.com/vs2005/

Hope this helps
Jay
"Dennis D." <te**@dennisys. com> wrote in message
news:Ox******** ******@TK2MSFTN GP09.phx.gbl...
"Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> wrote in message
news:OV******** ******@TK2MSFTN GP11.phx.gbl... Dennis,
1. What is the best method for capturing hh:mm from a user?


You can use the DateTimePicker to enter the time values. To use a DateTime
picker to enter your times set the following properties:

Format = Custom
CustomFormat = "HH:mm" (for 24 hour:min)
ShowUpDown = True


I am trying to capture a timespan, such as 00:15 for a 15 minute timespan.
The Date TimePicker unfortunately does not allow 00 in the hours position,
or it would be perfect.

In many applications, you can set an input filter: Phone: (nnn) nnn - nnnn
where the ( ) and the - are not writable.
The input to the user looks something like (xxx) xxx - xxxx

In this case I want to use a textbox to get a string nn : nn where n is a
numeric characters and the : colon is not writable.

To supply an hours format, I would like the first character to increment
from 0 to 2, and the second character to increment from 0 to 9, but for the
combination not to exceed 24, using the arrow keys on the keyboard, with the
option to simply type in the numbers. To me this implies character level
manipulation, and some keyboard translations, all of which are fairly
advanced for a vb novice. I'm still learning about character and string
manipulation in Visual Basic.

Is it possible to set an input filter in a textbox in visual basic, or do I
need to use two textboxes to capture nn : nn?
Thank You,
Dennis D.
--
http://www.dennisys.com/
Nov 21 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2860
by: David Chan | last post by:
Hi, I'm trying to use python to create GUI wizards, i.e. sequences of dialog boxes with <BACK and NEXT> buttons. Since I want to re-use some of the dialog boxes in different wizards, I want to have a main function which calls each dialog box, much like this: def select_item(): """runs GUI wizard to select item"""
11
7248
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 dynamic, it comes from a database. My question -- with CSS (because with HTML tables I don't think it's possible) how can I make my text "flow" in two columns? eg. If there are 100 lines of content, I would like 50 to be in the 1st column, and...
5
3812
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 close to the point of origination. I'm trying to decide whether to refactor... What is the cost of throwing an exception in the CLR - relative to, say, a conditional statement? Are we taking talking 1+ orders of magnitude? Is there...
9
1765
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 improved code readability and performance. Consider an application that must eliminate duplicates in a list. using system.collections;
7
2549
by: Dave | last post by:
Hi, I've read a few contradictory statements on how to do flow control between methods. Main problem is that I've seen recommendations (or "standards") to *not* use exceptions for flow control, but also that exceptions now replace the need to pass return codes between methods. So whats best to use? Thanks.
17
2727
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 know nothing about ASP. He can build the design of the pages in HTML with tables, labels, textboxes etc. But then I would need to change them to ASP.net objects and write the code to make the page work (normally I do this as I go - can't do this...
4
1986
by: VB Programmer | last post by:
I have user controls that I'm going to place on the form. There could be from 0 - 20. I want the user to be able to resize the window and have the controls relocate automatically, but like FLOW LAYOUT in ASP.NET. Any idea how I can do this in VB.NET 2005, the latest version? Thanks!
15
1660
by: c676228 | last post by:
Hi all, In traditional asp form, there is an action field in a form, any time the page is valid, after click the submit button, the next page comes up based on the value in the action field. In asp.net, in the sumit_click sub, after validating the all the fields in a form, do you always use response.redirect or reponse.transfer to go to the next page, any other ways? what's the exactly difference or which one will be better? -- Betty
2
5022
by: brianlum | last post by:
Hi, I have been looking for a good way to convert python code into a control flow graph. I know of Python functions that will convert an expression into an abstract syntax tree (i.e. ast = parser.expr('(x+5)*5') then t = ast.totuple() then t), but I am not sure how to obtain a CFG. I've gone through the compiler and it has code that converts the AST
3
2607
by: Lowrider | last post by:
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...
0
9719
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9597
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10372
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10110
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9187
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5546
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5682
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4329
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 we have to send another system
3
3008
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.