You are not logged in.

Dear visitor, welcome to Jabaco - Community. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

scGuy

Beginner

  • "scGuy" started this thread

Posts: 40

Date of registration: Jan 12th 2011

  • Send private message

1

Thursday, January 13th 2011, 6:36pm

Is VB and VBA implementation documented?

Is there a master document that indicates which subroutines and functions from VB and VBA have been implemented in Jabaco? I don't see any docs here or in my installation. I tried a few functions at random and figured out that it appears things are missing--an example would be date functions like IsDate, DateDiff, etc...



Anyone have a quick reference that simply lists which funcitons I can expect to use in Jabaco?



Thanks

A1880

Intermediate

  • "A1880" is male

Posts: 500

Date of registration: Jan 1st 2009

Location: Hanover, Germany

Occupation: Software Engineer

Hobbies: Hilbert Curves

  • Send private message

2

Thursday, January 13th 2011, 9:44pm

Documentation is a weaker point in Jabaco.
Many cases have been discussed in this forum. Make use of the search facility.
There is a first attempt to implement DateDiff.

The advantage compared to VB6 and VBA is that Jabaco's framework is open.
You can always have a look at the source to find out how things work out in detail.

Cheers

A1880

theuserbl

Intermediate

Posts: 436

Date of registration: Dec 20th 2008

  • Send private message

3

Friday, January 14th 2011, 5:36pm

Shit have edited me post. Wantet to reply it.
Ok. My last post was, that I am not sure, which will be better.

There existing already a VBA/DateTime.java , which have not all implemented.
And I am not sure, if it would be better to take the original one and modify it or to delete the VBA/DateTime.java and creating your VB/DateTime.jsrc instead of it.

Also I have thanked you, that you have mentioned your nice code again, so that I am remembered, that it would be a nice idea, to upload it in svn.

My last post ends with the comment "Not sure, which is at this point the best. :S". I meaned if it is better update DateTime.java or to crate a new *.jsrc file and deleting DateTime.java.

Then I wrote this answer:
-------------------------------------------------------------


Not sure, which is at this point the best. :S


Personally I tend to integrate it in the existing Java-file, instead of creating a new (Jabaco) file and deleting therefore the existing one.

Here is the Java-port of your file

Jabaco Source

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import VBA.*;
import java.text.*;
import java.util.*;

public class DateTime
{

  public static long DateDiff(String Interval, VBVariant Date1, VBVariant Date2)
  {
    // Gibt die Anzahl der Zeitintervalle zwischen zwei Datumsangaben zurück

    // returns the amount of timespans between the two dates
    // Interval: a string representing the kind of time
    // Date1: one end of the timespan
    // Date2: the other end of the timespan

    // note: does not consider different first days of the week

    return DateVal(Interval, Date2) - DateVal(Interval, Date1);
  }

  private static long DateVal(String Interval, VBVariant d) {
    Date d1 = (Date)d.toObject();
    long sec = Conversion.CLng(VBVariant.valueOf(d1.getTime() * 0.001));
    int y = d1.getYear();
    long ret = 0;

    if (Interval.equals("s"))
      ret = sec;
    else if (Interval.equals("n"))
      ret = Conversion.CLng(VBVariant.valueOf(sec / 60));
    else if (Interval.equals("h"))
      ret = Conversion.CLng(VBVariant.valueOf(sec / 3600));
    else if (Interval.equals("d") || Interval.equals("y"))
      ret = Conversion.CLng(VBVariant.valueOf(sec / (24 * 3600)));
    else if (Interval.equals("w") || Interval.equals("ww"))
      ret = y * 52 + getWeekShort(d1);  // quick hack! not correct for multiple-year diffs
    else if (Interval.equals("m"))
      ret = 12 * y + d1.getMonth();
    else if (Interval.equals("q"))
      ret = 4 * y + d1.getMonth() / 4;
    else if (Interval.equals("yyyy"))
      ret = y;
    else {
      System.out.println("DateVal: unknown interval '" + Interval + "'");
      ret = 0;
     }

    return ret;
  }

  public static Date Now()
  {
    return Calendar.getInstance().getTime();
  }

  public static Date DateSerial(int year, int month, int day)
  {
    // beim java.util.GregorianCalendar ist der Monat nullbasiert, d.h. Januar
    Date DateSerial = new GregorianCalendar(year, month - 1, day).getTime();
    return DateSerial;
  }

  private static int getWeekLong(Date d) {
    //  Return year of the week
 
    int week = getWeekShort(d);
    Calendar cal = Calendar.getInstance();
    int month = 0;
    int year = 0;

    cal.setTime(d);
    month = cal.get(Calendar.MONTH);
    year = cal.get(Calendar.YEAR);

    if ( (week == 1) && (month == Calendar.DECEMBER) )
      year += 1;
    else if ( (week >= 52) && (month == Calendar.JANUARY) )
      year -= 1;

    return 100 * (year % 10) + week;
  } 

  private static int getWeekShort(Date d) {
    Calendar cal = Calendar.getInstance();

    cal.setTime(d);
    return cal.get(Calendar.WEEK_OF_YEAR);
  }

  public static void DateDiffTest() {
    ddt("s", "01.07.2009 10:00:00", "01.07.2009 10:01:00", 60);
    ddt("n", "01.07.2009 10:00:00", "01.07.2009 10:01:00", 1);
    ddt("h", "01.07.2009 10:00:00", "01.07.2009 11:00:00", 1);
    ddt("d", "01.07.2009 10:00:00", "02.07.2009 10:01:00", 1);
    ddt("d", "01.07.2009 10:00:00", "12.07.2009 10:01:00", 11);
    ddt("y", "01.07.2009 10:00:00", "02.07.2009 10:01:00", 1);
    ddt("w", "01.07.2009 10:00:00", "09.07.2009 10:01:00", 1);
    ddt("ww", "01.07.2009 10:00:00", "09.07.2009 10:01:00", 1);
    ddt("m", "01.07.2009 10:00:00", "01.08.2009 10:01:00", 1);
    ddt("q", "01.07.2009 10:00:00", "01.10.2009 10:01:00", 1);
    ddt("yyyy", "01.07.2009 10:00:00", "01.07.2010 10:01:00", 1);
    ddt("yyyy", "01.07.2009 10:00:00", "01.07.2011 10:01:00", 2);
  }

  private static void ddt(String Interval, String ds1, String ds2, long ret) {
    try {
      DateFormat df = (DateFormat)new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
      Date d1 = df.parse(ds1);
      Date d2 = df.parse(ds2);
      long d = DateDiff(Interval, VBVariant.valueOf(d1), VBVariant.valueOf(d2));

      if (d != ret) {
        System.out.println("d1: " + d1);
        System.out.println("d2: " + d2);
        System.out.println(Interval + ": "+ ds1 + " - " + ds2 + " = " + d + " <> " + ret);
      }

    } catch (java.text.ParseException e) {
            System.out.println(e);
    }
  }

  public static void main(String[] args) {
    DateDiffTest();
  }
}


The next step will be to fusion this file with the existing file...

Or do you think, it would be better to take your original Jabaco source instead of this Java port? :S

Still not really sure, what will be better.
Some suggestions?

This post has been edited 5 times, last edit by "theuserbl" (Jan 14th 2011, 9:29pm)


A1880

Intermediate

  • "A1880" is male

Posts: 500

Date of registration: Jan 1st 2009

Location: Hanover, Germany

Occupation: Software Engineer

Hobbies: Hilbert Curves

  • Send private message

4

Friday, January 14th 2011, 9:26pm

I don't mind.
The Java version is probably more efficient and might be easier to maintain.

The Jabaco version demonstrates the power of Jabaco.
We could remove all public functions and just let DateDiff survive.

Thanks for your initiative!

Greetings

A1880

theuserbl

Intermediate

Posts: 436

Date of registration: Dec 20th 2008

  • Send private message

5

Friday, January 14th 2011, 10:05pm

We could remove all public functions and just let DateDiff survive.


Done:
http://code.google.com/p/jabacoframework…A/DateTime.java

theuserbl

Intermediate

Posts: 436

Date of registration: Dec 20th 2008

  • Send private message

6

Friday, January 14th 2011, 10:25pm


scGuy

Beginner

  • "scGuy" started this thread

Posts: 40

Date of registration: Jan 12th 2011

  • Send private message

7

Saturday, January 15th 2011, 2:25am

Good to know people are still involved, this is a fun tool to play with. I'm a little confused in general about some other compatibility issues--since there was no IsDate function that I could see, I thought I'd write my own by simply doing the following:



Function MyIsDate(sData as String) as Boolean



Dim dTemp as Date

On Error Goto NotADate



dTemp=CDate(sData)

MyIsDate=True

Exit Function



NotADate:

MyIsDate=False



End Function



However, this totally did not do what I expected. I expected that if I had a nonsense value in sData, CDate would throw an error and I could return false, otherwise if CDate was successful, return a true because it must be a valid date. Instead, when a nonsense value was in sData, no errors occurred. The dTemp variable ended up with the current date/time, as if I had used "Now". So in the end a little confused.



That aside, I would be willing to start a quick reference that would simply be a table of every VB statement I can think of, whether Jabaco supports it, or what a Jabaco equivalent would be...

A1880

Intermediate

  • "A1880" is male

Posts: 500

Date of registration: Jan 1st 2009

Location: Hanover, Germany

Occupation: Software Engineer

Hobbies: Hilbert Curves

  • Send private message

8

Saturday, January 15th 2011, 11:41am

In such cases, one can always look at the framework sources.

CDate is implemented as follows in VBA.Conversion.java:

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
        public static java.util.Date CDate(VBVariant Expression) {
                if (Expression.isDate()) return (Expression.toDate());
                return CDate(Expression.toString());
        }
        public static java.util.Date CDate(String Expression) {
                java.util.Date ret = null;
                for (int i = 0; i < CheckDatePatterns.length; i++) {
                        for (int x = 0; x < CheckDatePatterns[i].length; x++) {
                                ret = CreateDateFormater(Expression, Join(CheckDatePatterns[i], CheckDatePatterns[i].length - x));
                                if (ret != null) { return ret; }
                        }
                }
                return new java.util.Date();
        }
        public static VBVariant CDate(Object obj) {
                return new VBVariant(obj);
        }


So, there is no way to get an exception thrown.
You are right. Nonsense date strings should end up in an error.
What is the exact behaviour of CDate in VB6?

Happy experimenting!

A1880

scGuy

Beginner

  • "scGuy" started this thread

Posts: 40

Date of registration: Jan 12th 2011

  • Send private message

9

Saturday, January 15th 2011, 9:53pm

Well, for questions like "what would vb6 do?" I finally feel qualified to answer! If it is a nonsense string value, it will cause a "type mismatch" error. Same is true of an empty string. A null value passed in causes "invalid use of null" error. A numeric value passed in (like integer or long) will actually be converted to a date, but as the internal storage of java dates vs vb dates may differ, this last one should probably not be supported, would prefer a "type mismatch" myself.

LuizRedes

Beginner

  • "LuizRedes" is male

Posts: 9

Date of registration: Jan 12th 2011

Location: Brazil

Occupation: Visual Basic Programmer

Hobbies: Drive Muscle Cars

  • Send private message

10

Monday, January 17th 2011, 6:15pm

Hello all!

I'm a newbie in Jabaco and i was reading here about date functions. Trying to do something to play with Jabaco here i got an error running the code:

text1.text = Date

This code in VB6 works fine but in Jabaco got an error, what is wrong here?
Sorry if my question is too simple, but i'm trying to learn how to use Jabaco to convert a Project in Visual Basic 6 to run in Linux, windows and Mac and this information is very important...
If exists any documentation about this, please, send me a link.

Thanks.

scGuy

Beginner

  • "scGuy" started this thread

Posts: 40

Date of registration: Jan 12th 2011

  • Send private message

11

Monday, January 17th 2011, 6:44pm

Hi, I had no idea that would work in VB6, I had to try it. Perhaps this was included in vb for backward compatibility/etc. The proper statement should really be:



Text1.text = Now



Which Jabaco should support.

LuizRedes

Beginner

  • "LuizRedes" is male

Posts: 9

Date of registration: Jan 12th 2011

Location: Brazil

Occupation: Visual Basic Programmer

Hobbies: Drive Muscle Cars

  • Send private message

12

Monday, January 17th 2011, 7:55pm

Thanks scGuy!

But now i have another question, how can i format the output of the constant "now"?
In VB6 i use the follow code:

text1.text = format(now, "YYYY-MM-DD")

The format returned is like: 2011-01-17

With Jabaco, the code returns an error in the text box:

java.util.GregorianCalendar[time=?,areFieldsSet=false,areAllFieldsSet=false,lenient=true,
zone=sun.util.calendar.ZoneInfo[id="America/Sao_Paulo",offset=-10800000,dstSavings=3600000,
useDaylight=true,transitions=129,lastRule=java.util.SimpleTimeZone[id=America/Sao_Paulo,
offset=-10800000,dstSavings=3600000,useDaylight=true,startYear=0,startMode=3,
startMonth=9,startDay=15,startDayOfWeek=1,startTime=0,startTimeMode=0,endMode=3,
endMonth=1,endDay=15,endDayOfWeek=1,endTime=0,endTimeMode=0]],firstDayOfWeek=2,
minimalDaysInFirstWeek=1,ERA=?,YEAR=2011,MONTH=0,WEEK_OF_YEAR=?,WEEK_OF_MONTH=?,
DAY_OF_MONTH=17,DAY_OF_YEAR=?,DAY_OF_WEEK=?,DAY_OF_WEEK_IN_MONTH=?,AM_PM=?,
HOUR=16,HOUR_OF_DAY=?,MINUTE=52,SECOND=28,MILLISECOND=0,ZONE_OFFSET=?,DST_OFFSET=?]

How can i format the output of the constant "now"?

Thanks

scGuy

Beginner

  • "scGuy" started this thread

Posts: 40

Date of registration: Jan 12th 2011

  • Send private message

13

Monday, January 17th 2011, 9:25pm

Oh, not surprising that Format isn't implemented in Jabaco, in VB it does nearly everything. See if this works:



text1.text=Year(Now) & "-" & Month(Now) & "-" & Day(Now)



That's not the best, I know, you'll lose leading zeros. But I just tried this, and it didn't work, returned very odd values. Obviously we need to remember that Jabaco is a work in progress, and not necessarily intended as an exact replacement of VB. Still, starting to be clear to me that date functions in general need a lot of work.

LuizRedes

Beginner

  • "LuizRedes" is male

Posts: 9

Date of registration: Jan 12th 2011

Location: Brazil

Occupation: Visual Basic Programmer

Hobbies: Drive Muscle Cars

  • Send private message

14

Tuesday, January 18th 2011, 3:02pm

OK scGuy, i tried here too and returned odd values...
Really, Jabaco is work in progress and in the case of date functions there is a lot of work to do.
But we still testing!!!


Thanks!

A1880

Intermediate

  • "A1880" is male

Posts: 500

Date of registration: Jan 1st 2009

Location: Hanover, Germany

Occupation: Software Engineer

Hobbies: Hilbert Curves

  • Send private message

15

Tuesday, January 18th 2011, 6:38pm

Thanks for the error hint!

This can be circumvented as follows:

Jabaco Source

1
2
3
4
5
6
7
8
9
Public Sub Command1_Click()
   Dim now As Date
   
   now = New Date() 

   Debug.Print now
   Debug.Print Year(now) & "-" & Month(now) & "-" & Day(now)
   Debug.Print Year(now) & "-" & Right("0" & Month(now), 2) & "-" & Right("0" & Day(now), 2)
End Sub


The "official" function "now" returns a DateTime value in Jabaco.
This is wrongly converted when used as "Date" parameter in functions.

Greetings

A1880

scGuy

Beginner

  • "scGuy" started this thread

Posts: 40

Date of registration: Jan 12th 2011

  • Send private message

16

Sunday, January 23rd 2011, 7:29pm

Please clarify in the code above: As a VB programmer, I consider a "Date" as a data type, not an object, therefore the "new" keyword would never be used. Dates are dim'd just like integers, etc... The above code includes "now = New Date()" which implies that the "Date" item in Jabaco is not a data type, but an object. Is this true?

Next question: would "now = New Date" execute the same as "now = New Date()" as above?

Last question! In VB these statements would fail at runtime, since whenever you are assigning an object to a previously dimmed (but empty) object variable, you need to use "set" as in "Set MyVar = New SomeObject". In Jabaco, is "set" unnecessary, or ignored like good old "let" (as in "let a=5" from the good old days...)

Thanks!

theuserbl

Intermediate

Posts: 436

Date of registration: Dec 20th 2008

  • Send private message

17

Sunday, January 23rd 2011, 11:05pm

Please clarify in the code above: As a VB programmer, I consider a "Date" as a data type, not an object, therefore the "new" keyword would never be used. Dates are dim'd just like integers, etc...
In this case is Date not a Jabaco-function. Date comes from Java and can be found at java.util.Date.

Quoted

The above code includes "now = New Date()" which implies that the "Date" item in Jabaco is not a data type, but an object. Is this true?
In Java it is an object. And because Jabaco have currently not an own one, it usess the Java one. Right.

Quoted

Next question: would "now = New Date" execute the same as "now = New Date()" as above?
Yes. It compiles to the same binary and so it runs the same.

Quoted

Last question! In VB these statements would fail at runtime, since whenever you are assigning an object to a previously dimmed (but empty) object variable, you need to use "set" as in "Set MyVar = New SomeObject". In Jabaco, is "set" unnecessary, or ignored like good old "let" (as in "let a=5" from the good old days...)
Have now tested with Set MyVar = New String and MyVar = New String . Both producing the same binary.

That are compiler things. The compiler is not OpenSource. So I can only assume, what the compiler will do generally.
And I can only test special situations and test it.
now = New Date() compiles to the same like now = New Date
And Set MyVar = New String compiles to the same like MyVar = New String
So for example I assume, that the Set command is ignored. But it is possible, that in some special cases it takes effect.


To help you, to answer your questions yourself, have a look at this decompilers:
http://www.varaneckas.com/jad
http://java.decompiler.free.fr/?q=jdgui
They help you to understand, what the compiler do.

For example the Jabaco-code

Jabaco Source

1
2
3
4
Public Sub main(ByJava args() As String)
  Dim now As Date
  now = New Date() 
End Sub


is compiled and then decompiled this Java-code:

Jabaco Source

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import java.util.Date;

public class Module1
{

    public static void main(String args[])
    {
        Throwable Err = null;
        Date date = new Date();
        date.setTime(0);
        Date now = date;
        now = new Date();
    }

    public Module1()
    {
    }

}


So you can see, that Date comes from java.util.Date

Additional helpful is to disassemble a program "Module1.class" with the command javap -c Module1
The Javap.exe file you can find in your bin-directory of your JDK-path.

And then there existing at last the nice Windows/DOS program FC , which comes with Windows.

With fc /b BinaryFile1 BinaryFile2 , you can differ the two files, if they are exactly the same or not.
This helps, if you want to know, if different Jabaco-code creating the same files.

scGuy

Beginner

  • "scGuy" started this thread

Posts: 40

Date of registration: Jan 12th 2011

  • Send private message

18

Monday, January 24th 2011, 6:35am

Thank you so much for your efforts, and all the information. I'll be spending some time figuring all of this out!

Rate this thread
WoltLab Burning Board