469,366 Members | 2,349 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,366 developers. It's quick & easy.

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 5871
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by Roger Withnell | last post: by
6 posts views Thread by MickG | last post: by
1 post views Thread by Rasmus | last post: by
3 posts views Thread by BK | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.