Results 1 to 12 of 12

Thread: Please help me for optimize my code.

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2007
    Posts
    227

    Please help me for optimize my code.

    Dear all expert programmers,
    Please look part of my code. My code is not complete and I think it make slow but I can't optimize. Please help me.




    Code:
    strFixvalue="abcdefghi"
    LimitEnd=len(strFixvalue)
    
    For bstart = bLow To LimitEnd
                    For cstart = cLow To LimitEnd
                        For dstart = dLow To LimitEnd
                            For estart = eLow To LimitEnd
                                For fstart = fLow To LimitEnd
                                    For gstart = gLow To LimitEnd
                                        For hstart = hLow To LimitEnd
                                            Do
                                                DoEvents
                                                If blnStop = False Then
                                                    If Pause Then
                                                        'Statment
                                                    Else
                                                        strnewConcat = Mid$(strFixvalue, bstart, 1) & Mid$(strFixvalue, cstart, 1) & Mid$(strFixvalue, dstart, 1) & Mid$(strFixvalue, estart, 1) & Mid$(strFixvalue, fstart, 1) & Mid$(strFixvalue, gstart, 1) & Mid$(strFixvalue, hstart, 1)
                                                        lblstatus.Caption = strnewConcat
    													'Statment
                                                    End If
                                                Else
                                                    Exit Sub
                                                End If
                                            Loop While Pause
                                        Next
                                        If hstart > LimitEnd Then hLow = gstart + 1
                                    Next
                                    If gstart > LimitEnd Then gLow = fstart
                                Next
                                If fstart > LimitEnd Then fLow = estart
                            Next
                            If estart > LimitEnd Then eLow = dstart
                        Next
                        If dstart > LimitEnd Then dLow = cstart
                    Next
                    If cstart > LimitEnd Then cLow = bstart
                Next
    Thank you for all posts.

  2. #2
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: Please help me for optimize my code.

    Well you would need to give us some details on what this is supposed to be doing and what some of those values may be. Just looking at the code can't tell much from the code posted. A lot of nested loops there. If those values are large then it definitely could be slow.

  3. #3
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,253

    Re: Please help me for optimize my code.

    Quote Originally Posted by DataMiser View Post
    Well you would need to give us some details on what this is supposed to be doing ...
    If I'd have to make a guess (and given the OPs last posts about "Web-stuff"), the whole thing looks like
    a "password-cracker" (producing all kind of Char-combinations on a given baseString with a given length).

    @the OP
    Sorry for this "wild guess" - but if it isn't then I'd surely like to hear, for what purpose you need these Char-combos.

    Olaf

  4. #4
    Frenzied Member
    Join Date
    May 2014
    Location
    Kallithea Attikis, Greece
    Posts
    1,289

    Re: Please help me for optimize my code.

    The scope isn't needed. The answer is that this approach, to feed a caption a string as all combinations for a series of letters, is wrong.
    What you need is a function where an input value give a combination. How this is possible? Using mod and div. Vb6 has \ as div.So if the right most letter can use 20 chars then you need to read n mod 20. So you have a number from 0 to 19. Then you do a divide n\20. Now you go for the next letter. The last letter will be the most left.
    Why is better a function from the nested for? Because you can make a timer to generate the next number. So you can use it like a background task.
    You can't pause a series of nested for. And the doevents...is a fault also. You use it because you grant the process in an event. So send process as a slice in a timer event and this is.

  5. #5
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: Please help me for optimize my code.

    Actually yes the scope is needed, that code looks horrendous and I surely would not take the time to try an determine exactly what it is meant to do without the poster taking some time to give some details on it.

    As for the method described in post #4 as usual it is hard to follow and more confusing than enlightening.

  6. #6
    Frenzied Member
    Join Date
    May 2014
    Location
    Kallithea Attikis, Greece
    Posts
    1,289

    Re: Please help me for optimize my code.

    Datamiser,
    The code I am sure isn't a password cracker...
    Can you follow what I wrote in #4?

  7. #7
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,253

    Re: Please help me for optimize my code.

    Quote Originally Posted by georgekar View Post
    The code I am sure isn't a password cracker...
    Well, to me (after making it work here, and using a few Debug.Prints) it still looks that way -
    but as long as the OP doesn't give a good reason - or what he wants to accomplish with
    that horribly nested looping, we can only speculate.

    Quote Originally Posted by georgekar View Post
    Can you follow what I wrote in #4?
    As usual with everything you post, it *is* hard to follow (and sometimes entirely out of context)
    ... Aside from that, since we don't know yet what the OP really wants to do, it is entirely pointless
    to post any advice with regards to certain, more optimized algorithms.

    Olaf

  8. #8
    Frenzied Member
    Join Date
    May 2014
    Location
    Kallithea Attikis, Greece
    Posts
    1,289

    Re: Please help me for optimize my code.

    Olaf,
    thank you for your answer. About the OP code, it is obvious that it isn't password cracker because no one can use 6 char length as password, and the combinations are too many...to check every in a life. Supposed we have 26 chars.26 power 6 is 308915776...308 millions. 308 millions pings...is a lot of time....About 3.5 days with 1ms ping time. Make that tImes 100...need one year. And if owner change password every month? So I suspect this code is for lottery..

  9. #9
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Please help me for optimize my code.

    Yep, looks like the OP is trying to get the permutations from a set of characters. As far as optimizing, the OP may want to search this forum and google for keywords like: permutations. Depending on length & whether repetition is allowed, one is looking at a time-consuming process, optimized or not.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  10. #10
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Please help me for optimize my code.

    Quote Originally Posted by georgekar View Post
    So I suspect this code is for lottery..
    I doubt that. Permutations don't work for a lottery. A lottery has a finite number of selections. Each selection is a random pick from a list of remaining numbers. Permutations can be used for cracking passwords/combinations or for solving anagrams & games like "Jumble". But for a lottery type application, better to use logic like:
    Code:
    For n = 1 to nrSelections
        randomly select from a list of numbers
        remove number from list
    Next
    Edited: I said permutations don't work for lotteries. A better statement would've been that permutations are the wrong tool for lotteries.
    Last edited by LaVolpe; Dec 20th, 2014 at 05:29 PM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Aug 2007
    Posts
    227

    Re: Please help me for optimize my code.

    Dear sir,
    My code want output below.

    If strFixvalue="abcdefghi" that mean

    1. Will loop to display aaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaab, aaaaaaaaaaaaaaaaaaac on label caption until complete but if user press stop button it will stop process. If user not press stop button will show lblstatus.Caption = strnewConcat and call some statment, example

    lblstatus.Caption = strnewConcat
    call showSpecialResult(strnewconcat)
    .....


    2. In showSpecialResult that containt many statment to show data in unlimit arrays and need to get parameter from strnewConcat to process.

  12. #12
    Frenzied Member
    Join Date
    May 2014
    Location
    Kallithea Attikis, Greece
    Posts
    1,289

    Re: Please help me for optimize my code.

    @lavolpe,
    There are lotteries that you win more if you have plus 3 and or minus 3. And that is for lottery company a 3pla lottery...So perhaps you have a game that has a lottery stage, how you can display 3pla numbers?
    For more professional gamblers there are configurations of lower value games which have numbers that are excluded from a list by using a pattern or other logical comparisons. So for that reason a generator for that numbers needed. This can be used for random picks too. Or to simulate the lottery.

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