Results 1 to 10 of 10

Thread: Few Questions...

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2009
    Posts
    3

    Few Questions...

    Hey guys, i want to ask you few questions...

    1.In my program I have 2 textboxes.In first textbox user need to put some number.Let's say he put number 10, then in other textbox program need to write numbers from 1 - 10, like this:
    Code:
    1,2,3,4,5,6,7,8,9,10
    If he put 20 in first textbox, in second textbox it should be:
    Code:
    1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20
    2.I need to do this...
    Import text file to listbox.
    Export items in listbox as text file.

  2. #2
    PowerPoster keystone_paul's Avatar
    Join Date
    Nov 2008
    Location
    UK
    Posts
    3,327

    Re: Few Questions...

    I don't see one question let alone a few.

    You've told us what you want to do, what are you struggling with?

  3. #3
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    Re: Few Questions...

    You can use a for loop to create the output you are looking for. Take a look at an example here:

    http://msdn.microsoft.com/en-us/library/5z06z1kb.aspx


    The my.computer.filesystem can help you read and write files:

    http://msdn.microsoft.com/en-us/library/0b485hf7.aspx

  4. #4
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: Few Questions...

    Will the user ever edit that sequence of numbers 1,2,3...etc? If not, the second textbox should actually be a label.
    My usual boring signature: Nothing

  5. #5

    Thread Starter
    New Member
    Join Date
    Jun 2009
    Posts
    3

    Re: Few Questions...

    @Negative0

    That doesn't work because between every number i need comma.

  6. #6
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,422

    Re: Few Questions...

    to output a sequence of numbers:

    vb Code:
    1. textbox2.text = "1"
    2. for x as integer = 2 to cint(textbox1.text)
    3.     textbox2.text &= "," & x.tostring
    4. next

    to load a listbox from a txt file:

    vb Code:
    1. listbox1.items.addrange(io.file.readalllines(filename))

    to save a listbox contents to a txt file:

    vb Code:
    1. Dim items(listbox1.items.count - 1) As String
    2. ListBox1.Items.CopyTo(items, 0)
    3. IO.File.WriteAllLines(filename, items)

  7. #7

    Thread Starter
    New Member
    Join Date
    Jun 2009
    Posts
    3

    Re: Few Questions...

    Thank you Paul it worked!

    Now I have one more questions....

    1.Is this possible....

    I have a textbox and button.

    Starting text in textbox is:

    Code:
    I am from Croatia
    Is it possible that when i press button that it removes word "Croatia" and every word after word "Croatia" from this textbox.

    Example:

    This is in textbox:

    Code:
    I am from Croatia vdvhdfgdsfgsd
    I need to remove word "Croatia" and every word after it(In this case it is "vdvhdfgdsfgsd")

  8. #8

  9. #9
    Fanatic Member
    Join Date
    Oct 2008
    Location
    Dominican Republic
    Posts
    733

    Re: Few Questions...

    If the user isn't going to select the word, you can do this, if not, just tweak it a little bit

    vb.net Code:
    1. Public Sub DeleteWords()
    2.         Dim sentence As String = "I'm hot Croatia and I'm bored as hell"
    3.         Dim words As String() = sentence.Split(New Char() {" "c})
    4.         Dim check As Integer = 0
    5.  
    6.         For i As Integer = 0 To words.Count - 1
    7.             If words(i) = "Croatia" Then
    8.                 check = i - 1
    9.             End If
    10.         Next
    11.         For c As Integer = 0 To check
    12.             MsgBox(words(c) & " ")
    13.         Next
    14.     End Sub

    Hope it helps
    "In our profession, precision and perfection are not a dispensable luxury, but a simple necessity."
    Niklaus E. Wirth


    Rate any post that helped you, it's a good way of saying thanks
    Please specify your Visual Studio Version!

    Why rating is useful

    My Code Bank Submissions: How to determine Windows Version| Working With Mouse Events | Blocking Input Using API | Get host's IP | Minimize to system tray "animated" | Colored ListBox (custom fonts, colors, highlight) Updated -New Class! | [VS 2008] Strong encryption and hashing class - Updated! 31/August/2009 | Create a shortcut using IWshRuntimeLibrary

  10. #10
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    Re: Few Questions...

    That's way more complicated than required. All you need to do is check the position of the word "Croatia" in the string using the IndexOf method, and then extract the first part using the SubString method. It can be done in one line.

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