Results 1 to 13 of 13
  1. #1
    nathanael890's Avatar
    Join Date
    Aug 2008
    Gender
    male
    Posts
    158
    Reputation
    13
    Thanks
    46
    My Mood
    Bored

    [Help]Add Listbox Items per line[Solved]

    This is sudden guys but I need the code for adding listbox items per line at textboxes or a text file.

    It will be for the log


    Status: Unknown

  2. #2
    Jason's Avatar
    Join Date
    Apr 2010
    Gender
    male
    Location
    /dev/null
    Posts
    5,704
    Reputation
    918
    Thanks
    7,676
    My Mood
    Mellow
    Wait, do you mean add each line from a textfile as new listbox entry, or write each listbox entry to a textfile?

    Quote Originally Posted by Jeremy S. Anderson
    There are only two things to come out of Berkley, Unix and LSD,
    and I don’t think this is a coincidence
    You can win the rat race,
    But you're still nothing but a fucking RAT.


    ++Latest Projects++
    [Open Source] Injection Library
    Simple PE Cipher
    FilthyHooker - Simple Hooking Class
    CLR Injector - Inject .NET dlls with ease
    Simple Injection - An in-depth look
    MPGH's .NET SDK
    eJect - Simple Injector
    Basic PE Explorer (BETA)

  3. #3
    freedompeace's Avatar
    Join Date
    Jul 2010
    Gender
    female
    Posts
    3,033
    Reputation
    340
    Thanks
    2,792
    My Mood
    Sad
    Code:
    dim content As String = ""
    foreach item As string In listbox.Items
    textbox.Items.Add(item)
    content += item
    next
    if File.Exists("out.txt")
    then
    File.Delete("out.txt")
    end if
    File.WriteAllText("out.txt")
    her is code. typed on mobile, first ever time i tried doing this :L

  4. #4
    Jason's Avatar
    Join Date
    Apr 2010
    Gender
    male
    Location
    /dev/null
    Posts
    5,704
    Reputation
    918
    Thanks
    7,676
    My Mood
    Mellow
    Quote Originally Posted by freedompeace View Post
    Code:
    dim content As String = ""
    foreach item As string In listbox.Items
    textbox.Items.Add(item)
    content += item
    next
    if File.Exists("out.txt")
    then
    File.Delete("out.txt")
    end if
    File.WriteAllText("out.txt")
    her is code. typed on mobile, first ever time i tried doing this :L
    Don't need to delete the file, WriteAllText doesn't append text. I would just say:

    Code:
    IO.File.WriteAllLines("C:\VB Projects\out.txt", ListBox1.Items.Cast(Of String).ToArray)


    And leave it at that

    Quote Originally Posted by Jeremy S. Anderson
    There are only two things to come out of Berkley, Unix and LSD,
    and I don’t think this is a coincidence
    You can win the rat race,
    But you're still nothing but a fucking RAT.


    ++Latest Projects++
    [Open Source] Injection Library
    Simple PE Cipher
    FilthyHooker - Simple Hooking Class
    CLR Injector - Inject .NET dlls with ease
    Simple Injection - An in-depth look
    MPGH's .NET SDK
    eJect - Simple Injector
    Basic PE Explorer (BETA)

  5. The Following User Says Thank You to Jason For This Useful Post:

    Lyoto Machida (02-08-2011)

  6. #5
    Lyoto Machida's Avatar
    Join Date
    Jan 2011
    Gender
    male
    Location
    Far away with girls
    Posts
    3,734
    Reputation
    133
    Thanks
    1,621
    My Mood
    Aggressive
    Quote Originally Posted by Jason View Post


    Don't need to delete the file, WriteAllText doesn't append text. I would just say:

    Code:
    IO.File.WriteAllLines("C:\VB Projects\out.txt", ListBox1.Items.Cast(Of String).ToArray)


    And leave it at that
    =) Nice ... Im gonna use this xD

    PS: What change is coming?

  7. #6
    nathanael890's Avatar
    Join Date
    Aug 2008
    Gender
    male
    Posts
    158
    Reputation
    13
    Thanks
    46
    My Mood
    Bored
    Let's say in the textbox the content is
    Code:
    Content 1
    Content 2
    Content 3
    then every line of it will appear in each item.


    Status: Unknown

  8. #7
    Jason's Avatar
    Join Date
    Apr 2010
    Gender
    male
    Location
    /dev/null
    Posts
    5,704
    Reputation
    918
    Thanks
    7,676
    My Mood
    Mellow
    Quote Originally Posted by nathanael890 View Post
    Let's say in the textbox the content is
    Code:
    Content 1
    Content 2
    Content 3
    then every line of it will appear in each item.
    Code:
    ListBox1.Items.AddRange(TextBox1.Lines)
    Is that what you're after?

    Quote Originally Posted by Jeremy S. Anderson
    There are only two things to come out of Berkley, Unix and LSD,
    and I don’t think this is a coincidence
    You can win the rat race,
    But you're still nothing but a fucking RAT.


    ++Latest Projects++
    [Open Source] Injection Library
    Simple PE Cipher
    FilthyHooker - Simple Hooking Class
    CLR Injector - Inject .NET dlls with ease
    Simple Injection - An in-depth look
    MPGH's .NET SDK
    eJect - Simple Injector
    Basic PE Explorer (BETA)

  9. The Following User Says Thank You to Jason For This Useful Post:

    nathanael890 (02-12-2011)

  10. #8
    Hassan's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    System.Threading.Tasks
    Posts
    4,764
    Reputation
    495
    Thanks
    2,133
    My Mood
    Dead
    Quote Originally Posted by nathanael890 View Post
    Let's say in the textbox the content is
    Code:
    Content 1
    Content 2
    Content 3
    then every line of it will appear in each item.
    Edit: Jason answered it. Is that what ya want ?

  11. #9
    nathanael890's Avatar
    Join Date
    Aug 2008
    Gender
    male
    Posts
    158
    Reputation
    13
    Thanks
    46
    My Mood
    Bored
    Actually He did it in reverse..
    but I don't need it as I already know it.

    I was looking for adding some items on every line on a textbox or a text file..

    I think it includes the "Enter" button..


    Status: Unknown

  12. #10
    Hassan's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    System.Threading.Tasks
    Posts
    4,764
    Reputation
    495
    Thanks
    2,133
    My Mood
    Dead
    Quote Originally Posted by nathanael890 View Post
    Actually He did it in reverse..
    but I don't need it as I already know it.

    I was looking for adding some items on every line on a textbox or a text file..

    I think it includes the "Enter" button..
    Set Multiline property of Textbox to True via properties.

    Or by code:

    Code:
    Textbox1.Multiline = True
    This way you can use the Enter button !

    ...?

  13. #11
    Jason's Avatar
    Join Date
    Apr 2010
    Gender
    male
    Location
    /dev/null
    Posts
    5,704
    Reputation
    918
    Thanks
    7,676
    My Mood
    Mellow
    Quote Originally Posted by nathanael890 View Post
    Actually He did it in reverse..
    but I don't need it as I already know it.

    I was looking for adding some items on every line on a textbox or a text file..

    I think it includes the "Enter" button..
    Sorry, I don't understand what you want, you keep changing your mind. Please give a decent explanation

    Quote Originally Posted by Jeremy S. Anderson
    There are only two things to come out of Berkley, Unix and LSD,
    and I don’t think this is a coincidence
    You can win the rat race,
    But you're still nothing but a fucking RAT.


    ++Latest Projects++
    [Open Source] Injection Library
    Simple PE Cipher
    FilthyHooker - Simple Hooking Class
    CLR Injector - Inject .NET dlls with ease
    Simple Injection - An in-depth look
    MPGH's .NET SDK
    eJect - Simple Injector
    Basic PE Explorer (BETA)

  14. The Following User Says Thank You to Jason For This Useful Post:

    nathanael890 (02-12-2011)

  15. #12
    nathanael890's Avatar
    Join Date
    Aug 2008
    Gender
    male
    Posts
    158
    Reputation
    13
    Thanks
    46
    My Mood
    Bored
    Quote Originally Posted by Jason View Post


    Sorry, I don't understand what you want, you keep changing your mind. Please give a decent explanation
    I wasn't talking about you... It was from the other guy and I did a wrong grammar.. anyway,

    the code works as you said... thanks for it..
    I do also use this code that I found but more than codes than yours..
    Code:
    For Each Line As String In TextBox1.Lines
    ListBox1.Items.Add(Line)
    Next
    Thanks..


    Status: Unknown

  16. #13
    Jason's Avatar
    Join Date
    Apr 2010
    Gender
    male
    Location
    /dev/null
    Posts
    5,704
    Reputation
    918
    Thanks
    7,676
    My Mood
    Mellow
    Alright, marked as solved. No posting unless it's relevant and the thread is under a week old.

    As for the code differences, addrange does pretty much the same thing as looping through the elements and adding them all, albeit tidier.

    Quote Originally Posted by Jeremy S. Anderson
    There are only two things to come out of Berkley, Unix and LSD,
    and I don’t think this is a coincidence
    You can win the rat race,
    But you're still nothing but a fucking RAT.


    ++Latest Projects++
    [Open Source] Injection Library
    Simple PE Cipher
    FilthyHooker - Simple Hooking Class
    CLR Injector - Inject .NET dlls with ease
    Simple Injection - An in-depth look
    MPGH's .NET SDK
    eJect - Simple Injector
    Basic PE Explorer (BETA)

  17. The Following User Says Thank You to Jason For This Useful Post:

    nathanael890 (02-12-2011)