In VB 6.0 you use Left$(str, 2) to get the 2 left most characters....

Just a simple question probably but how do you do this in VB.net, because that command dosn't exist anymore? Thanx :)

Comments

  • : Just a simple question probably but how do you do this in VB.net, because that command dosn't exist anymore? Thanx :)
    :

    According to the books i have read, Left is still there, but i have not been able to get to work myself. Not sure if there is something i`m missing, or i'm doing something wrong.

    Anyone had any success using Left within .net?
  • : Just a simple question probably but how do you do this in VB.net, because that command dosn't exist anymore? Thanx :)
    :

    Use Substring. Two arguments - 1st is where to start in the original string (remember 0-based), and the 2nd is the number of characters to pull off.


    Dim strStart as string = "This is a string"
    TextBox1.Text = strStart.Substring(0, 2)

  • Thank you, your solution was exactly what I needed. My problem was, I wanted to be able to add and remove users to my game by making there own directory to keep .dat files in for form arrays, variables, ect... I had it working but I also had to include a text file to hold the usernames in. I knew there was a better wasy but I couldn't use Directory.getdirectories("users") without the first directory showing (users / username). WIth your tip strusername.substring(2,6) i was able to write a line of code that would enter the users by directory only and delete allt he same. THanks alot and heres a sample of the code reading in the directories into a combobox for anyone else here looking for answers. This is just a small piece of what I've did with this code, e-mail me if you have questions
    KeeblerShadowHaje@yahoo.com
    Sub loadnames(ByRef combobox As Object)
    Dim addnext As Byte = 0, name As String, names() As String, nm As String, x As Byte
    combobox.Items.Clear() : addnext = 0
    names = Directory.GetDirectories("users")'get's all in users
    '(users / username)
    For Each name In names
    x = Len(name) - 6
    nm = name.Substring(6, x)
    combobox.items.add(nm)
    Next
    End Sub 'this isn't the actual code i used, i broke it down for easier understanding..... but it's all you need
  • : Thank you, your solution was exactly what I needed. My problem was, I wanted to be able to add and remove users to my game by making there own directory to keep .dat files in for form arrays, variables, ect... I had it working but I also had to include a text file to hold the usernames in. I knew there was a better wasy but I couldn't use Directory.getdirectories("users") without the first directory showing (users / username). WIth your tip strusername.substring(2,6) i was able to write a line of code that would enter the users by directory only and delete allt he same. THanks alot and heres a sample of the code reading in the directories into a combobox for anyone else here looking for answers. This is just a small piece of what I've did with this code, e-mail me if you have questions
    : KeeblerShadowHaje@yahoo.com
    : Sub loadnames(ByRef combobox As Object)
    : Dim addnext As Byte = 0, name As String, names() As String, nm As String, x As Byte
    : combobox.Items.Clear() : addnext = 0
    : names = Directory.GetDirectories("users")'get's all in users
    : '(users / username)
    : For Each name In names
    : x = Len(name) - 6
    : nm = name.Substring(6, x)
    : combobox.items.add(nm)
    : Next
    : End Sub 'this isn't the actual code i used, i broke it down for easier understanding..... but it's all you need
    :
    I might find some uses for that... thanks
  • : : Just a simple question probably but how do you do this in VB.net, because that command dosn't exist anymore? Thanx :)
    : :
    :
    : According to the books i have read, Left is still there, but i have not been able to get to work myself. Not sure if there is something i`m missing, or i'm doing something wrong.
    :
    : Anyone had any success using Left within .net?
    :

    Its still there, but you need to use:
    Microsoft.VisualBasic.Left()
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories