yewmeng Posted February 26, 2004 Posted February 26, 2004 hi all my problem is how to insert a value to a textbox length for example i want to insert string "a" when the len(textbox1.text) = 3 please help me thx in advance Quote
techmanbd Posted February 26, 2004 Posted February 26, 2004 not sure exactly what you are saying but hopefully this is what you are looking for if textbox1.text.length = 3 then whereveryouwant.text = a end if Quote Quote Live as if you were to die tomorrow. Learn as if you were to live forever. Gandhi
kas Posted February 26, 2004 Posted February 26, 2004 Not sure I fully understand where your string goes, but here's code to test the length of the text box's text Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged If TextBox1.Text.Length = 3 Then TextBox1.Text &= "a" End If End Sub Let me know if I've not understood your queestion. kas Quote
yewmeng Posted February 27, 2004 Author Posted February 27, 2004 yeah is working but still have some problem coz the .net version i have is recognise , as decimal point instead of . so i want to clear the . and replace , when user key in . i have try the code u posted at here but how to clear the . Quote
kas Posted February 27, 2004 Posted February 27, 2004 Try This: Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress e.Handled = True 'This effectively Cancels the Keypress If e.KeyChar <> "." Then e.Handled = False ' Else TextBox1.Text &= "," TextBox1.SelectionStart = TextBox1.Text.Length End If End Sub kas Quote
yewmeng Posted February 27, 2004 Author Posted February 27, 2004 yeah is working good how about this Private Sub txtQuantityIn_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtQuantityIn.KeyPress Dim keyAscii As Int16 keyAscii = Asc(e.KeyChar) If keyAscii = 46 Then MessageBox.Show("ajsdjha") txtQuantityIn.Text = "" End If End Sub i want to clear the textbox but cant. so how to clear it Quote
kas Posted February 27, 2004 Posted February 27, 2004 The solution to all these kinds of problems is the e.Handled statement. This controls whether the key press is allowed to be displayed or not. Private Sub txtQuantityIn_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtQuantityIn.KeyPress e.Handled = True ' Suppress the key press for now Dim keyAscii As Int16 keyAscii = Asc(e.KeyChar) If keyAscii = 46 Then MessageBox.Show("ajsdjha") txtQuantityIn.Text = "" Else e.Handled = False ' Allow the key press if not ASC(46) End If End Sub kas Quote
kas Posted February 27, 2004 Posted February 27, 2004 In fact, slightly better code would be: Private Sub txtQuantityIn_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtQuantityIn.KeyPress e.Handled = True ' Suppress the key press for now If Asc(e.KeyChar) = 46 Then MessageBox.Show("ajsdjha") txtQuantityIn.Clear() Else e.Handled = False ' Allow the key press if not ASC(46) End If End Sub There is no benefit in declaring your Int16 variable. kas Quote
yewmeng Posted February 27, 2004 Author Posted February 27, 2004 it working good thx so much 1 more question how to check the value in listbox exist or not i have try this code in a button dim i as integer for i = 0 to listbox1.lenght - 1 if listbox1.text = "abc" then messagebox.show("aaaa") end if next but no messagebox pop up but in my listbox has the value abc Quote
kas Posted February 27, 2004 Posted February 27, 2004 You were close. It should be: If ListBox1.SelectedItem = "abc" Then MessageBox.Show("Hooray") kas Quote
Heiko Posted February 27, 2004 Posted February 27, 2004 How about if myListBox.FindStringExact("abc") = Listbox.NoMatches then 'nothing found else myListBox.SelectedIndex = myListBox.FindStringExact("abc") end if Quote .nerd
yewmeng Posted February 27, 2004 Author Posted February 27, 2004 yeah both of the code also working good.... thx kas and heiko may god bless both of u .... Quote
yewmeng Posted February 27, 2004 Author Posted February 27, 2004 hi again how about to obtain part of the string in the textbox when the textbox lenght = 3 lets say,input 123 to textbox1.text then how to obtain the value 3. pls help me, thx in advance! Quote
kas Posted February 29, 2004 Posted February 29, 2004 Label1.Text = txtQuantityIn.Text.Chars(2) (The length count of a string starts with zero, so you pick out element #2) kas Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.