473,399 Members | 3,038 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,399 software developers and data experts.

focus with the text selected

I have this program that you enter a year in the text box and it returns
either a true or false in the picture box based on if it is a leap year or
not. The program works fine but I need to return focus to the text box with
the old text selected. Any answers on how to do this. My code is below.

Thanks,
Kelsey

Private Sub Command1_Click()

If IsNumeric(txtInput.Text) Then
If IsLeapYear(txtInput.Text) Then
picOutput.Cls
picOutput.Print "True"

Else
picOutput.Cls
picOutput.Print "False"

End If
Else
MsgBox ("Enter in a Year")
picOutput.Cls
txtInput.Text = " "
End If
End Sub

Private Sub Command2_Click()
End
End Sub

Here is the module--

Public Function IsLeapYear(Yr As Integer) As Boolean
IsLeapYear = False

If Yr Mod 4 = 0 Then
IsLeapYear = True
If Yr Mod 100 = 0 Then
If (Yr Mod 400) Then IsLeapYear = False
End If
End If
End Function
Jul 17 '05 #1
5 5979
in the gotfocus event of the textbox, put:

with txtInput
.selstart = 0
.sellength = len(.text)
end with

.... then just place a

txtInput.SetFocus

.... in the appropriate point in the code.

--

Randy Birch
MVP Visual Basic
http://www.mvps.org/vbnet/
Please respond only to the newsgroups so all can benefit.
"Randi" <RS******@stny.rr.com> wrote in message
news:gg*******************@twister.nyroc.rr.com...
: I have this program that you enter a year in the text box and it returns
: either a true or false in the picture box based on if it is a leap year or
: not. The program works fine but I need to return focus to the text box
with
: the old text selected. Any answers on how to do this. My code is below.
:
: Thanks,
: Kelsey
:
: Private Sub Command1_Click()
:
: If IsNumeric(txtInput.Text) Then
: If IsLeapYear(txtInput.Text) Then
: picOutput.Cls
: picOutput.Print "True"
:
: Else
: picOutput.Cls
: picOutput.Print "False"
:
: End If
: Else
: MsgBox ("Enter in a Year")
: picOutput.Cls
: txtInput.Text = " "
: End If
: End Sub
:
: Private Sub Command2_Click()
: End
: End Sub
:
: Here is the module--
:
: Public Function IsLeapYear(Yr As Integer) As Boolean
: IsLeapYear = False
:
: If Yr Mod 4 = 0 Then
: IsLeapYear = True
: If Yr Mod 100 = 0 Then
: If (Yr Mod 400) Then IsLeapYear = False
: End If
: End If
: End Function
:
:
Jul 17 '05 #2
Randy,
Thank You, Thank You....

Kelsey

"Randy Birch" <rg************@mvps.org> wrote in message
news:9u****************@news04.bloor.is.net.cable. rogers.com...
in the gotfocus event of the textbox, put:

with txtInput
.selstart = 0
.sellength = len(.text)
end with

... then just place a

txtInput.SetFocus

... in the appropriate point in the code.

--

Randy Birch
MVP Visual Basic
http://www.mvps.org/vbnet/
Please respond only to the newsgroups so all can benefit.
"Randi" <RS******@stny.rr.com> wrote in message
news:gg*******************@twister.nyroc.rr.com...
: I have this program that you enter a year in the text box and it returns
: either a true or false in the picture box based on if it is a leap year or : not. The program works fine but I need to return focus to the text box
with
: the old text selected. Any answers on how to do this. My code is below. :
: Thanks,
: Kelsey
:
: Private Sub Command1_Click()
:
: If IsNumeric(txtInput.Text) Then
: If IsLeapYear(txtInput.Text) Then
: picOutput.Cls
: picOutput.Print "True"
:
: Else
: picOutput.Cls
: picOutput.Print "False"
:
: End If
: Else
: MsgBox ("Enter in a Year")
: picOutput.Cls
: txtInput.Text = " "
: End If
: End Sub
:
: Private Sub Command2_Click()
: End
: End Sub
:
: Here is the module--
:
: Public Function IsLeapYear(Yr As Integer) As Boolean
: IsLeapYear = False
:
: If Yr Mod 4 = 0 Then
: IsLeapYear = True
: If Yr Mod 100 = 0 Then
: If (Yr Mod 400) Then IsLeapYear = False
: End If
: End If
: End Function
:
:

Jul 17 '05 #3
"Randi" <RS******@stny.rr.com> wrote in message news:<gg*******************@twister.nyroc.rr.com>. ..
I have this program.. if it is a leap year or
not. Here is the module--

Public Function IsLeapYear(Yr As Integer) As Boolean
IsLeapYear = False

If Yr Mod 4 = 0 Then
IsLeapYear = True
If Yr Mod 100 = 0 Then
If (Yr Mod 400) Then IsLeapYear = False
End If
End If
End Function


I think you are missing an "else" in there somewhere..
I'd rather be playing backgammon..
http://anzwers.org/free/3dfibs

3dfibster
Jul 17 '05 #4
No, that works.

--

Randy Birch
MVP Visual Basic
http://www.mvps.org/vbnet/
Please respond only to the newsgroups so all can benefit.
"3dfibster" <3d****@excite.com> wrote in message
news:27************************@posting.google.com ...
: "Randi" <RS******@stny.rr.com> wrote in message
news:<gg*******************@twister.nyroc.rr.com>. ..
: > I have this program.. if it is a leap year or
: > not.
:
: > Here is the module--
: >
: > Public Function IsLeapYear(Yr As Integer) As Boolean
: > IsLeapYear = False
: >
: > If Yr Mod 4 = 0 Then
: > IsLeapYear = True
: > If Yr Mod 100 = 0 Then
: > If (Yr Mod 400) Then IsLeapYear = False
: > End If
: > End If
: > End Function
:
: I think you are missing an "else" in there somewhere..
:
:
: I'd rather be playing backgammon..
: http://anzwers.org/free/3dfibs
:
: 3dfibster
Jul 17 '05 #5
"3dfibster" <3d****@excite.com> wrote in message <news:27************************@posting.google.co m>...
"Randi" <RS******@stny.rr.com> wrote in message news:<gg*******************@twister.nyroc.rr.com>. ..

Public Function IsLeapYear(Yr As Integer) As Boolean
IsLeapYear = False

If Yr Mod 4 = 0 Then
IsLeapYear = True
If Yr Mod 100 = 0 Then
If (Yr Mod 400) Then IsLeapYear = False
End If
End If
End Function


I think you are missing an "else" in there somewhere..


Actually, it's fine. I'd want to rewrite it, though:

Public Function IsLeapYear(ByVal Yr As Integer) As Boolean
IsLeapYear = (Day(DateSerial(Yr, 3, 0)) = 29)
End Function

Alternatively, assuming the current rules will never change:

Public Function IsLeapYear(ByVal Yr As Integer) As Boolean
Debug.Assert Yr >= 100 And Yr <= 9999

If Yr Mod 4 > 0 Then
IsLeapYear = False

ElseIf Yr Mod 100 > 0 Then
IsLeapYear = True

ElseIf Yr Mod 400 > 0 Then
IsLeapYear = False

Else ' Yr Mod 400 = 0
IsLeapYear = True
End If
End Function

--
Joe Foster <mailto:jlfoster%40znet.com> Sacrament R2-45 <http://www.xenu.net/>
WARNING: I cannot be held responsible for the above They're coming to
because my cats have apparently learned to type. take me away, ha ha!
Jul 17 '05 #6

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

Similar topics

3
by: Dai Ba Wong | last post by:
Hi: Currently I am having a problem with my webpage. My page consist of two frames, one consist of input text field and the other contains link for different pop-up windows. The problem...
9
by: Roger Withnell | last post by:
Tearing hair out time! Simple attached page shows the problem. http://www.brilley.co.uk/TestFocusSelect.htm Using a function to test if too many characters have been keyed in to a textarea....
6
by: MickG | last post by:
Hi, I am trying to validate these values, this seems to work fine for the phone number and name but I am trying to get the program to fail to submit and set the focus on the date when 2006 is...
0
by: Mike | last post by:
My original problem was solved by Bruce Dodds (Thanks!!) ORIGINAL PROBLEM I have developed an application for data enty for daily production in my factory. I have one combo box for shifts...
1
by: Rasmus | last post by:
I need to grab focus to a specific node i my treeview when I click on my listbox. Here's the code that differs between the different event i the listBox: private void...
3
by: BK | last post by:
I've created a small calculator that will pop up on demand within a form. The calculator is working fine, but I'm having a focus problem. The calculator looks almost identical to the Windows...
1
by: ozzy66 | last post by:
Hiho NG, I've created a tool (tray application) like "keytext" or "shortcut" that is a little tool where you can store text components which you can call from any running app. Such a stored text...
6
by: probashi | last post by:
Hi, Issue: After post back selected item of a list box is getting out of focus (when it contains more items than it's size). I have a List Box in an ASPX page. I select an item from the...
2
dlite922
by: dlite922 | last post by:
Before traversing my code, here's what my goal is and what this function does: I have a table of fields that dynamically grows as the user enters information. A minimum of 3 rows must always...
10
by: Derek Hart | last post by:
I can set focus to my property grid by using propgrid.Focus - but how can I set the default property that is always first? Or just set focus to the default property? Can this be done?
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
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
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,...
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...
0
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 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.