aspose file tools*
The moose likes Java in General and the fly likes Need help with Array (setting variable) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Need help with Array (setting variable)" Watch "Need help with Array (setting variable)" New topic
Author

Need help with Array (setting variable)

Laura Wells
Greenhorn

Joined: Sep 14, 2005
Posts: 12
I'm working with Java inside Rational XDE Test tool. I need help with my Java code. I wasn't sure if this was a beginner question or immediate.

What I need to do is 1) instead of returning the values in the table in the same variables (rawdata, text and after) is there anyway I can set each value from the HTML table with a unique variable name? Maybe set something in the array? 2) Toward the bottom of this HTML table I'm reading in - there is a Branch Total value I need to get the value of. How do I pull off a specific value for that row and column. I know this Branch Total row is the second row from the bottom of the table.

Here's my code:



(Marilyn added code tags)
[ September 15, 2005: Message edited by: Marilyn de Queiroz ]
Norm Radder
Ranch Hand

Joined: Aug 10, 2005
Posts: 687
    
    1
Sorry, I don't understand the input for your question and there's alot of code to wade through. Being lazy, I like you to
Could you reduce your question to something smaller and simpler?
For example:
How do I create a 10 element array and add elements to it?
String[] tenEl = new String[10];
tenEl[0] = "an el";

Or is your problem with how to get the input?
Laura Wells
Greenhorn

Joined: Sep 14, 2005
Posts: 12
Sorry for the long winded note. I didn't know what code I should include. Thank you for responding. I'll try to shorten and be more to the point with my question if I can.

I have the input. I consider that to be my HTML table (with the code below).
ITestDataTable revenueTable; revenueTable =
(ITestDataTable)Table_HtmlTable_9().getTestData("grid");

My question is - how do I get a specific value off that table. The value I need is at the bottom of the table in the column 3, the row that starts with 'Branch Total'.

The following will read in all rows except for the last 3 rows of the table.
for (int row=0, rowCount = revenueTable.getRowCount(); row < rowCount -3; ++row) {

Now, should I create another for loop so I can pull the second to the last row of data? If so, how do I do this? should I do this based on the rowcount -2?

Or can it do it based on row, col to identify specific cell? The only problem is that the rows may change so that this value may not always be in the same row. It iwll always be in the same column but if there is more data the total lines on the report (html table) will be pushed down.

Or should I do this completely different. Someone mentioned using a try/catch statment. I just need something that will work - doesn't have to be the best option. I can always tweak the code later.

If that still is not enough info - I can provide info on what the report/HTML table looks like.
Thanks!
Laura
Norm Radder
Ranch Hand

Joined: Aug 10, 2005
Posts: 687
    
    1
Sorry, I am still not understanding your source of data. Sounds like SQL (which I don't know) with rows and columns and cells.
The original title suggested a problem with Arrays, but if its the source of the data that's the problem, I can't help.
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
After looking at your code, it looks like the ITestDataTable interface has a getCell() method. So you can use the variable named revenueTable to call this method and get the data directly. If you only need a cell from the third-to-last row, you don't need a loop to go through all the rows before it. You can specify the value directly to the getCell() method:

If you set the col varible used above to the value of the column you need, then you will get the value you want.

Does this answer your question?

Layne


Java API Documentation
The Java Tutorial
Laura Wells
Greenhorn

Joined: Sep 14, 2005
Posts: 12
Great! Yes, I tried that and it works!

Thank you!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Need help with Array (setting variable)