SPONSORS:






User Tag List

Thanks Thanks:  0
Likes Likes:  0
Dislikes Dislikes:  0
Results 1 to 4 of 4
  1. #1
    Member
    Join Date
    Sep 2007
    Location
    Australia
    Posts
    357
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Clean up my code - this works but its ugly - whats the best way?

    restructure? Rename soem variables ? break it down to sub functions etc - just have drawn a blank as to the best way.....


    Public Function enterYourDetails (Stringparam, datarow)
    excelintdata = datarow
    Openparams=Split(Stringparam, "|")
    ApplicationUnderTest = Openparams(0)
    ApplicationEnv = Openparams(1)
    sFileName = Openparams(2)
    Brwser = Openparams(3)
    Componenttoprocess = Openparams(4)
    Set oAutoIt = CreateObject("AutoItX3.Control")
    oAutoIt.Run("C:\Unified Functional Testing\traytip.exe")
    tcid = "enter Your Details"
    oAutoIt.Run """C:\Unified Functional Testing\traytip.exe"" ""Run Status Message"" ""Going to process this = """ & vbCrlf & """" & tcid & """"

    Call GetExcelDataArray(Environment.Value("Resources")& "/" & ApplicationEnv & "/" & ApplicationUnderTest & "/" & ApplicationUnderTest&"_"&"TestFlow.xlsx", "DataFlow",1)

    Environment.Value("enterYourDetails") = Environment.Value("SheetArray")
    For Detailsint = 1 To Ubound(Environment.Value("enterYourDetails"),1) Step 1
    If True Then
    Environment.Value("enterYourDetails")(Detailsint,1 )="enterYourDetails"
    Exit for
    End If
    Next

    '##########################################
    'Enter Details
    For Deatilstoenterint = 2 To Ubound(Environment.Value("enterYourDetails"),2) Step 1
    If Environment.Value("enterYourDetails")(Detailsint,D eatilstoenterint) <> "#EOF" Then
    For DataHeaders = 2 To UBound(Environment.Value("AutomationTestCaseData") ,2) Step 1
    If Environment.Value("AutomationTestCaseData")(2,Data Headers) <> "#EOF" then
    If Environment.Value("AutomationTestCaseData")(2,Data Headers) <> "" Then
    If Environment.Value("AutomationTestCaseData")(2,Data Headers) = Environment.Value("enterYourDetails")(Detailsint,D eatilstoenterint) Then
    ObjectClass = split(Environment.Value("AutomationTestCaseData")( 1,DataHeaders),"|")
    Select Case ObjectClass(0)
    Case "Class Name:=WebEdit"
    Call SWWebEdit (ObjectClass(1),Environment.Value("AutomationTestC aseData")(excelintdata,DataHeaders),0)
    DataHeaders = UBound(Environment.Value("AutomationTestCaseData") ,2)
    Case "Class Name:=WebRadioGroup"
    call SWRadioGroup (ObjectClass(1),Environment.Value("AutomationTestC aseData")(excelintdata,DataHeaders),0)
    DataHeaders = UBound(Environment.Value("AutomationTestCaseData") ,2)
    Case else
    Report "Fail", ObjectClass(1), "Column Read = " & Environment.Value("AutomationTestCaseData")(exceli ntdata,DataHeaders), Environment.Value("AutomationTestCaseData")(exceli ntdata,DataHeaders), "Row = " & iRow
    End Select

    Exit for
    End if
    Else
    Exit for
    msgbox "didn't find the SWKeyword looking for"
    End If
    End if
    Next
    End If
    Next

  2. #2
    Moderator
    Join Date
    Sep 2001
    Location
    Doncaster, UK
    Posts
    5,809
    Post Thanks / Like
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0
    I would defo replace those nested if's with Select/Case statements, it reads better and is more flexible, you could then replace the Msgbox with a Case Else statement.

  3. #3
    Member
    Join Date
    Sep 2007
    Location
    Australia
    Posts
    357
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0
    Quote Originally Posted by mwsrosso View Post
    I would defo replace those nested if's with Select/Case statements, it reads better and is more flexible, you could then replace the Msgbox with a Case Else statement.
    I will do that - its kinda slow going as I've been given an I3 with 4gb memory to develop with.........

  4. #4
    SQA Knight
    Join Date
    May 2006
    Location
    Playa Del Rey, California, United States
    Posts
    2,619
    Post Thanks / Like
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Total Downloaded
    0
    My advice is try to avoid nested if/else and nested loops. Use functions instead.

    When you have a nested loop, there's probably some higher level logic that can be abstracted.

    Ex:
    Code:
    For Deatilstoenterint = 2 To Ubound(Environment.Value("enterYourDetails"),2) Step 1
      itemInDetails = Environment.Value("enterYourDetails")[DetailsToEnterIn]
      ProcessDetails(itemInDetails)
    Next
    The key to good code is no one is going to remember what the heck you were writing a year from now. Try to make it read like poetry.

    I find the best code looks somewhat like haikus. Loops tend to have 5 parts in the beginning, followed by a 7 words in some sort of method call, followed by a 5 word comment line summarizing the business logic.
    Code:
      for (each item in queue) {
        PolishFinishedItem(Color.black, Texture.shiny);
        //Luxury Item specifications for Spain
      }
    David Lai
    SDET / Consultant
    LinkedIn profile

 

 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Search Engine Optimisation provided by DragonByte SEO v2.0.36 (Pro) - vBulletin Mods & Addons Copyright © 2017 DragonByte Technologies Ltd.
Resources saved on this page: MySQL 12.50%
vBulletin Optimisation provided by vB Optimise v2.6.4 (Pro) - vBulletin Mods & Addons Copyright © 2017 DragonByte Technologies Ltd.
User Alert System provided by Advanced User Tagging v3.2.8 (Pro) - vBulletin Mods & Addons Copyright © 2017 DragonByte Technologies Ltd.
vBNominate (Lite) - vBulletin Mods & Addons Copyright © 2017 DragonByte Technologies Ltd.
Feedback Buttons provided by Advanced Post Thanks / Like (Pro) - vBulletin Mods & Addons Copyright © 2017 DragonByte Technologies Ltd.
Username Changing provided by Username Change (Free) - vBulletin Mods & Addons Copyright © 2017 DragonByte Technologies Ltd.
BetaSoft Inc.
Digital Point modules: Sphinx-based search
All times are GMT -8. The time now is 06:06 PM.

Copyright BetaSoft Inc.