Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Code condensing
#1
Not Solved
1) Is there a faster (i.e. shorter) way to accomplish this code, or is this the most condensed method?

2) Even if not more condensed, is there a better way?

3) Is there a way to compare values while ignoring empty space and being case insensitive?

The code compares text fields on a web page with values in a datatable. As the parameterized test goes down, it compares each row with the values in the text field.

Only the zprod value is entered into a text field, while the xprod value is autofilled out by the web page.
Code:
xprod = Browser("...").Page("...").WebEdit("txtName").GetROProperty("value")
zprod = Browser("...").Page("...").WebEdit("txtBr").GetROProperty("value")
xprodTbl = DataTable.Value ("A",dtLocalSheet)
zprodTbl = DataTable.Value ("B",dtLocalSheet)

If xprod = xprodTbl AND  zprod = zprodTbl Then
    Reporter.ReportEvent micPass, "Match", "Values in field match values in Table"
    Else
    Reporter.ReportEvent micFail, "Don't Match", "Values in field do not match values in Table"
End If
Reply
#2
Not Solved
Hi,
If you want to compare multiple values I would suggest you to use Dictionary object.

And to avoid spaces you can use Trim function and to make the comparision case insensitive you can use lcase or Ucase on both the values to be compares that way it will convert the value in lower case or upper case and you can compare them.

let me know if u have any queries regarding this.
Reply
#3
Not Solved
I've looked at Dictionary objects before, but I'm not really clear on where to put the code (some have placed the code in a function library), I'm also not too clear on the benefits of using it (over what is listed here), or how I would compare objects using it.

For simple item creation, i could write "x = [whatever]" or for a dictionary I'd have to write:
Dim x
Set x = [whatever]
and then some items here which I don't know their use.

So the dictionary term becomes quite longer than the simple "x = y"


As for trim and ucase, would this be the correct method?

Code:
xprod = Trim(UCase(Browser("...").Page("...").WebEdit("txtName").GetROProperty("value")))
zprod = Trim(UCase(Browser("...").Page("...").WebEdit("txtBr").GetROProperty("value")))
xprodTbl = Trim(Ucase(DataTable.Value ("A",dtLocalSheet)))
zprodTbl = Trim(Ucase(DataTable.Value ("B",dtLocalSheet)))

That doesn't seem quite right.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)