ucla11
asked on
Need to clear Textbox after each number is added to ListBox
I have a program I made for my kids math homework. The problem I am having is the user enters a number in a textbox then click an enter buttonor presses enter on the keyboard and the number is added to the listbox. What I want happen next is the textbox is cleared and textbox has focus so the user can enter a new number right away without having to clear the textbox themselves. What is happening is after you type the first number in and click the button there is a delay in which the number appears in the listboxafter that though the rest of the numbers are added to listbox immediately. This isn't such a big deal but I was wondering if there is a better way to clear the textbox after each number is added to the listbox.
here is my code....
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Num = CLng(TextBox1.Text)
ListBox1.Items.Add(Format( Num, "#,#"))
TextBox1.Clear()
TextBox1.Focus()
End Sub
Thanks...
here is my code....
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Num = CLng(TextBox1.Text)
ListBox1.Items.Add(Format(
TextBox1.Clear()
TextBox1.Focus()
End Sub
Thanks...
Try something like this...
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Num = CLng(TextBox1.Text)
ListBox1.Items.Add(Format( Num, "#,#"))
Clear_Form
End Sub
Private Sub Clear_Form
ListBox1.Refresh
TextBox1.Clear()
TextBox1.Focus()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Num = CLng(TextBox1.Text)
ListBox1.Items.Add(Format(
Clear_Form
End Sub
Private Sub Clear_Form
ListBox1.Refresh
TextBox1.Clear()
TextBox1.Focus()
End Sub
ASKER
TextBox1.Text = "" does the same thing
Private Sub Clear_Form
ListBox1.Refresh
TextBox1.Clear()
TextBox1.Focus()
End Sub
works in reverse the listbox loads quickly but the textbox clears slowly, and only after the first inputthen it works fine either way.
Private Sub Clear_Form
ListBox1.Refresh
TextBox1.Clear()
TextBox1.Focus()
End Sub
works in reverse the listbox loads quickly but the textbox clears slowly, and only after the first inputthen it works fine either way.
This works for me...
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim Num As Long
If TextBox1.Text.Length <= 0 Then
Exit Sub
End If
Num = CLng(TextBox1.Text)
ListBox1.Items.Add(Format( Num, "#,#"))
Clear_Form()
End Sub
Private Sub Clear_Form()
ListBox1.Refresh()
TextBox1.Clear()
TextBox1.Focus()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim Num As Long
If TextBox1.Text.Length <= 0 Then
Exit Sub
End If
Num = CLng(TextBox1.Text)
ListBox1.Items.Add(Format(
Clear_Form()
End Sub
Private Sub Clear_Form()
ListBox1.Refresh()
TextBox1.Clear()
TextBox1.Focus()
End Sub
ASKER
Maybe I am doing some different because it still works the same for me.....works in reverse the listbox loads quickly but the textbox clears slowly, and only after the first input then it works fine either way.
the only thing that looks different is Dim Num As Long....I already declared Num.......
Public Class Form1
Inherits System.Windows.Forms.Form
Private Num As Long
there is about a 3second delay for me before the textbox clears(again it is only on the first number inputed and only when you first start the Application. If I clear the listbox an enter new numbers it works fine, even the first number inputed. If I can't fix it that is okay but it is driving me crazy. I made the exact same program in VB 6.0 and it works fine.
the only thing that looks different is Dim Num As Long....I already declared Num.......
Public Class Form1
Inherits System.Windows.Forms.Form
Private Num As Long
there is about a 3second delay for me before the textbox clears(again it is only on the first number inputed and only when you first start the Application. If I clear the listbox an enter new numbers it works fine, even the first number inputed. If I can't fix it that is okay but it is driving me crazy. I made the exact same program in VB 6.0 and it works fine.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I would either do as mdougan said or, right when the form first opens, add a number to the list box and then removed it right quick. Sure, it's a stupid work around for a problem that should exist, but at least the delay will be out of the way by the time the user is ready to enter data.
Good luck.
Good luck.
"Sure, it's a stupid work around for a problem that should exist..."
should read:
"Sure, it's a stupid work around for a problem that should not exist..."
should read:
"Sure, it's a stupid work around for a problem that should not exist..."
I like that idea UncleMidriff.... the user is not really going to notice it much as the form loads.
Well... I have pasted your code in one form and there are no problem, the textBox is cleared as fast as the first time.
TextBox1.Text = ""