hpconvert.java

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

JAVA
1,924 行
字号
package HPCore.stdfunc;
import  HPCore.Exception.*;
import  HECore.stddata.*;

//import  HcBean.*;
/*
FUNCTION:
        Asc ,  Chr,   Hex,  Oct
        CBool, CByte, CDate(in vbdatetime)
        CDbl,  CInt,  CLng, CSng, CStr
        Str,   CVar,  StrConv,    CVErr
Author: hu xia
*/

public class hpconvert
{
    /**
	 *Asc(string)
	 *Returns the character code corresponding to the first letter in a string.
	 *Note   AscB is provided for use with byte data contained in a string. Instead
			 of returning the character code for the first character, AscB returns
			 the first byte.
	 */
	public static short ASC(Variant expression) throws HpException
    {
		String    str=null;
        switch( expression.getType() )
		{
        case Variant.V_EMPTY:
        throw new HpException(5,"Invalid procedure call");

        case Variant.V_NULL:
        throw new HpException(94,"Invalid use of null");

        case Variant.V_OBJ:

		//Wrapper   obj = vari.getObject();
        //if( obj==null )
        //    throw new HpException( 91, "Object variable or With block variable not set");
        str = ((VObject)expression).getDefaultProperty().strValue();
        break;

        case Variant.V_FIX_STR:
        fixedString  fixstr = ((VString)expression).getfixedLenStrValue();
		str = fixstr.strValue();
        if( str.compareTo("")==0 )
            throw new HpException(5,"Invalid procedure call");
		break;

        default:
        str = expression.strValue();
    	if( str==null)
            throw new HpException(94,"Invalid use of null");
        if( str.compareTo("")==0 )
            throw new HpException(5,"Invalid procedure call");
        }
	    return (short)(str.charAt(0));
    } //end of function ASC

	public static short ASC(boolean expression) throws HpException
    {
        String  s = (new Boolean(expression)).toString();
        return (short)(s.charAt(0));
    }
	public static short ASC(HByte expression) throws HpException
    {
        String s = expression.strValue();
        return (short)(s.charAt(0));
    }
	public static short ASC(short expression) throws HpException
    {
        String s = Short.toString(expression);
        return (short)(s.charAt(0));
    }
	public static short ASC(int expression) throws HpException
    {
        String s = Integer.toString(expression);
        return (short)(s.charAt(0));
    }
	public static short ASC(float expression) throws HpException
    {
        String s = Float.toString(expression);
        return (short)(s.charAt(0) );
    }
	public static short ASC(double expression) throws HpException
    {
        String s = Double.toString(expression);
        return (short)(s.charAt(0));
    }
	public static short ASC(HCurr expression) throws HpException
    {
        String s = Double.toString(expression.dblValue() );
        return (short)(s.charAt(0));
    }
	public static short ASC(HDate expression) throws HpException
    {
        String s = Double.toString(expression.dblValue());
        return (short)(s.charAt(0));
    }
	public static short ASC(fixedString expression) throws HpException
    {
        String s = new String( expression.strValue()).trim();
        if( s=="" )
            throw new HpException(5,"Invalid procedure call");
        return (short)(s.charAt(0));
    }

	public static short ASC(String expression) throws HpException
    {
        if( expression.trim()=="" )
            throw new HpException(5,"Invalid procedure call");
        return (short)(expression.charAt(0));
    }


   	public static short ASCB(Variant variant) throws HpException
    {
	    return ASC(variant);
    }
   	public static short ASCB(boolean variant) throws HpException
    {
	    return ASC(variant);
    }
   	public static short ASCB(HByte variant) throws HpException
    {
	    return ASC(variant);
    }
   	public static short ASCB(short variant) throws HpException
    {
	    return ASC(variant);
    }
   	public static short ASCB(int variant) throws HpException
    {
	    return ASC(variant);
    }
   	public static short ASCB(float variant) throws HpException
    {
	    return ASC(variant);
    }
   	public static short ASCB(double variant) throws HpException
    {
	    return ASC(variant);
    }
   	public static short ASCB(HCurr variant) throws HpException
    {
	    return ASC(variant);
    }
   	public static short ASCB(HDate variant) throws HpException
    {
	    return ASC(variant);
    }
   	public static short ASCB(fixedString variant) throws HpException
    {
	    return ASC(variant);
    }
   	public static short ASCB(String variant) throws HpException
    {
	    return ASC(variant);
    }


    public static short ASCW(Variant variant) throws HpException
    {
    return  ASC(variant);
    }	//1
   	public static short ASCW(boolean variant) throws HpException
    {
	    return ASC(variant);
    }
   	public static short ASCW(HByte variant) throws HpException
    {
	    return ASC(variant);
    }
   	public static short ASCW(short variant) throws HpException
    {
	    return ASC(variant);
    }
   	public static short ASCW(int variant) throws HpException
    {
	    return ASC(variant);
    }
   	public static short ASCW(float variant) throws HpException
    {
	    return ASC(variant);
    }
   	public static short ASCW(double variant) throws HpException
    {
	    return ASC(variant);
    }
   	public static short ASCW(HCurr variant) throws HpException
    {
	    return ASC(variant);
    }
   	public static short ASCW(HDate variant) throws HpException
    {
	    return ASC(variant);
    }
   	public static short ASCW(fixedString variant) throws HpException
    {
	    return ASC(variant);
    }
   	public static short ASCW(String variant) throws HpException
    {
	    return ASC(variant);
    }


	/**
	 *Chr(charcode)
	 *Returns the character associated with the specified character code.
	 *Remarks
		Numbers from 0 to 31 are the same as standard, nonprintable ASCII codes.For
		example, Chr(10) returns a linefeed character.
	 *Note
	    Another function (ChrB) is provided for use with byte data contained in a
		string.  Instead of returning a character, which may be one or two bytes,
		ChrB always returns a single byte.
	 */
    public static String CHR$(Variant variant) throws HpException
    {
        return CHR(variant).strValue();
    }

    public static String CHR$(boolean expression) throws HpException
    {
        if( expression==true )
           throw new HpException(5, "Invalid procedure call");
        else
        {
            Character c = new Character((char)0);
            return c.toString();
        }
    }

    public static String CHR$(HByte byte_expression) throws HpException
    {
        String  s=null;
        Character c;
        short   expression = byte_expression.byteValue();

        if(expression<0 )
           throw new HpException(5, "Invalid procedure call");

		if(  expression==13   &&
                  !System.getProperty("os.name").equalsIgnoreCase("Windows Nt") &&
        	      !System.getProperty("os.name").equalsIgnoreCase("Windows 95") )
        {
           s = System.getProperty("line.separator");
        }
        else
        {
            c = new Character((char)expression);
            s = c.toString();
        }
        return s;
    }

    public static String CHR$(short expression) throws HpException
    {
        String  s=null;
        Character c;

        if(expression<0 || expression>255)
           throw new HpException(5, "Invalid procedure call");

		if(  expression==13   &&
                  !System.getProperty("os.name").equalsIgnoreCase("Windows Nt") &&
        	      !System.getProperty("os.name").equalsIgnoreCase("Windows 95") )
        {
           s = System.getProperty("line.separator");
        }
        else
        {
            c = new Character((char)expression);
            s = c.toString();
        }
        return s;

    }

    public static String CHR$(int expression) throws HpException
    {
        String  s=null;
        Character c;

        if(expression<0 || expression>255)
           throw new HpException(5, "Invalid procedure call");

		if(  expression==13   &&
                  !System.getProperty("os.name").equalsIgnoreCase("Windows Nt") &&
        	      !System.getProperty("os.name").equalsIgnoreCase("Windows 95") )
        {
           s = System.getProperty("line.separator");
        }
        else
        {
            c = new Character((char)expression);
            s = c.toString();
        }
        return s;

    }

    public static String CHR$(float expression) throws HpException
    {
        String  s=null;
        Character c;

        int code = hpstring.dbl2int( (double) expression );
        if(code<0 || code>255)
           throw new HpException(5, "Invalid procedure call");

		if(  code==13   &&
                  !System.getProperty("os.name").equalsIgnoreCase("Windows Nt") &&
        	      !System.getProperty("os.name").equalsIgnoreCase("Windows 95") )
        {
           s = System.getProperty("line.separator");
        }
        else
        {
            c = new Character((char)code);
            s = c.toString();
        }
        return s;

    }

    public static String CHR$(double expression) throws HpException
    {
        String  s=null;
        Character c;

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

		if(  code==13   &&
                  !System.getProperty("os.name").equalsIgnoreCase("Windows Nt") &&
        	      !System.getProperty("os.name").equalsIgnoreCase("Windows 95") )
        {
           s = System.getProperty("line.separator");
        }
        else
        {
            c = new Character((char)code);
            s = c.toString();
        }
        return s;
    }

    public static String CHR$(HCurr expression) throws HpException
    {
        String  s=null;
        Character c;

        double d = expression.dblValue();
        int code = hpstring.dbl2int( d );
        if(code<0 || code>255)
           throw new HpException(5, "Invalid procedure call");

		if(  code==13   &&
                  !System.getProperty("os.name").equalsIgnoreCase("Windows Nt") &&
        	      !System.getProperty("os.name").equalsIgnoreCase("Windows 95") )
        {
           s = System.getProperty("line.separator");
        }
        else
        {
            c = new Character((char)code);
            s = c.toString();
        }
        return s;

    }

    public static String CHR$(HDate expression) throws HpException
    {
        String  s=null;
        Character c;

        double d = expression.dblValue();
        int code = hpstring.dbl2int( d );
        if(code<0 || code>255)
           throw new HpException(5, "Invalid procedure call");

		if(  code==13   &&
                  !System.getProperty("os.name").equalsIgnoreCase("Windows Nt") &&
        	      !System.getProperty("os.name").equalsIgnoreCase("Windows 95") )
        {
           s = System.getProperty("line.separator");
        }
        else
        {
            c = new Character((char)code);
            s = c.toString();
        }
        return s;

    }

    public static String CHR$(fixedString expression) throws HpException
    {
        String  s = null;
        Character c;

		String str = expression.strValue();
    	str = str.trim();
    	if( str=="" )
    	    throw new HpException(13, "Type mismatch");
   	    double db = hpstring.strtodbl(str);

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

		if(  code==13   &&
                  !System.getProperty("os.name").equalsIgnoreCase("Windows Nt") &&
        	      !System.getProperty("os.name").equalsIgnoreCase("Windows 95") )
        {
           s = System.getProperty("line.separator");
        }
        else
        {
            c = new Character((char)code);
            s = c.toString();
        }
        return s;
    }


    public static String CHR$(String expression) throws HpException
    {
        double db =0;
        String s = null;
        Character c;

    	expression = expression.trim();
    	if( expression.compareTo("")==0 )
    	    throw new HpException(13, "Type mismatch");

	    db = hpstring.strtodbl( expression );
        int code = hpstring.dbl2int( db );
        if(code<0 || code>255)
           throw new HpException(5, "Invalid procedure call");

		if(  code==13   &&
                  !System.getProperty("os.name").equalsIgnoreCase("Windows Nt") &&
        	      !System.getProperty("os.name").equalsIgnoreCase("Windows 95") )
        {
           s = System.getProperty("line.separator");
        }
        else
        {
            c = new Character((char)code);
            s = c.toString();
        }
        return s;
    }


    public static Variant CHR(Variant varnumber) throws HpException
    {
        int         code=0;
        Character   c;
        VString     v = null;

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

		if(  code==13   &&
                  !System.getProperty("os.name").equalsIgnoreCase("Windows Nt") &&
        	      !System.getProperty("os.name").equalsIgnoreCase("Windows 95") )
        {
            v = new VString( System.getProperty("line.separator") );
        }
        else
        {
            c = new Character((char)code);
            v = new VString( c.toString() );

⌨️ 快捷键说明

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