Confused about why using Java...

Hi,

I have programmed in other languages before(Visual Basic, PHP, SQL...), but all of them had a lot of libraries of functions so for example you can do anything you want with strings and dates, etc...

If I understand right, with Java if I want to compare two dates and figure out what´s the difference in days between them I have to create a function myself because there isn´t one already created?

I am wondering if I should use Javascript instead for Screen-Scraper scripting. In what case would I want to use one or the other?

(I am asuming that I cannot mix both in the same screenscraper script)

Thanks!

bogavante, Yes, you are

bogavante,

Yes, you are correct. Java does not have the same ready-made functions as some other programming languages. And, yes, you cannot mix languages within the same script. You can, however, have one script written in JavaScript and another written in Interpreted Java where one saves the result of a function as a session variable and the other refers to that session variable.

Here is an example script written in Interpreted Java which you should be able to modify for different date comparison purposes you have.

import java.util.Date;
import java.util.Locale;
import java.util.Calendar;
import java.text.SimpleDateFormat;

// For date formatting
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");

// Local reference to variables
dateStart       = session.getVariable("DATE_START");
dateEnd         = session.getVariable("DATE_END");

// Parse to date
Date d  = sdf.parse(dateStart);
Calendar dateStart = Calendar.getInstance();
dateStart.setTime(d);
Date e  = sdf.parse(dateEnd);
Calendar dateEnd = Calendar.getInstance();
dateEnd.setTime(e);

session.logInfo("==================================================");
session.logInfo("Search start date: " + d);
session.logInfo("To end date: " + e);
session.logInfo("==================================================");

while( dateStart.before(dateEnd)/* || dateStart.equals(dateEnd) */)
{
        // Log
        ds = sdf.format(dateStart.getTime());
        end = dateStart.clone();
        end.add(Calendar.DATE, 1);
        de = sdf.format(end.getTime());
       
        session.logInfo("===Starting date=====");
        session.logInfo("=== " + ds + " ======");
       
        // Set vars
        session.setVariable("DATE", ds);
        session.setVariable("DATE_NXT", de);
  session.executeScript("start CSV");
 
        // Scrape
        session.scrapeFile("Report");
        session.scrapeFile("Pre-results");
        session.scrapeFile("Results");
       
        // Update date start
        dateStart.add(Calendar.DATE, 1);
}

Hope this helps,
Scott

Thank you Scott. I will look

Thank you Scott. I will look into this interpreted Java example to see how I can make use of it, and play a little bit with using a Javascript script containing a Javascript script and communicate the parameters and return value with a Java script(this is starting to look like a riddle :) ) using session variables and session.executescript

Besides, I am interested to know, if I choose to use Javascript for everything or mostly everything instead of Java. Will I be limited and in what way?

Thanks!
Boga

Boga, If you choose to use

Boga,

If you choose to use Javascript instead of Interpretive Java I don't believe you will experience any limitations. We don't use Javascript very much internally so I can't speak to any type of performance hit.

It's entirely up to you which language you use. If you experience any issues please let us know. We love receiving bug reports.

-Scott

I think I will be using a bit

I think I will be using a bit of both ;-)
thanks,
boga