• 2009-10-09

    vb.net - [VB]

    <%@ Page language="VB" %>

    <script runat="server">

    dim arrColors(5) as String
    sub Page_Load(obj as object, e as eventargs)
     arrColor(0) = "green"
     arrColor(1) = "red"
     arrColor(2) = "yellow"
     arrColor(3) = "blue"
     arrColor(4) = "violet"
     
     Response.Write("The first element is: ")
     Response.Write(arrColor(0)&"<p>")

     Response.Write("The third element is: ")
     Response.Write(arrColor(2) & "<p>")

    end sub
    </script>
    <html>
    <body>
    </body>
    </html>

    ReDim Preserver arrColor(12) 增加长度
    Erase arrColor 清空数组

    if (condition ) then
     some code
    end if

    Select Case variable
     Case option1
     code
     Case Else
      code
    End

    Select Case FirstName
     Case "sun"
     Response.Write("")
     Case "Paul"
     Response.Write("ds")
    End Select


    while condition
     code
    End While

    dim intCount as Integer = 1
    while intCount < 10 
      Response.Write(intCount & "<pr>")
     intCount = intCount -1;
    End While

    For intCount = 1 to 12
     Response.Write(intCount)
    Next

    在VB.NET中有两种分支逻辑:函数和子程序,去区别在于函数能返回信息,而子程序不能。

    Sub name(parameters)
     code
    End Sub

    function name(parameters) as type
     code
     Return value
    end function

    sub Page_Load(obj as object, e as eventargs)
     code
    end sub


    <script runat="server">
      sub Page_Load(obj as object, e as eventargs)
     MultiplyNumbers(3,4)
     MultiplyNumbers(3,6)
      end sub


      sub MultiplyNumbers(intA as integer, intB as integer)
     Response.Wirte(intA*intB &<br>)
      end sub
    </script>


    可选参数 function MutliplyNumbers(intA as integer, optional intB as integer) as Integer
    <script runat="server">
      Class Clock
     public second as integer
     public minute as integer
     public hour as integer
     
     sub SetTime(intSec as integer, intMin as integer,intHour as as integer)
      Second = integer
      Minute = intMin
      hour = intHour
     end sub
      End Class

    </script>

  • 2009-07-07

    事件处理

    #pragma once
    #include <atlstr.h>


    class CUccEvent;
    class CUccEventHandler
    {
    public:
     CUccEventHandler(){};
      virtual ~CUccEventHandler(){};
    public:
     virtual bool Do(LPCTSTR lpMsg) = 0{};
    };

     

    class CUccEvent
    {
    public:
     CUccEvent(void):m_pEventHder(NULL){}

     CUccEvent(CUccEventHandler* pEventHder){
      m_pEventHder = pEventHder;
     }

     virtual ~CUccEvent(void){
      m_pEventHder = NULL;
     }

    public:
     void Attach(const CUccEventHandler* pEventHder){
      m_pEventHder = (CUccEventHandler*)pEventHder;
     }

     CUccEventHandler* Detach(void){
      CUccEventHandler* pTemp = m_pEventHder;
      m_pEventHder = NULL;
      return pTemp;
     }

    public:
     virtual bool Fire(LPCTSTR lpMsg) = 0{
      if (NULL != m_pEventHder)
      {
       return m_pEventHder->Do(lpMsg);
      }else{
       return FALSE;
      }
     }
    private:
     CUccEventHandler* m_pEventHder;
    };


    class CUccGpEventHandler:public CUccEventHandler
    {
    public:
     CUccGpEventHandler(void){};
     virtual ~CUccGpEventHandler(){};
    public:
     virtual bool Do(LPCTSTR lpMsg)
     {
      return true;
     }
    };


    class CUccGpEvent:public CUccEvent
    {
    public:
     CUccGpEvent(CUccEventHandler* pEventHder):CUccEvent(pEventHder){};  
      ~CUccGpEvent(){};
    public:
     virtual bool Fire(LPCTSTR lpMsg){
      return CUccEvent::Fire(lpMsg);
     }
    };

  • 2009-06-26

    SQL查询


    转自: http://rzchina.net/node/3180


    写出一条SQL语句:取出表A中第31~40条记录(SQLServer,以自动增长的ID作为主键)

    注意:ID可能不是连续的。
    【考点】
    数据表中连续记录的查询方法。
    【出现频率】
    ★★★☆☆
    【解答】
     SELECT TOP 10 * FROM [A] WHERE [id] NOT IN(SELECT TOP 30 [id] FROM [A])
    【分析】
    这道题目非常简单,也有多种解答方法。这里作者用IN子句查询出表A的前30条记录,IN子句可确定指定的值是否与子查询或列表中的值相匹配,其语法格式如以下代码所示。
    用于测试的表达式 [ NOT ] IN( 子查询 | 表达式列表 [ ,...n ])
    为了查询到第31到第40记录,本题解答中在IN前面使用了NOT关键字,对IN子句的结果取反。即表A中所查询的记录要求id字段值不处于前30条记录的id字段值中,然后查询这些记录的前10条即可(TOP 10)。

  • 一 在程序开始点添加

     int tmpFlag = _CrtSetDbgFlag( _CRTDBG_REPORT_FLAG );
     tmpFlag |= _CRTDBG_LEAK_CHECK_DF;
     _CrtSetDbgFlag( tmpFlag );

    包含

    #define _CRTDBG_MAP_ALLOC
    #include<stdlib.h>
    #include<crtdbg.h>

    二 完整运行程序,出现调试信息

     

    三 在出现程序开始的位置

    _crtBreakAlloc = [内存分配的序号]

    四 运行程序,在[内存分配的序号]位置停下来.

  •  

     

     

     

     

     

    由于vs2008中不能添加Web 服务的引用.我的解决方法是,首先在VS2003中实现该功能,然后将访问Web service的H文件,添加到VS2008中.

     

    一.利用vs2003建立一个非托管的访问Web Service的程序,得到Web Serices的H文件。该文间包含了Web Services提供的API
    1.创建一个Mfc应用程序vs2003E2C,不选择"使用托管扩展"选项。
    2.右击项目,弹出在快捷菜单中选则"添加Web引用"菜单项.
    3.在添加Web引用的url中输入Web service的url."http://fy.webxml.com.cn/webservices/EnglishChinese.asmx",这是一个提供英语与汉语翻译的Webservice.
    4 点击"转到"按钮,然后就找到了这个WEBservice服务.
    5.在"Web引用中输入","E2CWebService",再单击"添加引用".编译器就会为我们编译生成"E2CWebService.h"文件.这就是我们访问Web Service的接口文件.
    6.在该程序中测试该websercice
    ///////////////////////////////////////////////////////////
    //
    //
     ::CoInitialize(NULL);
     using namespace EnglishChinese;

     CEnglishChineseT<> e2c;


     BSTR sKey = L"city";
     BSTR* pRet = new BSTR[5];
     int nLen = 0;
     HRESULT hr = e2c.TranslatorString(sKey, &pRet, &nLen);

     if (SUCCEEDED(hr))
     {
      CComBSTR br0(pRet[0]);
      CComBSTR br1(pRet[1]);
      CComBSTR br2(pRet[2]);
      CComBSTR br3(pRet[3]);//"城市"
      CComBSTR br4(pRet[4]);

     }

     ::CoUninitialize(); 
    //
    //
    //////////////////////////////////////////////////////////////
    二.从http://www.codeplex.com/AtlServer下载ATL的访问Web Servrice的文件,下载解压后为文件夹 ATL_Server_Code


    三.将在VS2008中添加ATL_Server_Code文件夹的配置
    1.options->Projects and Solutions->VC++ Directories
    2.在Show directoried for下拉框中选择"include files"
    3.新建一项,输入".\Atl_Server\Code\include".使用现对路径
    4.OK

    四.在VS2008的工程中包含Web Serices的H文件即可.调用的方法同上.