Results 1 to 10 of 10

Thread: Little Code Thing

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2003
    Location
    World!
    Posts
    112

    Little Code Thing

    Hello all, how are you? Ok I have a question concering if the code In my program is to much and can be shorter if its bad or what not?
    VB Code:
    1. Dim ArrItems As Variant
    2. Dim I As Integer
    3.     ArrItems =
    4.  
    5. Array(""Mr.","The-","www.","Dr","Dr+","Dr.""pimp.","yahoo.","name.","login.","login-","login+","name+","my+","sos+","*****+","pimp+","freak+","lucky+","Mister+","Mrs+","cool+","bad+","****.","****+","Da-","name-","Mrs.","Cool-","Yahoo-","Miss-","Mister-","Master-","Boy-","Kid-","Guy-","Lady-","Woman-","Girl-","krack-","crack-","Goth-","Gothic-","Group-","Idol-","Erotic-","Era-","Main-","Satan-","Hero-","Evil-","Happy-","Fun-","Funny-","Doctor-","King-","Dog-","Dogg","420","187","Mr.+","The+","Dr.+","Da+","Mrs.+","Cool+","Yahoo+","Miss+","Mister+","Master+","Boy+","Kid+","Guy+","Lady+","Woman+","Girl+","Happy+","Fun+","Funny+","Doctor+","King+","Dog+","Dogg+","Pimp.+","420+","187+","yahoo_")
    6.     For I = 0 To UBound(ArrItems)
    7.         List1.AddItem ArrItems(I) & Text1.Text
    8.     Next I

    So Im wondering if this code can be made shorter or more useful? Thanks in advance for some help and its very much appreciated. Have a good day
    Have A Good Day

  2. #2
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    You mean this way :
    VB Code:
    1. Array(""Mr.","The-","www.","Dr","Dr+","Dr.""pimp.","yahoo.", _
    2. "name.","login.","login-","login+","name+","my+","sos+" _
    3. ,"*****+",
    4. "pimp+","freak+","lucky+","Mister+","Mrs+","cool+", _
    5. "bad+","****.","****+","Da-","name-","Mrs.","Cool-", _
    6. "Yahoo-","Miss-","Mister-","Master-","Boy-","Kid-","Guy-" _
    7. ,"Lady-","Woman-","Girl-","krack-","crack-","Goth-","Gothic-","Group-","Idol-","Erotic-","Era-","Main-","Satan-","Hero-", _
    8. 'etc .......

  3. #3
    Frenzied Member
    Join Date
    Jan 2000
    Location
    Bellevue, WA, USA
    Posts
    1,357
    It looks pretty short, but usefull is up to you

    It would be more efficient (faster) to add the items into the list box 1 directly instead of writing them to an array and then looping through the array and adding them to the list box in the loop, unless you need them in an array for some other reason.
    ~seaweed

  4. #4
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    either you store them in a file or in a database !

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Mar 2003
    Location
    World!
    Posts
    112
    No I dont but I thought it would be faster then:
    VB Code:
    1. List1.Additem Text1.Text & "*****"
    2. List1.AddItem Text1.Text & "Mrs"

    I thought that would be worse because its a lot more code and stuff? So I dont need an array so would you suggest it this way or another? Thanks in advance for some help man
    Have A Good Day

  6. #6
    Fanatic Member Geespot's Avatar
    Join Date
    Oct 2001
    Location
    Birmingham, UK
    Posts
    577
    Originally posted by NoobieVb
    No I dont but I thought it would be faster then:
    VB Code:
    1. List1.Additem Text1.Text & "*****"
    2. List1.AddItem Text1.Text & "Mrs"

    I thought that would be worse because its a lot more code and stuff? So I dont need an array so would you suggest it this way or another? Thanks in advance for some help man
    Lesson 1. More code doesn't always equal slower

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Mar 2003
    Location
    World!
    Posts
    112
    Hehe yes I know so now im just curious which ones more effecinece and betetr to use all the long code List1.AddItem or the array? Thanks in advance for some help I really appreciate it
    Have A Good Day

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Mar 2003
    Location
    World!
    Posts
    112
    ANyone at all please? Id really appreciate it
    Have A Good Day

  9. #9
    Fanatic Member Geespot's Avatar
    Join Date
    Oct 2001
    Location
    Birmingham, UK
    Posts
    577
    Originally posted by NoobieVb
    ANyone at all please? Id really appreciate it
    Lesson 2: All in good time

    ok enough with the lessons

    try making a quick program to measure the times between them.
    Also if you not going to be continuly calling the code, you might aswell leave it because if it only gets called once, you only gonna save about 0.00000000001 seconds for one of the methods.

  10. #10
    Frenzied Member
    Join Date
    Jan 2000
    Location
    Bellevue, WA, USA
    Posts
    1,357
    Originally posted by NoobieVb
    No I dont but I thought it would be faster then:
    VB Code:
    1. List1.Additem Text1.Text & "*****"
    2. List1.AddItem Text1.Text & "Mrs"

    I thought that would be worse because its a lot more code and stuff? So I dont need an array so would you suggest it this way or another? Thanks in advance for some help man
    The "more code" solution is faster. Your shorter version does the exact same thing, except it also creates an array, fills the array, and then accesses each item of the array.

    The reason yours looks "faster" is because the AddItem step is performed in a loop, instead of written out one line at a time.
    ~seaweed

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