Click to See Complete Forum and Search --> : VB = Left, VB.Net = ??
TaNz
Oct 29th, 2002, 12:37 AM
I copy this from somewhere but this is used in VB, so I decided to move it into .NET, hopping there won't be errors but...
So anyone can show me the light?
Dim str As String
Dim WordPos As Long
Dim MyTextLeft As String
Dim MyTextRight As String
WordPos = InStr(TextBox1.Text, "06:00 AM")
MyTextLeft = Left(TextBox1.Text, WordPos - 1)
MyTextRight = Mid(TextBox1.Text, WordPos + Len("07:00 AM"), Len(TextBox1.Text) - WordPos + Len("07:00 AM"))
TextBox2.Text = MyTextLeft & MyTextRight
Basically the commands is to take the words before "06:00 AM" and words after "07:00 AM" and put them together in TextBox2..
PT Exorcist
Oct 29th, 2002, 06:31 AM
use the Mid()/Substring() function..left() and right() suck in comp. with mid() lol
Sheppe
Oct 29th, 2002, 11:31 AM
Look in the Strings namespace. :)
MagellanTX
Oct 29th, 2002, 12:44 PM
If you still need it, the old left and right methods are in the Microsoft.Visualbasic namespace.
TaNz
Oct 29th, 2002, 06:43 PM
Originally posted by PT Exorcist
use the Mid()/Substring() function..left() and right() suck in comp. with mid() lol
Ermm.. anyone kind to explain it in much more simpler words?? Not very bright here..
TaNz
Oct 29th, 2002, 07:12 PM
Originally posted by MagellanTX
If you still need it, the old left and right methods are in the Microsoft.Visualbasic namespace.
Tried for all Microsoft.Visualbasic.( Everything )
But nothing seems to work..
Error codes -->
'Public Overloads Property Left() As Integer' has no parameters and its return type cannot be indexed.
Hu Flung Dung
Oct 29th, 2002, 07:14 PM
Originally posted by TaNz
Tried for all Microsoft.Visualbasic.( Everything )
But nothing seems to work..
Error codes -->
'Public Overloads Property Left() As Integer' has no parameters and its return type cannot be indexed.
Ahh, there is a Left function, just like in VB6, but it seems like the compiler thinks that your referring to the Left property for controls.
The String.SubString method seems to work really well for string manipulation.
Jeremy Martin
Oct 29th, 2002, 07:19 PM
I think this is what you are looking for, not sure though.
Dim myString As String = "it is was 6:00 pm but now is 7:00 pm and will be 8:00 pm"
Dim myString1 As String
Dim myString2 As String
Dim sep1 As String = "6:00 pm"
Dim Sep2 As String = "7:00 pm"
myString1 = myString.Remove(myString.IndexOf(sep1) - 1, myString.Length - myString.IndexOf(sep1) + 1)
myString2 = myString.Remove(0, myString.IndexOf(Sep2) + Sep2.Length + 1)
MsgBox(myString1 & vbCrLf & myString2 & vbCrLf & myString)
TaNz
Oct 29th, 2002, 07:40 PM
Originally posted by Jeremy Martin
I think this is what you are looking for, not sure though.
Dim myString As String = "it is was 6:00 pm but now is 7:00 pm and will be 8:00 pm"
Dim myString1 As String
Dim myString2 As String
Dim sep1 As String = "6:00 pm"
Dim Sep2 As String = "7:00 pm"
myString1 = myString.Remove(myString.IndexOf(sep1) - 1, myString.Length - myString.IndexOf(sep1) + 1)
myString2 = myString.Remove(0, myString.IndexOf(Sep2) + Sep2.Length + 1)
MsgBox(myString1 & vbCrLf & myString2 & vbCrLf & myString)
Great.. this is the kind I'm looking for but I want those words extracted out to be displayed.. Can the "myString" used as in Textbox instead? Will the properties like "myString.Remove" change to "Textbox.Remove"?
TaNz
Oct 29th, 2002, 07:41 PM
Originally posted by Hu Flung Dung
Ahh, there is a Left function, just like in VB6, but it seems like the compiler thinks that your referring to the Left property for controls.
The String.SubString method seems to work really well for string manipulation.
So how do I use this String.Substring? Do I have to import them into this form or it's just a command to be used in the program?
Jeremy Martin
Oct 29th, 2002, 09:04 PM
You can use the string functions on textboxes, but you need to refer the the text property and not the object. Example instead of:
myString1 = myString.Remove(myString.IndexOf(sep1) - 1, myString.Length - myString.IndexOf(sep1) + 1)
you could use:
myString1 = TextBox1.Text.Remove(TextBox1.Text.IndexOf(sep1) - 1, TextBox1.Text.Length - TextBox1.Text.IndexOf(sep1) + 1)
The textbox.text does have all the same properties and methods as a string.
Jeremy
Hu Flung Dung
Oct 29th, 2002, 09:18 PM
Originally posted by TaNz
So how do I use this String.Substring? Do I have to import them into this form or it's just a command to be used in the program?
You dont understand. Dont think of it like the String data type, there aren't any 'data types' anymore in VB. Everything is an object. The Substring() function is a shared member of the String class. All of your String variables will have the SubString() function, and since you dont have to instantiate an object to use its shared members, you can also call the String.Substring() method directly by using the syntax: 'String.SubString()'. The IDE's intellisense will tell you what arguments to use. Basically, it just returns a portion of the string you pass in.
TaNz
Oct 30th, 2002, 12:05 AM
Ohh..... I begin to see the lights.. Thanks everybody!!
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.