netnewb2002 Posted September 17, 2002 Posted September 17, 2002 Hello, I need some help with .NET for Visual Basic. Probably is extremely easy for you pros, but it's sure giving me a head ache. I have a textbox, named txtinput.text and a numpad, named nud1.value. At runtime text will be inputed into txtinput, and the numpad: Whether clicked up or down will display the left letters, center letters, and right letters, of the string. I've have figured out how to get the left and the right side to work properly, but for the center, I have no clue. txtleft.text 'displays the left side of the string txtcenter.text 'displays the center of the string txtright.text 'displays the right side of the string This is my code for the numpad. No idea on how to get the center of the string to display correctly, any help? I deleted the mid function I tried, cause at run time it would start way out at the right end of the string, and go backwards when I clicked the numpad. Private Sub nud1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles nud1.ValueChanged Dim input As String 'declaring as string input = txtinput.Text 'input = textbox txtright.Text = Strings.Right(input, nud1.Value) 'will input each letter from right to left according to nud value input = txtinput.Text 'input = textbox txtleft.Text = Strings.Left(input, nud1.Value) 'will input each letter from right to left according to nud value If nud1.Value > Len(input) Then 'if nud1.value is greater than the string length and error box will appear MsgBox("doesnt go that high, try agian", MsgBoxStyle.Critical, "String Handler") End If End Sub Thanks, Netnewb2002 Quote
*Experts* Bucky Posted September 17, 2002 *Experts* Posted September 17, 2002 You can use the Substring method of any String to get the "middle" (or beginning or end, depending on how you use it). Substring is essentially the same as Mid(), except it is 0-based (the index of the first character is zero). If I understand correctly, and you're trying to get the string that is between the end and the start, you want something like this after setting txtLeft. txtCenter.Text = input.Substring(nud1.Value, input.Length - nud1.Value) The first parameter of Substring is the starting index to get the string from. The second parameter is the length. I'm not 100% sure on this, and you may need to stick in a +1 or -1 somewhere. HTH Quote "Being grown up isn't half as fun as growing up These are the best days of our lives" -The Ataris, In This Diary
Guest tamandt Posted September 18, 2002 Posted September 18, 2002 .NEt Not to familliar with .NET but in VB6 there are three functions right$(String, length) left$(String, length) and mid$(String, start, length) see if .net supports that function Quote
netnewb2002 Posted September 18, 2002 Author Posted September 18, 2002 (edited) txtcenter.Text = input.Substring(nud1.Value, input.Length - nud1.Value) I tried inputing this for code. It did almost the same thing as the mid() function. For example: I input 1234567 and say I had 4 for the num pad. txtleft=1234 txtcenter=567 txtright=7654 Center is off a little still :( I tried modifying the code a little just to see what would happen. txtcenter.Text = input.Substring(nud1.Value\2, input.Length \2 ) Using the same input of 1234567 and numpad of 4 txtcenter=345 which seems about right, till I change the value of the numpad... lets say 5 txtcenter.text=345 still If I change the value to 6 txtcenter.text=456 which is still wrong. If everything is correct, this should happen: If I put in a 1 for the numpad, and 12345 for txtinput.text txtleft=1 txtright=5 txtcenter=3 If I would change it to 3 instead of one txtleft=123 txtright=543 txtcenter= 234 Any other suggestions? Edited September 18, 2002 by netnewb2002 Quote
netnewb2002 Posted September 18, 2002 Author Posted September 18, 2002 Tamandt, txtcenter.Text = Mid(input, nud1.Value, input.Length) Just tried this, I used 1234567 and 1-7 for numpad txtcenter.text=1234567 for 1 txtcenter.text=123456 for 2 and so on. :( Quote
Pookie Posted September 18, 2002 Posted September 18, 2002 Sorry, maybe i haven't read your question close enough as it a bit hard to follow. If you want to grab the middle 3 numbers of a string strResult = mid$(strNumber , len(strNumber) \ 2 - 1 , 3) Quote
*Gurus* divil Posted September 18, 2002 *Gurus* Posted September 18, 2002 Bad people! This is VB.NET! Use the Substring method of the string class, not Mid/Left/Right! Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
netnewb2002 Posted September 18, 2002 Author Posted September 18, 2002 Thanks for the assistance, the substring worked great :) Thanks, 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.