Click here to Skip to main content
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 10: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 Maciej Los 315
1 OriginalGriff 233
2 Aajmot Sk 224
3 Richard MacCutchan 220
4 Marcin Kozub 210
0 OriginalGriff 7,853
1 Sergey Alexandrovich Kryukov 7,107
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,790


Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 10 May 2013
Copyright © CodeProject, 1999-2014
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