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 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 (InvalidCastException 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 InvalidCastException
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/ 10 1816
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**************@tk2msftngp13.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.text)
dtmY=CDate(y.text)
dtmZ=CDate(z.text)
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 (InvalidCastException 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 InvalidCastException
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/
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.Substring(2, 1) <> ":" _
OrElse Not IsDate(x.Text) Then
MessageBox.Show("the date is wrong")
x.Focus()
x.SelectionLength = 0
x.SelectionStart = 0
Else
Dim dtmX As DateTime = CDate(x.Text)
End If
///
I hope this helps?
Cor
"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.text)
dtmY=CDate(y.text)
dtmZ=CDate(z.text)
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
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.text) dtmY=CDate(y.text) dtmZ=CDate(z.text)
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
"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.text) dtmY=CDate(y.text) dtmZ=CDate(z.text)
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
"Dennis" <De****@discussions.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
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*******@usinternet.com> "Dennis" <De****@discussions.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
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message news:OV**************@TK2MSFTNGP11.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/
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.DateTimePicker1.Value.TimeOfDay
End Get
Set(ByVal value As TimeSpan)
Me.DateTimePicker1.Value = Me.DateTimePicker1.MinDate.Add(value)
End Set
End Property
Optionally you could try:
Return
Me.DateTimePicker1.Value.Subtract(Me.DateTimePicke r1.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**************@TK2MSFTNGP09.phx.gbl...
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:OV**************@TK2MSFTNGP11.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/
Please disable HTML formatting in your News Reader!
- Done When you use CustomFormat = "HH:mm" the DateTimePicker allows 00 in the hours! At least in VS.NET 2003 (.NET 1.1) it does!
I noticed the difference between HH and hh, forgot the meaning, and ignored
it.
I learned lazy is not good practice.
- Are you using VS.NET 2002 or VS.NET 2005?
Using 2002 that came with VB.NET. I'll take a look at the beta.
- the masked edit control
With the Maxwell Smart voice, "Ah, yes, the Masked Edit Control!"
Can almost hear him saying it can't you? How does the brain do that?
Now there's an intelligence tool for the CIA to drool over. Real time voice
translation.
-
But it begs the question: Shouldn't VB.Net+VS.Net be able to create the
masked edit control solution?
Same with DateTimePicker. The source for the control is in VS.Net or not?
- A few replies down Larry said: "Create a class that inherits from Textbox, and give it the functionality you need,
then use those in place of the original textboxes."
-
There's a programming challenge for me. I'm reading this about stuff, but
there is nothing like actually doing the coding to help the learning
process. Hence, the project.
Thanks Jay B. Harlow,
and thanks Larry Serflaten,
I'm on the case!
Dennis D.
-- http://www.dennisys.com/ This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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: 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,...
|
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: 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...
|
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...
|
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 =...
|
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...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
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: 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...
|
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...
| |