Results 1 to 18 of 18

Thread: [RESOLVED] Java To VB

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Resolved [RESOLVED] Java To VB

    In a Java file I have this

    Code:
    public int images_X_Y[] = {0, 0, 119, 166, 183, 147, 235, 133, 288, 118};
    Can I do something similar in VB, like this

    Code:
    public images_X_Y() As Integer = (0, 0, 119, 166, 183, 147, 235, 133, 288, 118)


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  2. #2
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Java To VB

    No, you'd have to create the array and then initialize the values.

    Of course one option might be something like:

    Code:
    Public images_X_Y As Variant
    :
    :
    Public Sub Init()
        images_X_Y = Array(0, 0, 119, 166, 183, 147, 235, 133, 288, 118)
    End Sub
    If you can live with a Variant containing an array that's fine, otherwise you might use a loop to copy that into an actual Integer array.

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Java To VB

    Yikes!

    I have about 20 arrays that contain hundreds of pre-calculated numeric values. The example I posted was shortened just to conserve space but it actually contains 200 integer values.

    How does one initialize these arrays with each value different than the others? Would it be like this

    Code:
    Public images_X_Y() As Integer
    :
    :
    Public Sub Init()
     
        imgsXY = Array(0, 0, 119, 166, 183, 147, 235, 133, 288, 118)
    
        For n = 0 To Ubound(imgsXY)
          images_X_Y(n) = imgsXY(n)
        Next n
    
    End Sub
    Would it be better to go ahead and use it as a Variant then in the code where it is called convert to integer like this

    Code:
    Public images_X_Y As Variant
    :
    :
    Public Sub Init()
        images_X_Y = Array(0, 0, 119, 166, 183, 147, 235, 133, 288, 118)
    End Sub
    
    Private Function GetArrayValue() As Integer
     GetArrayValue = CInt( images_X_Y(5))
    End Function
    Last edited by jmsrickland; Nov 28th, 2013 at 08:34 PM.


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  4. #4
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Java To VB

    "Better" is pretty subjective and situational.

    If you have a ton of this stuff you could consider other ugly stuff, for example:

    Create one program that sets up the values and writes them out as binary files. Then in your "real" program, compile these files in as custom resources, at runtime load them into Byte arrays and use CopyMemory to move them into the actual arrays (since LoadResData() calls return Byte arrays).

    That would be faster but extra effort to maintain.


    BTW: Those colons I used were just a sort of "vertical ellipsis" to show a gap that might have other statements in between, and they don't need to be there.

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Java To VB

    Byte Array? Many of the arrays have strings, and other values greater than a byte.


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  6. #6
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: Java To VB

    Quote Originally Posted by jmsrickland View Post
    I have about 20 arrays that contain hundreds of pre-calculated numeric values.
    Quote Originally Posted by jmstrickland
    Byte Array? Many of the arrays have strings, and other values greater than a byte.
    Bit of scope creep here .....?


    If this is a one-off conversion then you could write some VB code to parse your Java source code to pull out the Array definitions and values and re-format them for VB. Write the re-formatted code to a file and copy and paste into VB. The Java statements specify the variable type so you can 'type' the VB Arrays as you go. A few InStr, InStrRev, Mid$ and Split statements should do it.
    Last edited by Doogle; Nov 29th, 2013 at 02:53 AM.

  7. #7

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Java To VB

    Don't understand your post, Doogle.

    Anyway I think I will use the method suggested by dilettante in post #2

    Code:
    Public images_X_Y As Variant
      '
      '
    Public Sub Init()
     images_X_Y = Array(0, 0, 119, 166, 183, 147, 235, 133, 288, 118)
      '
      ' Other arrays here
      '
    End Sub
    
    Public Function images_X_Y_GetValue(Index As Integer) As Integer
     images_X_Y_GetValue = CInt( images_X_Y(Index))
    End Function
      '
      '


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  8. #8
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: Java To VB

    Quote Originally Posted by jmsrickland View Post
    Don't understand your post, Doogle. '
    If you mean the scope creep he is referring to this

    Quote Originally Posted by jmsrickland View Post
    I have about 20 arrays that contain hundreds of pre-calculated numeric values.
    then a few posts later you say
    Quote Originally Posted by jmsrickland View Post
    Byte Array? Many of the arrays have strings,

  9. #9
    PowerPoster Spoo's Avatar
    Join Date
    Nov 2008
    Location
    Right Coast
    Posts
    2,656

    Re: Java To VB

    Quote Originally Posted by jmsrickland View Post
    Don't understand your post, Doogle.
    JMS

    I think Doogle (and Dilletante too) is suggesting you essentially create a sub
    to read the Java code and create a text file containing the 20 arrays and their
    200+ values. Thus, your text file would end up with 20 lines.

    You could then, in your VB app, read said textfile (on demand) and populate
    the array as needed. Thus, you would not be "hard-wiring" the 20 arrays.

    It will "cost" some time to write the extraction app, but that seems to be less than
    "hard-wiring" your actual app.

    Spoo

  10. #10

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Java To VB

    I already have the hard coded values of the arrays. They are in the Java source code so it isn't like I have to re-write the values. All I have to do is to copy them into a sub. I don't see the advantage of reading the code and create an external file then later read in that file and populate the arrays other than it will save me from having to make the sub like dillettante suggested in post #2 but that is just as easy as making a sub to read the Java code, etc.

    Java Source Code (Example of one array)

    Code:
      '
      '
    public int imagesXY[] = 
    {
       0, 0, 119, 166, 183, 147, 235, 133, 288, 118,
        98, 132, 155, 119, 206, 105, 255, 93, 80, 105,
        132, 92, 180, 81, 226, 71, 64, 81, 114, 71,
        159, 61, 203, 53, 119, 152, 183, 135, 236, 121,
        288, 106, 98, 120, 155, 106, 206, 93, 255, 82,
        80, 93, 132, 82, 181, 71, 226, 61, 64, 71,
        114, 61, 159, 51, 203, 44, 119, 139, 182, 123,
      '
      '
      '
      '
        236, 109, 288, 94, 99, 107, 155, 95, 206, 82,
        255, 71, 80, 81, 132, 72, 181, 60, 227, 51,
        64, 61, 114, 51, 159, 42, 203, 34, 119, 124,
        183, 110, 236, 95, 289, 81, 98, 93, 155, 83,
        206, 70, 255, 59, 79, 69, 132, 60, 180, 50,
        227, 40, 64, 51, 114, 41, 159, 32, 204, 24,
        119, 152, 183, 135, 236, 121, 288, 106, 98, 120,
        155, 106, 206, 93, 255, 82, 80, 93, 132, 82,
        181, 71, 226, 61, 64, 71, 114, 61, 159, 51
    };
      '
      '
      '
    So all I do is copy the values and put them in a sub like this

    VB code

    Code:
    Private imagesXY() As Variant 
      '
      '
      '
      '
    '
    ' I call the Sub from Form_Load 
    '
    Public Sub InitArrays()
     imagesXY = Array(0, 0, 119, ...............51)
    
     bigNumbersScore = Array(66, 67, 0, 0, 67, 67, ............ 68)
    
      '
      ' the rest of the arrays
      '
    End Sub
      '
      '
    Now, I have a Sub for each array so I can get the values

    Code:
      '
      '
    Public Function imagesXY_GetValue(Index As Integer) As Integer
     imagesXY_GetValue = CInt(imagesXY(Index))
    End Function
    
    Public Function bigNumbersScore_GetValue(Index As Integer) As Integer
     bigNumbersScore_GetValue = CInt(bigNumbersScore(Index))
    End Function
      '
      ' Functions for the rest of the arrays
      '
    Then in the code where ever it called for one of the arrays I just call the function instead

    Code:
      '
      '
      '
    Public Sub drawBallsOnBoard(g1 As Graphics, i As Integer, j As Integer)
    'public void drawBallsOnBoard(Graphics g1, int i, int j){
     Dim k As Integer
    
     k = 1                                              ' int k = 1;
    
     Do                                                 ' do
       If ballsOnPoles_GetValue(k) <> 0 Then            '   if(ballsOnPoles[k] != 0)
         g1.drawImage images(imagesXY_GetValu(k * 2))   '     g1.drawImage(imagesXY[k * 2]);
       End If
    
       k = k + 1
     While k < 65                                       ' while(++k < 65);
    End Sub                                             '}
      '
      '


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  11. #11

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Java To VB

    Quote Originally Posted by DataMiser View Post
    If you mean the scope creep he is referring to this



    then a few posts later you say
    I know that is what he was referring to. I don't understand why he quoted it; is there something strange about what I said?


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  12. #12

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Java To VB

    I see that I do not need to helper functions as I can reference the array directory so all I have to do is to initialize the arrays using this code

    Code:
    Public Sub InitArrays()
     imagesXY = Array(0, 0, 119, ...............51)
    
     bigNumbersScore = Array(66, 67, 0, 0, 67, 67, ............ 68)
    
      '
      ' the rest of the arrays
      '
    End Sub
    Then in the code just reference the array instead of calling the GetValue Subs

    So, why is creating an external file then loading that file back into the program and initializing the arrays any better than what I'm doing?


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  13. #13
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: Java To VB

    Quote Originally Posted by jmsrickland View Post
    I know that is what he was referring to. I don't understand why he quoted it; is there something strange about what I said?
    Yes.. AT first you indicated that you were dealing with numeric values. The implication was that you were only dealing with numeric values and not dealing with strings. Then when someone gave some advise you say you have strings in some of them which of course changes things.

    Ideally if you were dealing with strings and numeric values then you should have said so in the first post rather than implying only numeric values.

    Have you read your sig?

  14. #14

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Java To VB

    Here's why and I know others do not understand.

    It's simple: On a need to know basis

    In my original post I simply asked if I can take an array like it is declared in Java and do the same in VB and I gave a simple example. Why would I think that telling I had arrays of strings and values larger than a byte have anything to do with my first question. It simply didn't make any difference what was in the arrays.

    When I open a thread I use the least amount of info I feel is needed so that I do not over state or add a lot of stuff that doesn't apply at the time I ask my question because I see a lot of posts where others comment that it is too long or too much stuff posted which tends to complicate the issue. So, I keep mine at a minimum and only add to it if it becomes necessary. If I get an answer that satisfies my request then good, everything is kosher, I closes the thread and I am on my way. However, when certain unforeseen things pop up I simply handle them as they occur like when dillettante suggested the byte array (post 2) which never occurred to me since I was satisfied with his first reply so I didn't say I had arrays that contained strings and values greater than a byte until he brought it up. To my way of thinking it simply didn't apply prior to his post #2.

    Quote Originally Posted by DataMiser View Post
    Have you read your sig?
    Oh, that's message is for you
    Last edited by jmsrickland; Nov 29th, 2013 at 06:15 PM.


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  15. #15
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: Java To VB

    Quote Originally Posted by jmsrickland View Post
    It simply didn't make any difference what was in the arrays.
    In this case it did. Dilettante's suggestion in Post #4 would have been ideal if the data was all numeric (i.e. you know the length of each variable). You'd just use CopyMemory to copy the correct number of bytes from the byte array into a suitably 'typed' array.

    e.g.
    Dim lngArray(3) As Long
    CopyMemory lngArray(0), bytArray(0), 16

    would result in elements 0 to 3 of lngArray being populated with values from bytArray.

    With strings involved, you don't necessarily know the length of each string, so CopyMemory would not be suitable, implying that Dilettante wasted some time in replying.

    BTW My earlier comment regarding scope creep was an (obviously failed) attempt at light scarcasm - should have inserted a smilie - DM's interpretation of what I was getting at was exactly correct.

    I almost understand your 'need to know' strategy by not 'littering' a question with what might be unrelated information, but the problem with that is, if you don't understand something how do you know what's 'litter' and what's important to include?

    All to often we see threads here with 20+ responses and then OP comes up with "Oh, by the way ........" which changes the complete context of the original problem. I personally prefer too much, rather than not enough information - it's then up to me to filter it and see if I can come up with a solution.

  16. #16

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: [RESOLVED] Java To VB

    The thing is I wasn't interested in Dillettante's post #4. His post #2 was ideal in my opinion and it is the one that I am using. It's the easiest approach and it's straightforward so why do anything else. I can not think that any other approach would be any better and I do not agree with you about it did make a difference as to what is in the arrays as my original question had nothing to do with contents but rather can it be done in VB as it was done in Java was my only concern when I started this thread so why say more than is necessary when what I posted as an example was sufficient enough for the question I asked at that time. It must have been as dillettant answered it in post #2. Dillettante had no idea exactly what kind of data was in the array other than what I posted and yet he had a good answer without any other information. That there alone tells me I gave enough information. I think the mistake was when I made post #3 which prompted dillettane to respond with post #4. If I had given more thought to his first post I would not have had to ask in post 3. So, in view of this the information I gave was enough to warrant his 1st and best answer. Like I stated when the occasion calls for it I will add further comments to my request but not if it goes no further whether it's me or someone else who carries it on further.

    It's going to happen more often than we would like when someone starts a thread that the OP cannot think of everything and for sure you are going to get that "Oh, by the way ......." bit. That's just human nature. I don't always think of everything that I should include and I will probably wind up saying "Oh, by the way...." or "I forgot to mention.....". And yet life goes on anyway.......


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  17. #17
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: [RESOLVED] Java To VB

    Quote Originally Posted by jmsrickland View Post
    And yet life goes on anyway.......
    Too true - anyway, the important thing is that you've got a workable solution and you now know more than you did when the Thread was started.

  18. #18
    Hyperactive Member Daniel Duta's Avatar
    Join Date
    Feb 2011
    Location
    Bucharest, Romania
    Posts
    396

    Re: [RESOLVED] Java To VB

    Quote Originally Posted by Doogle View Post
    you now know more than you did when the Thread was started.
    As long as the first Dile's suggestion "was ideal" we could understand the above knowledge may be reduced to that classic Array function

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width