CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: VB Bug ???

  1. #1
    Guest

    VB Bug ???

    Hi all,

    Here's my problem


    Given

    A Form containing

    A/ a textbox (txt_Name = Name of a company)
    B/ a command button (cmd_Save = Save button)
    C/ a lostfocus event for this textbox (txt_Name)

    private Sub LostFocus_txt_Name()
    ' Checks if company name is filled in
    ' & then enables the command buttton
    cmd_Save.Enabled = false
    If (len(Trim(txt_Name)) = 0) then
    Exit Sub
    End If
    cmd_Save.Enabled = true
    End Sub



    Problem

    You have to click 2 times on the command button to activate the
    Click event on this command button !!!

    Is there a solution to this problem ???

    Thanks.

    Jordan


  2. #2
    Guest

    Re: VB Bug ???

    If you are using VB6 it's much better to use Validate event:

    private Sub txtName_Validate(Cancel as Boolean)
    If txtName.Text = "" then Cancel = true
    End Sub



    Actually you can use LostFocus for this particular case, but when you place at least one more control which value you need to validate when it's loosing focus you'll have hightmare.
    Vlad



  3. #3
    Join Date
    May 1999
    Location
    Oxford UK
    Posts
    1,459

    Re: VB Bug ???

    It's not a bug - just a 'bad' (?) way of doing it. How about setting the enabled property in the 'change' event of the text1 textbox :


    private Sub txtName_Change()
    If len(Trim$(txtName.Text)) > 0 then
    cmdSave.Enabled = true
    else
    cmdSave.Enabled = false
    End If
    '
    ' or if you want to be really clever
    '
    ' cmdSave.Enabled = (len(Trim$(txtName.Text)) > 0)

    End Sub




    Either of the two methods above will work (- with all versions of VB since v3 I think)

    Chris Eastwood

    CodeGuru - the website for developers
    http://codeguru.developer.com/vb

  4. #4
    Join Date
    Dec 1999
    Location
    india,hyderabad
    Posts
    7

    Re: VB Bug ???

    hey use a global variable here goes
    public i as integer

    form_load()
    I=0
    end sub

    command1_click()
    if i =0 then
    i=I+1
    exit sub
    else
    * perform wot ever operations u want *
    i=0 again
    end if
    end sub

    try this code it may work!

    Sudharshaan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured