VB.NET to Java on these lines please...

CryoEnix

Well-known member
Joined
Jan 11, 2003
Messages
93
Location
Wrexham, Wales
Hi there guys, I wasnt sure which area to post in, so I thought this one best.

Im currently writing an encryption program side by side in Java and VB.NET, to compare performance differences and generally get the hang of Java (Im new to it). Problem is, I have this code to initialize the encryption class in VB:

Code:
Dim NewEnc(1024) As ClassEnc6

        For Num = 1 To UBound(NewEnc)
            NewEnc(Num) = New ClassEnc6("encryptionkey")
        Next

How do I recreate this in Java? Ive tried all sorts, and any Java documentation I can find is way over my head. Any ideas?
 
ClassEnc6 NewEnc() = new ClassEnc6(1024);

for(int num = 1; num < 1024; num++)
{
NewEnc(num) = new ClassEnc6("encryptionkey");
}

I dont know the ubound command in java. It could be NewEnc.GetLength

Edit: there might be a semicolon after num++. I have to brush up my Java/C++ skills. Havent used them in so long (VB.NET is addicting :D)
Edit2: Also Im assuming you know how to create the basic program (just to get it running.. ex; Creating the public static void main(String args[]) function...etc). if you need help on that I"ll post some code.
Also, id recommend JCreator Pro, its a 30 day trial, however Xinox software seems to release new versions all the time, and if you give them your email theyll send you updates and let you "try" their new software for an extra 30 days. What they dont realize is, this is a cheap way to keep the software forever (legally).

-The Pentium Guy
 
Last edited by a moderator:
Theres no ; behind the last argument in a for loop. And youre sure that this class also exists in Java(not sure if this is a custom or VB .net class)
Some mistakes though:

ClassEnc6[] NewEnc = new ClassEnc6[1024];

for(int num = 0; num < NewEnc.Length; num++) //Arrays begin at index 0
{
NewEnc[num] = new ClassEnc6("encryptionkey");
}

And I would recommend JBuilder Personal from borland as it is free. :)
 
Theres no ; behind the last argument in a for loop. And youre sure that this class also exists in Java(not sure if this is a custom or VB .net class)
Ah. Thanks for clarifying. Yeah it should be a custom class, I havent heard of a ClassEnc6 in vb.net or java.

Im pretty sure it doesnt matter where the square brackets go.
Edit: Heh, corrected myself. Square brackets. I forgot about that.

Yeah I was going to mention the index. CyroEnix, it would be better if you started your array with index 0 and ended with 1023 (unless you wanted 1025 elements in your array by ending with 1025), remember, 0 is an element.

-The Pentium Guy
 
ThePentiumGuy, Himo... What can I say? You guys are the dogs! I mean, have you ever been so grateful for some help that youd be willing to go to someones door to thank them personally? Thats where I am now - of course, theres the transport issue, and I dont think youd be too chuffed with a new stalker.

Enough of the ranting, thanks a million - gonna start playing with that code right away!


On the note of arrays, since .NETs removal of manual dimming (3 to 6, for example), Ive been dimensioning them one higher than usual - in this case, from 0 to 1024 and ignoring the 0. I find this especially useful to find out if theres anything in an array - as trying a Ubound() on an undimensioned array tends to make VBN scream like a girl.
 
Last edited by a moderator:
How bout using collections? They start at 1 and theyre easy to work with.
Dim c as new collection

c.add(myclass)

But you cant control where that item goes unfortunately, it goes "on top". So c.Item(1) would be myclass.

.NETs removal of manual dimming (3 to 6, for example),
Those were the good old days.... :D.

-TPG
 
What about Vectors? Theyre in Java.Util.Vector (I think, has been a while) and functions like dynamic uber-arrays. They have a InsertAt/RemoveAt function and a can contain everything, thanks to explicit casting, I love it.
Just an extension.
 
Back
Top