• Post Reply Bookmark Topic Watch Topic
  • New Topic

Interpret short VB statement to Java  RSS feed

 
Niall McLoughlin
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I've inherited a process that uses a couple of VB functions to encrypted and unencrypt some data. I need to interpret the VB functions into java. I've comleted most of the conversion, but there is one line that I haven't been able to correct.

If there are any java coders out there with VB skill, I'd appreciate a hand.

The code takes an ( encoded ) String, decrypts it and converts it to an ascii character array. The line of code I'm struggling with is:



I've interpreted this various ways, but the most obvious equivalent I can see is:

 
Niall McLoughlin
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aha. Got it.

The for loop in VB has a control variable that starts initialises to 1. My java for loop has the counter initialised to 0.

Amended the value, got the right result.
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

WHY DEAR GOD WHY??

You know this creates a new Object, only used to get one single character?

PLEASE, replace it with the following:

It does the exact same thing without creating another object, and therefore is more memory efficient and faster.
 
Niall McLoughlin
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
At the minute, I'm replicating some functionality in VB. That is a literal translation of what the VB code is doing. I'll look at refining it once I have the functionality down.
 
Niall McLoughlin
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And you should check your logic as well. If I replaced my code with yours, it would give me the wrong result.
 
Adam Nace
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Niall McLoughlin:
And you should check your logic as well. If I replaced my code with yours, it would give me the wrong result.


I think you might want to try that again, then. Take a look at this code, compile it, and run it, and you should see that what he told you was true.

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!