focus with the text selected

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Randi

    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(txtIn put.Text) Then
    If IsLeapYear(txtI nput.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


  • Randy Birch

    #2
    Re: focus with the text selected

    in the gotfocus event of the textbox, put:

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

    .... then just place a

    txtInput.SetFoc us

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

    --

    Randy Birch
    MVP Visual Basic

    Please respond only to the newsgroups so all can benefit.


    "Randi" <RSaddler@stny. rr.com> wrote in message
    news:ggXsb.7891 3$ji3.72966@twi ster.nyroc.rr.c om...
    : 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(txtIn put.Text) Then
    : If IsLeapYear(txtI nput.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
    :
    :


    Comment

    • Randi

      #3
      Re: focus with the text selected

      Randy,
      Thank You, Thank You....

      Kelsey

      "Randy Birch" <rgb_removethis @mvps.org> wrote in message
      news:9uYsb.3983 $YX1.372@news04 .bloor.is.net.c able.rogers.com ...[color=blue]
      > in the gotfocus event of the textbox, put:
      >
      > with txtInput
      > .selstart = 0
      > .sellength = len(.text)
      > end with
      >
      > ... then just place a
      >
      > txtInput.SetFoc us
      >
      > ... 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" <RSaddler@stny. rr.com> wrote in message
      > news:ggXsb.7891 3$ji3.72966@twi ster.nyroc.rr.c om...
      > : 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[/color]
      or[color=blue]
      > : 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[/color]
      below.[color=blue]
      > :
      > : Thanks,
      > : Kelsey
      > :
      > : Private Sub Command1_Click( )
      > :
      > : If IsNumeric(txtIn put.Text) Then
      > : If IsLeapYear(txtI nput.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
      > :
      > :
      >
      >[/color]


      Comment

      • 3dfibster

        #4
        Re: focus with the text selected

        "Randi" <RSaddler@stny. rr.com> wrote in message news:<ggXsb.789 13$ji3.72966@tw ister.nyroc.rr. com>...[color=blue]
        > I have this program.. if it is a leap year or
        > not.[/color]
        [color=blue]
        > 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[/color]

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


        I'd rather be playing backgammon..


        3dfibster

        Comment

        • Randy Birch

          #5
          Re: focus with the text selected

          No, that works.

          --

          Randy Birch
          MVP Visual Basic

          Please respond only to the newsgroups so all can benefit.


          "3dfibster" <3dfibs@excite. com> wrote in message
          news:27808ed8.0 311171407.2fa5a f@posting.googl e.com...
          : "Randi" <RSaddler@stny. rr.com> wrote in message
          news:<ggXsb.789 13$ji3.72966@tw ister.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


          Comment

          • Joe \Nuke Me Xemu\ Foster

            #6
            Re: focus with the text selected

            "3dfibster" <3dfibs@excite. com> wrote in message <news:27808ed8. 0311171407.2fa5 af@posting.goog le.com>...
            [color=blue]
            > "Randi" <RSaddler@stny. rr.com> wrote in message news:<ggXsb.789 13$ji3.72966@tw ister.nyroc.rr. com>...[/color]
            [color=blue][color=green]
            > > 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[/color]
            >
            > I think you are missing an "else" in there somewhere..[/color]

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

            Public Function IsLeapYear(ByVa l 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(ByVa l 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:jlfoste r%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!


            Comment

            Working...