hpconvert.java

来自「一个简单的visio程序。」· Java 代码 · 共 1,924 行 · 第 1/4 页

JAVA
1,924 行
字号
    public static HByte CBYTE(String exp) throws HpException
    {
        double d = hpstring.strtodbl(exp);
        if( d>255 || d<0 )
            throw new HpException(6,"Overflow");
        return new HByte((short)(hpstring.dbl2int(d)));
    }

	/**
	 *CBool(expression)
	 *Converts an expression to a boolean.
	 */
    public static boolean CBOOL( Variant  exp) throws HpException
    {
        double     number=0;

        if( exp.getType()==Variant.V_STR && exp.strValue().equalsIgnoreCase("true") )
           return true;//i = -1;
        else if( exp.getType()==Variant.V_STR && exp.strValue().equalsIgnoreCase("false") )
           return false;//i = 0;
        else
        {
           number = hpstring.get_db(exp) ;
           if( number!=0 )
                return true;
           else
                return false;

           //if( number!=0 )
           // i = -1;

        }
        //return Variant.newBool( i );

    } //end of cbool

    public static boolean CBOOL( boolean  exp) throws HpException
    {
        return exp;
    }
    public static boolean CBOOL( HByte  exp) throws HpException
    {
        return exp.byteValue()==0 ? false:true;
    }
    public static boolean CBOOL( short  exp) throws HpException
    {
        return exp==0 ? false:true;
    }
    public static boolean CBOOL( int  exp) throws HpException
    {
        return exp==0 ? false:true;
    }
    public static boolean CBOOL( float  exp) throws HpException
    {
        return exp==0 ? false:true;
    }
    public static boolean CBOOL( double  exp) throws HpException
    {
        return exp==0 ? false:true;
    }
    public static boolean CBOOL( HCurr  exp) throws HpException
    {
        return exp.dblValue()==0 ? false:true;
    }
    public static boolean CBOOL( HDate  exp) throws HpException
    {
        return exp.dblValue()==0 ? false:true;
    }
    public static boolean CBOOL( fixedString  exp) throws HpException
    {
        String s = exp.strValue();
        double d = hpstring.strtodbl(s);
        return d==0 ? false:true;
    }
    public static boolean CBOOL( String  exp) throws HpException
    {
        double d = hpstring.strtodbl(exp);
        return d==0 ? false:true;
    }


	/**
	 *CCur(expression)
	 *Converts an expression to a ccurrency.
	 */
    public static HCurr CCUR(Variant exp) throws HpException
    {
        double d = hpstring.get_db(exp);
        return new HCurr( d );
    }

    public static HCurr CCUR(boolean exp) throws HpException
    {
        return new HCurr( exp==true ? (double)-1:(double)0 );
    }
    public static HCurr CCUR(HByte exp) throws HpException
    {
        return new HCurr( (double)(exp.byteValue()) );
    }
    public static HCurr CCUR(short exp) throws HpException
    {
        return new HCurr( (double)exp );
    }
    public static HCurr CCUR(int exp) throws HpException
    {
        return new HCurr( (double)exp );
    }
    public static HCurr CCUR(float exp) throws HpException
    {
        return new HCurr( (double)exp );
    }
    public static HCurr CCUR(double exp) throws HpException
    {
        return new HCurr( exp );
    }
    public static HCurr CCUR(HCurr exp) throws HpException
    {
        return new HCurr(exp.dblValue() );
    }
    public static HCurr CCUR(HDate exp) throws HpException
    {
        double d = exp.dblValue();
        return new HCurr( d );
    }
    public static HCurr CCUR(fixedString exp) throws HpException
    {
        String s = exp.strValue();
        double d = hpstring.strtodbl(s);
        return new HCurr( d );
    }
    public static HCurr CCUR(String exp) throws HpException
    {
        return new HCurr(hpstring.strtodbl(exp) );
    }

    /**
	 *Str[$](number)
	 *Returns a string (str$()) or variant string (str()) representation of a number.
	 *The number argument is any valid numeric expression.
	 */
    public static String STR$( Variant varnumber ) throws HpException
    {
        String  string;
        int type = varnumber.getType();

        if( type==Variant.V_NULL )
            throw new HpException(94, "Invalid use of nuLL");
        else
            string = STR( varnumber ).strValue();
        return  string;
    }

    public static String STR$(boolean number ) throws HpException
    {
        return (new Boolean(number)).toString();
    }
    public static String STR$(HByte number ) throws HpException
    {
        return " " + number.strValue();
    }
    public static String STR$(short number ) throws HpException
    {
        return " " + Short.toString(number);
    }
    public static String STR$(int number ) throws HpException
    {
        return " " + Integer.toString(number);
    }
    public static String STR$(float number ) throws HpException
    {
        return " " + Float.toString(number);
    }
    public static String STR$(double number ) throws HpException
    {
        return " " + Double.toString(number);
    }
    public static String STR$(HCurr number ) throws HpException
    {
        return " " + number.strValue();
    }
    public static String STR$(HDate number ) throws HpException
    {
        return number.strValue();
    }
    public static String STR$(fixedString number ) throws HpException
    {
        String str = number.strValue();

        int strlen = str.length();
        if( strlen>2 && str.charAt(strlen-1)=='0' && str.charAt(strlen-2)=='.' )
            str = " " + str.substring(0, strlen-2 );
        if( str.compareTo("-0")==0 )
            str = " 0";
        return str;
    }
    public static String STR$(String number ) throws HpException
    {
        String str = number;
        int strlen = str.length();
        if( strlen>2 && str.charAt(strlen-1)=='0' && str.charAt(strlen-2)=='.' )
            str = " " + str.substring(0, strlen-2 );
        if( str.compareTo("-0")==0 )
            str = " 0";
        return str;
    }



    /*--- Function:Str(number) ---*/
    public static Variant STR( Variant varnumber ) throws HpException
    {
        String      str="";
        int       type ;
        Variant      Variant = new Variant();
        int         strlen;

        type = varnumber.getType();

    	switch(type)
    	{
    	    case HECore.stddata.Variant.V_NULL:
    		    return new VNull();

            case HECore.stddata.Variant.V_FIX_STR:
    	        fixedString fixstr= ((VString)varnumber).getfixedLenStrValue();
    	        str = fixstr.strValue();
    	        strlen = str.length();

                if( strlen>2 && str.charAt(strlen-1)=='0' && str.charAt(strlen-2)=='.' )
                    str = " " + str.substring(0, strlen-2 );
                if( str.compareTo("-0")==0 )
                    str = " 0";
                break;

    	    case HECore.stddata.Variant.V_STR:
    	        double db = hpstring.get_db(varnumber);
    	        str = Double.toString(db);
                strlen = str.length();
                if( strlen>2 && str.charAt(strlen-1)=='0' && str.charAt(strlen-2)=='.' )
                    str = " " + str.substring(0, strlen-2 );
                if( str.compareTo("-0")==0 )
                    str = " 0";
    	        break;

    	    case HECore.stddata.Variant.V_EMPTY:
    	    case HECore.stddata.Variant.V_BYTE:
    	    case HECore.stddata.Variant.V_INT:
    	    case HECore.stddata.Variant.V_LONG:
    	        int tmpint = varnumber.lngValue();
    	        str =" " + Integer.toString( tmpint );
    	        break;

    	    case HECore.stddata.Variant.V_CURR:
    	    case HECore.stddata.Variant.V_DBL:
    	    case HECore.stddata.Variant.V_SINGLE:
    	    case HECore.stddata.Variant.V_VAR:
    	        double tmpdb = varnumber.dblValue();
    	        str = " " + Double.toString(tmpdb);
    	        break;

    	    case HECore.stddata.Variant.V_DATE:
    	        str = varnumber.strValue();//.dateValue();
    	        break;

    	    case HECore.stddata.Variant.V_BOL:
    	        str = varnumber.strValue();
    	        break;

        	case HECore.stddata.Variant.V_OBJ:
        	    //Wrapper  obj = varnumber.getObject();
        	    //if( obj==null )
                //    throw new HpException( 91, "Object variable or With block variable not set");
        	    str = (((VObject)varnumber).getProperty("dfault")).strValue();
        	    break;

        	 //case Variant.V_FORM:
        	 //   throw new HpException(450, "Wrong number of arguments or invalid property assignment");

    	    default:
    	       throw new HpException(13,"Type mismatch");
    	}

        return new VString(str);
    }


    public static Variant STR(boolean number ) throws HpException
    {
        return new VString( (new Boolean(number)).toString() );
    }
    public static Variant STR(HByte number ) throws HpException
    {
        return new VString(" " + number.strValue() );
    }
    public static Variant STR(short number ) throws HpException
    {
        return new VString( " " + Short.toString(number) );
    }
    public static Variant STR(int number ) throws HpException
    {
        return new VString(" " + Integer.toString(number));
    }
    public static Variant STR(float number ) throws HpException
    {
        return new VString(" " + Float.toString(number));
    }
    public static Variant STR(double number ) throws HpException
    {
        return new VString(" " + Double.toString(number));
    }
    public static Variant STR(HCurr number ) throws HpException
    {
        return new VString(" " + number.strValue());
    }
    public static Variant STR(HDate number ) throws HpException
    {
        return new VString(number.strValue());
    }
    public static Variant STR(fixedString number ) throws HpException
    {
        String str = number.strValue();

        int strlen = str.length();
        if( strlen>2 && str.charAt(strlen-1)=='0' && str.charAt(strlen-2)=='.' )
            str = " " + str.substring(0, strlen-2 );
        if( str.compareTo("-0")==0 )
            str = " 0";
        return new VString(str);
    }
    public static Variant STR(String number ) throws HpException
    {
        String str = number;
        int strlen = str.length();
        if( strlen>2 && str.charAt(strlen-1)=='0' && str.charAt(strlen-2)=='.' )
            str = " " + str.substring(0, strlen-2 );
        if( str.compareTo("-0")==0 )
            str = " 0";
        return new VString(str);
    }

    /**
	 *StrConv(string, number)
	 *Returns a converted string.
	 */
    public static Variant STRCONV( Variant string, Variant varnumber ) throws HpException
    {
        String    str;
        int      type = string.getType();

        if( type==Variant.V_NULL )
            return new VNull();
        else
            str = hpstring.get_str( string );

        int    number = hpstring.dbl2int( hpstring.get_db(varnumber));
        if( number>255 || number<0)
            throw new HpException(5,"Invalid procedure call");

        switch(number)
        {
            case 0:
                break;

            case 1:
                str = str.toUpperCase();
                break;

            case 2:
                str = str.toLowerCase();
                break;

            case 3:
                String tempstr;
                int    i = -1,temp = 0, leng=0;
                String sstr =str, s = "";

                java.util.StringTokenizer  token = new java.util.StringTokenizer(str);
                while( token.hasMoreTokens() )
                {
                    tempstr = new String( token.nextToken() );
                    i = sstr.indexOf( tempstr );
                    s += sstr.substring(0, i) + String.valueOf(Character.toUpperCase(tempstr.charAt(0))) + tempstr.substring(1);
                    temp = i + tempstr.length();
                    sstr = sstr.substring(temp);
                }
                str = new String(s);
                break;

            default:
                throw new HpException(5, "Invalid procedure call");

        }
        return new VString(str);
    }

    /**
	 *CVar( variant)
	 *Converts an expression to a Variant.
	 */
    public static Variant CVAR( Variant exp) throws HpException
    {
        int          type;
		Variant     v=null;

        type = exp.getType();
    	switch (type)
    	{
    	    case Variant.V_NULL:
            v = new VNull();
            break;

            default:
               v = (Variant)exp.clone();
    	}
        return v;
    }
    public static Variant CVAR(boolean  exp) throws HpException
    {
        return new VBoolean(exp);
    }
    public static Variant CVAR(HByte  exp) throws HpException
    {
        return new VByte(exp.byteValue());
    }
    public static Variant CVAR(short  exp) throws HpException
    {
        return new VInt(exp);
    }
    public static Variant CVAR(int  exp) throws HpException
    {
        return new VLong(exp);
    }
    public static Variant CVAR(float  exp) throws HpException
    {
        return new VSingle(exp);
    }
    public static Variant CVAR(double  exp) throws HpException
    {
        return new VDouble(exp);
    }
    public static Variant CVAR(HCurr  exp) throws HpException
    {
        return new VCurr( exp.dblValue() );
    }
    public static Variant CVAR(HDate  exp) throws HpException
    {
        return new VDate(exp.dblValue() );
    }
    public static Variant CVAR(fixedString  exp) throws HpException
    {
        String s = exp.strValue();
        return new VString(s);
    }
    public static Variant CVAR(String  exp) throws HpException
    {
        return new VString(exp);
    }


    public static double CDEC(double d) throws HpException
    {
        return CDBL(d);
    }


    /**
	 *CVErr(number)
	 *Returns a Variant of subtype Error containing an error number specified by
	 *the user.
	 */
    public static Variant CVERR( Variant number) throws HpException
    {
        int         num;
        String      str;
        VInt       v=  new VInt(number.intValue());    //Liu Lanfang 12/4/97
        //v.setVariantType(Variant.V_ERR);
        return v;
    }

 }//end Convert class

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?