Results 1 to 3 of 3

Thread: How to optimize the following code

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2013
    Posts
    14

    How to optimize the following code

    Hi, I have a code which is redundant. Sp please help me in optimizing the code.

    Basically I am feting a fetching a version number from registry. It can be in any of one of 6 path. So I am iterating like below code. I feel there can be something better than this. Please help me to optimize the below code.

    Private Function as Integer()

    'Some Code
    versionnum = GetRegValue (hKey,path1,"Version","")

    If versionnum = "" Then
    versionnum = GetRegValue (hKey,path2,"Version","")
    EndIf

    If versionnum = "" Then
    versionnum = GetRegValue (hKey,path3,"Version","")
    EndIf

    If versionnum = "" Then
    versionnum = GetRegValue (hKey,path4,"Version","")
    EndIf

    If versionnum = "" Then
    versionnum = GetRegValue (hKey,path5,"Version","")
    EndIf

    If versionnum = "" Then
    versionnum = GetRegValue (hKey,path6,"Version","")
    EndIf

    returnval = CompareVersion(Expected,versionnum)
    'Some Code

    End Function

  2. #2
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Re: How to optimize the following code

    Code:
    Private Function ReturnVal() As Integer
        Dim i As Single
    
        For i = 1! To 6!
            VersionNum = GetRegValue(hKey, Choose(i, Path1, Path2, Path3, Path4, Path5, Path6), "Version", vbNullString)
            If LenB(VersionNum) Then Exit For
        Next
    
        ReturnVal = CompareVersion(Expected, VersionNum)
    End Function
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  3. #3

    Thread Starter
    New Member
    Join Date
    Sep 2013
    Posts
    14

    Re: How to optimize the following code

    Quote Originally Posted by Bonnie West View Post
    Code:
    Private Function ReturnVal() As Integer
        Dim i As Single
    
        For i = 1! To 6!
            VersionNum = GetRegValue(hKey, Choose(i, Path1, Path2, Path3, Path4, Path5, Path6), "Version", vbNullString)
            If LenB(VersionNum) Then Exit For
        Next
    
        ReturnVal = CompareVersion(Expected, VersionNum)
    End Function
    Thank you so much

Tags for this Thread

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