Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Working with strings

Status
Not open for further replies.

rtgordon

Programmer
Jan 17, 2001
104
US
Hey guys/gals...

I have a java program that I call as a COM object from an ASP page. What it does is takes a request, does an MQSeries transaction, and the result is a 1000 byte string, which I pass back to the ASP for parsing (using Mid function which is similar to substring) and then, I paint the page with the results.

What I want to do is parse the message in java, and return the variables. This has me a little confused.

One way that I see to do it is to set up public strings for each of the vars

public String partNumber (String part)
{
part = msgTxt.substring(1,30)
return part;
}
public String vendorCode (String vendor)
{
vendor = msgTxt.substring(1,30)
return vendor;
}

Then, call them from the ASP page like:

set javaObject = GetObject("java:COMStocReqReply")
PartNumber = javaObject.partNumber(PartNumber)
VendorCode = javaObject.vendorCode(VendorCode)

This doesn't seem like the best way to do this. I am looking for a fundamentally better approach. Who knows, maybe this is the best way, but any input/help would be appreciated.

Thanks!
gordon
 
do this.

public String vendorCode()
{
return msgTxt.substring(1,30)
}

set javaObject = GetObject("java:COMStocReqReply")
VendorCode = javaObject.vendorCode()

i don't think there is any other way to optimise this
 
Thanks! much more succint.

One more question:

If my proggie is like this:

import com.ibm.mq.*;
import java.io.*;
import sun.io.*;

public class COMStocReqReply2
{
public static void main(String[] args)
{
//do nothing
}

//set up some strings

public void init()
{
//MQ Environment Stuff
}
public String PutMessage(String msg, String code)
{
try
{
//MQ Logic
String msgText = stocRetrievedMessage.readString(msgLength);
code = msgText;
}
//catch any exceptions and return the var code with errmsg
return code;
}
public String partNumber()
{
return msgText.substring(0,29);
}
}


How do I define msgText so that it can be accessed by partNumber?? On compilation I get an undefined error. I realize this is probably basic stuff, but any help is appreciated.

Thanks,
gordon
 
you need to define the string as an object member variable i.e. it is an attribute of the class. then it is accessable by every method in the class

public class COMStocReqReply2
{

// ADD MEMBER VAR HERE
private String msgText;

public static void main(String[] args)
{
//do nothing
}

//set up some strings

public void init()
{
//MQ Environment Stuff
}
public String PutMessage(String msg, String code)
{
try
{
//MQ Logic
msgText = stocRetrievedMessage.readString(msgLength);
code = msgText;
}
//catch any exceptions and return the var code with errmsg
return code;
}
public String partNumber()
{
return msgText.substring(0,29);
}
}


the private modifier states that the variable can not be accessed outside the scope of the class
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top