• Post Reply Bookmark Topic Watch Topic
  • New Topic

Casting Problem  RSS feed

 
Steven Tull
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, I am new to this forum and sorta new to Java programming. Here is my problem. I have a piece of Lotus script that I am basically converting to Java line by line. Probably not best practice I know.

Question when I try to cast a character to an integer I get errors and I cannot find the correct way to convert/compare.

I have included the Lotus Script, and then the Java.

//******************************************
//LOTUS SCRIPT
//******************************************
If Instr(specChar$, Mid(stringA, z, 1) ) > 0 Then
If Len(tchar) > 0 Then
If Isnumeric(tchar) Then
tempCNum% = Cint(tchar) - 2 - Len(stringB) - ctchars%
newString$ = Chr(tempCNum%) & newString$
ctchars% = ctchars% - 1
Else
tempCNum% = Asc(tchar) - 2 - Len(stringB) - ctchars%
newString$ = Chr(tempCNum%) & newString$
ctchars% = ctchars - 1
End If
End If
tchar = ""
If Mid(stringA, z, 1) = "." Then
skipfirst% = True
End If
Else
If skipfirst% Then
tchar = tchar + Mid(stringA,z,1)
End If
End If
//******************************************
//End of Lotus Script
//******************************************


//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//JAVA Section
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

if (specChar.indexOf( strEP.charAt(z), 0 ) > 0 )
{
if (tchar.length() > 0)
{
if ( isNumeric(tchar) )


if (Character.getNumericValue (newMyString.(tchar)))
{
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//Begining of section with problems. See comments below.
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
tempCNum = Integer.parseInt( tchar ); //why can't i convert tchar to an integer using this notation?
newMyString = Integer.toString(tempCNum) + newMyString; // why can't i convert tempCNum into a string? i want to concatenate these two string and put into newMyString.
ctchars -=1;
}
else
{
tempCNum =Integer.parseInt(tchar) - 2 - strFullName.length() - ctchars;
newMyString = tempCNum + newMyString; //why can't i convert tchar to an integer using this notation?
ctchars -=1;
}
}
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//End of section with problems
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@


tchar = "";
if (strEP.charAt(z) == '.')
skipfirst = true;

}

else
{
if (skipfirst)
tchar = tchar + strEP.charAt(z);
}
}
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//End of Java
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Steve,

Welcome to JavaRanch!

I don't know anything about LotusScript, except that it looks like some flavor of BASIC. I'm assuming it's a weakly typed language, meaning that a variable doesn't have a data type associated with it. It seems that you've already noticed that Java is a strongly typed language, and that you're struggling with what that means, exactly.

Now, truth be told, there's no substitute for an introductory textbook when you learn a new language, especially one which (I'm guessing) is rather different that anything you've been exposed too previously. Therefore, my first suggestion is that you take a deep breath, step back, buy one, and read it. Our Bunkhouse is a great place to find out about Java books, read reviews of them, and buy them.

But I'll try to give you a hand, if you promise me one thing: never write another line comment made up of 72 "at" signs (or any character, actually) again. Agreed? OK, good. Also, you can enclose your code in UBB "CODE" tags -- see the "What is UBB Code?" link on the page that lets you compose a message to learn more. CODE tags let your code show up as nicely formatted on the page here at the Ranch.

Now, the most important information I'd need to answer your questions doesn't appear in the code above. Every variable in Java has a type, be it char, String, int, or what-have-you. Each type has specific operations that are legal on it. Without seeing the declarations of these variables -- i.e., the point at which their types are declared -- I can't tell what you're doing wrong. Furthermore, compiler error messages are very helpful: if you're showing off some code with an error in it, cutting and pasting the compiler errors into your message would be very helpful.

Anyway, if you come back with more information, I can explain what's happening.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!