Looking for a way to pass back multiple data types from a method. I want to be able to pass back an array that the method fill out, and also the length of that array (I need that because the calling code will pass the byte array to the serial port, and the length must be specified). I looked into Vectors, but each element in the Vector must be an object (can't just be an integer).

Any idea on how to do this? I'm a java noob. In VB it was easy to just create a structure. Not sure what to do in Java


Re: Pass back multiple data types? 80 80

Create a class to hold that data. Return an instance of that class.

Re: Pass back multiple data types? 80 80

Ok. Here is what I have tried.

public class dataClass{
	byte[] bytChunk; // = new byte[100];
	int numBytes;

    dataClass() {}

    public static dataClass createByteArray() {
        dataClass dc = null;

        dc.numBytes = 15;
        dc.bytChunk = new byte[dc.numBytes];

        //loop and assign bytes to bytChunk array

        return dc;
    } //createByteArray

When I call this from another class, I don't seem to get anything back (at least I can't seem to access the members/variables from my new class).

Calling code:

dataClass myDC = dataClass.createByteArray();

Status.show("Back from call to dataClass");
Status.show("numBytes: " + Integer.toString(myDC.numBytes) );

I get the first message, but the second does not pop up.

Re: Pass back multiple data types? 80 80

You have to create a new Object of that classtype i.e.

dataClass dc = new dataClass();

Re: Pass back multiple data types? 80 80

Genius! Works like a charm. Thanks to you both.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.