Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Posted

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

Live as if you were to die tomorrow. Learn as if you were to live forever.
Gandhi
Posted

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

Posted

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 .

Posted

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

Posted

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

Posted

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

Posted

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

Posted

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

Posted

How about

 


      if myListBox.FindStringExact("abc") = Listbox.NoMatches then
       'nothing found
      else
       myListBox.SelectedIndex = myListBox.FindStringExact("abc")
      end if

.nerd
Posted

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!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...