Results 1 to 13 of 13

Thread: VB = Left, VB.Net = ??

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2002
    Location
    Singapore
    Posts
    93

    Unhappy VB = Left, VB.Net = ??

    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?

    VB Code:
    1. Dim str As String
    2.         Dim WordPos As Long
    3.         Dim MyTextLeft As String
    4.         Dim MyTextRight As String
    5.         WordPos = InStr(TextBox1.Text, "06:00 AM")
    6.         MyTextLeft = [color=red]Left[/color](TextBox1.Text, WordPos - 1)
    7.         MyTextRight = Mid(TextBox1.Text, WordPos + Len("07:00 AM"), Len(TextBox1.Text) - WordPos + Len("07:00 AM"))
    8.         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..
    An elephant learning VB..

  2. #2
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    use the Mid()/Substring() function..left() and right() suck in comp. with mid() lol

  3. #3
    Addicted Member Sheppe's Avatar
    Join Date
    Sep 2002
    Location
    Kelowna, BC
    Posts
    245
    Look in the Strings namespace.
    [vbcode]
    On Error Goto Hell
    [/vbcode]
    Sheppe Pharis, MCSD
    Check out http://www.vb-faq.com
    Click here for access to the free Code-Express source code and component sharing network for VB6
    Want a better way to skin your .NET applications? Click here!

  4. #4
    Hyperactive Member
    Join Date
    Feb 2001
    Location
    Houston, TX
    Posts
    342
    If you still need it, the old left and right methods are in the Microsoft.Visualbasic namespace.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Sep 2002
    Location
    Singapore
    Posts
    93
    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..
    An elephant learning VB..

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Sep 2002
    Location
    Singapore
    Posts
    93
    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.
    An elephant learning VB..

  7. #7
    Hyperactive Member
    Join Date
    Feb 2002
    Posts
    261
    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.

  8. #8
    Addicted Member
    Join Date
    Jul 1999
    Posts
    207
    I think this is what you are looking for, not sure though.

    VB Code:
    1. Dim myString As String = "it is was 6:00 pm but now is 7:00 pm and will be 8:00 pm"
    2. Dim myString1 As String
    3. Dim myString2 As String
    4. Dim sep1 As String = "6:00 pm"
    5. Dim Sep2 As String = "7:00 pm"
    6.  
    7. myString1 = myString.Remove(myString.IndexOf(sep1) - 1, myString.Length - myString.IndexOf(sep1) + 1)
    8. myString2 = myString.Remove(0, myString.IndexOf(Sep2) + Sep2.Length + 1)
    9.  
    10. MsgBox(myString1 & vbCrLf & myString2 & vbCrLf & myString)
    Last edited by Jeremy Martin; Oct 29th, 2002 at 08:25 PM.

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Sep 2002
    Location
    Singapore
    Posts
    93
    Originally posted by Jeremy Martin
    I think this is what you are looking for, not sure though.

    VB Code:
    1. Dim myString As String = "it is was 6:00 pm but now is 7:00 pm and will be 8:00 pm"
    2. Dim myString1 As String
    3. Dim myString2 As String
    4. Dim sep1 As String = "6:00 pm"
    5. Dim Sep2 As String = "7:00 pm"
    6.  
    7. myString1 = myString.Remove(myString.IndexOf(sep1) - 1, myString.Length - myString.IndexOf(sep1) + 1)
    8. myString2 = myString.Remove(0, myString.IndexOf(Sep2) + Sep2.Length + 1)
    9.  
    10. 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"?
    An elephant learning VB..

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Sep 2002
    Location
    Singapore
    Posts
    93
    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?
    An elephant learning VB..

  11. #11
    Addicted Member
    Join Date
    Jul 1999
    Posts
    207
    You can use the string functions on textboxes, but you need to refer the the text property and not the object. Example instead of:

    VB Code:
    1. myString1 = myString.Remove(myString.IndexOf(sep1) - 1, myString.Length - myString.IndexOf(sep1) + 1)

    you could use:

    VB Code:
    1. 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

  12. #12
    Hyperactive Member
    Join Date
    Feb 2002
    Posts
    261
    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.

  13. #13

    Thread Starter
    Lively Member
    Join Date
    Sep 2002
    Location
    Singapore
    Posts
    93
    Ohh..... I begin to see the lights.. Thanks everybody!!
    An elephant learning VB..

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width