Results 1 to 3 of 3

Thread: Need help with simple project

  1. #1

    Thread Starter
    Lively Member Charlie Stallings's Avatar
    Join Date
    Nov 2009
    Location
    Virginia
    Posts
    118

    Thumbs up Need help with simple project

    ok guys i need some help i am trying to make a listbox load whats in the textbox but i want it to repeat the text after its added so like say if i have ! in the text box it would add this to the listbox
    !
    !!
    !!!
    !!!!
    !!!!!
    !!!!!!
    !!!!!!!
    and so on

    any help would be greatful
    If i help please rate me

    If Your Question Has Been Answered Please Mark Your Thread As RESOLVED So Other People (ME) Can Use The Helpful Tips As Well , Thanks

    New to VBForums? It's ok i was also at one point n time and i am still learning and meeting new people everyday check out the FAQ Section it is very helpful




    Sleep brings release and the hope of a new day - Killswitch Engage

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Need help with simple project

    you can try like
    vb Code:
    1. for i = 1 to x
    2.   mystr = mystr & text1
    3.   list1.additem mystr
    4. next
    where x is the number of items you want to add to listbox
    for a single character you can use
    list1.additem string(i, text1)
    in place of building a string
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3
    Lively Member Arispan's Avatar
    Join Date
    Apr 2010
    Location
    Greece, Near Athens
    Posts
    98

    Re: Need help with simple project

    Hello,

    There is a built-in VB6 function for this : String$(number as Long, Character) as String
    Example :
    You should have a command button (command1), a listbox (list1) and a textbox (text1)
    vb Code:
    1. Private Sub Command1_Click()
    2. Dim str As String
    3. Dim i As Integer
    4. i = 0
    5. 'The length of the text in the textbox should be only one char
    6. str = Text1.Text
    7. Do Until i = 7 ' This will be the number of items in
    8. 'the list. You may change it for more results
    9. i = i + 1
    10. List1.AddItem String$(i, str)
    11. Loop
    12. End Sub

    However, the String$ function only repeats one character. That means that the textbox's text should be only one char. And if it's not, the String$ function will repeat only the first character in it.
    MOBO: Asrock X58 Extreme
    CPU : Core i7 950 @ 3.07Ghz
    Ram : 8GB
    Hard Drive : 1.5 TB (1 TB, 500GB)
    Graphics : ATI Radeon HD 5670
    Dual Boot : Windows XP Home, Windows 7 Ultimate x64


    _____________________
    If a reply has helped you, please consider rating it.

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