Click here to Skip to main content
11,637,415 members (58,047 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
I need to read the first 2 letters of a textbox.


Any idee's or links ?
Posted 9-May-13 9:41am
Comments
Sergey Alexandrovich Kryukov at 9-May-13 15:44pm
   
Does this require ideas?!
—SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Use TextBox.Text. And some minimal common sense.

Links? No, sorry. You did not bother to give us exact type name of the "TextBox" (do you know how many different type under this name are there?), but you can easily find a link using Google or Bing. Especially if you give it a fully-qualified name.

—SA
  Permalink  
Comments
Maciej Los at 9-May-13 16:31pm
   
+5
Sergey Alexandrovich Kryukov at 9-May-13 17:01pm
   
Thank you, Maciej.
—SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Dim str as String
str = TextBox1.Text.Substring(0,2)
  Permalink  
Comments
Maciej Los at 9-May-13 16:31pm
   
+5
Johnny J. at 10-May-13 7:33am
   
Just one thing: The OP will need to check that the text in the textbox is long enough, otherwise your code will generate an exception.

If TextBox1.Text.Length >=2 Then
str = TextBox1.Text.Substring(0,2)
End If

Sorry for pointing it out. It's common knowledge of course, but it doesn't seem like the OP has much experience in VB.NET...
ryanb31 at 10-May-13 7:46am
   
Good catch. Thank you.
pdoxtader at 10-May-13 8:57am
   
Yes, and he may want to trim the text in the textbox - unless he wants the 2 possible empty spaces. ( str = TextBox1.Text.Trim.Substring(0,2) )

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 295
1 stibee 288
2 jyo.net 270
3 Sergey Alexandrovich Kryukov 224
4 himanshu agarwal 184
0 OriginalGriff 9,031
1 Sergey Alexandrovich Kryukov 8,643
2 Mika Wendelius 6,959
3 F-ES Sitecore 2,388
4 Suvendu Shekhar Giri 2,320


Advertise | Privacy | Mobile
Web03 | 2.8.150728.1 | Last Updated 10 May 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100