VB电子教程教你制作一个网上征求意见的WindowsCGI应用程序
创始人
2024-06-09 16:50:25
0

大家用VB5.0也很长时间了吧,对于VB5.0给我们带来的好处也深有体会,在这里VB电子教程教你制作一个关于网上征求意见的WindowsCGI应用程序的一个小案例。

VB电子教程教你制作一个网上征求意见的WindowsCGI应用程序

下面举一个较复杂实用的WindowsCGI程序,它由4个子过程组成:CGI_Main(),EnterGuest(),ReturnForm()和Inter_Main();它的功能是:服务器向申请连接的Web客户发出一张表单,Web客户在表单里填入有关数据后送回服务器,服务器收到Web客户的数据并将它们写入一个文件中存储起来,同时向Web客户发送一个收条。这个WindowsCGI应用程序的工作流程如下:一当Web客户要求CGI连接,服务器运行该CGI程序,首先执行CGI_Main()过程,CGI_Main()过程调用ReturnForm()向Web客户送出一个表单,如果Web客户填了意见表,并按键寄回服务器(此时过程CGI_Main()中CGI_RequestMethod="POST"成立)则由CGI_Main()过程调用EnterGuest()获取客户发来的数据并将其放入文件guestbk.csv中,同时向Web客户返回一个信息回条表示客户表单已收到。
由于编译使用这个CGI程序的做法与上面完全相同,故下面仅给源程序代码:

  1. OptionExplicit  
  2. ConstBOOK_FILE="guestbk.csv"'存放客户  
  3. 数据的文件,自动生成,可用Excel97调阅  
  4. DeclareSubSleepLib"kernel32"  
  5. (ByValdwMillisecondsAsLong)  
  6. SubCGI_Main()  
  7. IfCGI_RequestMethod="POST"Then 
  8. EnterGuest  
  9. Beep  
  10. Else  
  11. ReturnForm  
  12. EndIf  
  13. EndSub' 

一当Web客户要求CGI连接,服务器执行ReturnForm(),送出征求建议的表单:

  1. SubReturnForm()  
  2. Send"Content-type:text/html"  
  3. Send""  
  4. Send("</FONT></STRONG>贵州大学  <LI class=alt><STRONG><FONT color=#006699></< SPAN>TITLE></< SPAN>HEAD></FONT></STRONG>")  <LI class="">Send("<STRONG><FONT color=#006699><BODY><H2></FONT></STRONG>欢迎您访问贵州  <LI class=alt>大学计算机软件与理论研究所WWW站点<STRONG><FONT color=#006699></< SPAN>H1></FONT></STRONG>")  <LI class="">Send("我们的e-mail是<STRONG><FONT color=#006699><</FONT></STRONG><FONT color=#ff0000>AHREF</FONT><STRONG><FONT color=#006699>AHREF</FONT></STRONG>=""<FONT color=#0000ff>mailto</FONT>:"  <LI class=alt>&CGI_ServerAdmin&_  <LI class="">"""<STRONG><FONT color=#006699>></FONT></STRONG>lixiang@gzu.edu.cn:<STRONG><FONT color=#006699></< SPAN>A></FONT></STRONG>")  <LI class=alt>Send("<STRONG><FONT color=#006699><HR></FONT></STRONG>")  <LI class="">Send("请填下表,留下您的宝贵建议:")  <LI class=alt>Send("<STRONG><FONT color=#006699><</FONT></STRONG><FONT color=#ff0000>FORMACTION</FONT><STRONG><FONT color=#006699>FORMACTION</FONT></STRONG>=<FONT color=#0000ff>""</FONT>"  <LI class="">&CGI_ExecutablePath&"""<FONT color=#ff0000>METHOD</FONT>=<FONT color=#0000ff>""</FONT>POST""<STRONG><FONT color=#006699>></FONT></STRONG>")  <LI class=alt>Send("<STRONG><FONT color=#006699><PRE></FONT></STRONG>您的姓名:  <LI class=""><STRONG><FONT color=#006699><</FONT></STRONG><FONT color=#ff0000>INPUTSIZE</FONT><STRONG><FONT color=#006699>INPUTSIZE</FONT></STRONG>=<FONT color=#0000ff>25NAME</FONT>=""name""<STRONG><FONT color=#006699>></FONT></STRONG>")  <LI class=alt>Send("E-mail地址:  <LI class=""><STRONG><FONT color=#006699><</FONT></STRONG><FONT color=#ff0000>INPUTSIZE</FONT><STRONG><FONT color=#006699>INPUTSIZE</FONT></STRONG>=<FONT color=#0000ff>25NAME</FONT>=""email""<STRONG><FONT color=#006699>></FONT></STRONG>")  <LI class=alt>Send("您给我们的建议:<STRONG><FONT color=#006699><</FONT></STRONG><FONT color=#ff0000>TEXTAREACOLS</FONT><STRONG><FONT color=#006699>TEXTAREACOLS</FONT></STRONG>=<FONT color=#0000ff>40</FONT> <LI class=""><FONT color=#ff0000>ROWS</FONT>=<FONT color=#0000ff>4WRAP</FONT>=<FONT color=#ff0000>VIRTUALNAME</FONT>=<FONT color=#0000ff>""</FONT>comments""<STRONG><FONT color=#006699>></FONT></STRONG>")  <LI class=alt>Send("<STRONG><FONT color=#006699></< SPAN>TEXTAREA></< SPAN>PRE></FONT></STRONG>")  <LI class="">Send("请击此处将您的建议送我们:  <LI class=alt><STRONG><FONT color=#006699><</FONT></STRONG><FONT color=#ff0000>INPUTTYPE</FONT><STRONG><FONT color=#006699>INPUTTYPE</FONT></STRONG>=<FONT color=#0000ff>""</FONT>submit""")  <LI class="">Send("<FONT color=#ff0000>VALUE</FONT>=<FONT color=#0000ff>""</FONT>发送您的建议""<STRONG><FONT color=#006699>></FONT></STRONG>")  <LI class=alt>Send("<STRONG><FONT color=#006699><HR></FONT></STRONG>")  <LI class="">Send("<STRONG><FONT color=#006699></< SPAN>FORM></< SPAN>BODY></< SPAN>HTML></FONT></STRONG>")  <LI class=alt>EndSub  <LI class="">'获取客户建议表单数据,将所填数据存入文件guestbk.csv并向客户返回一个信息  <LI class=alt>SubEnterGuest()  <LI class="">DimiLockTriesAsInteger  <LI class=alt>DimsDateAsString  <LI class="">DimsNameAsString  <LI class=alt>DimsEmailAsString  <LI class="">DimsCommentsAsString  <LI class=alt>'DimsBrowserAsString  <LI class="">DimsFirstNameAsString  <LI class=alt>DimfnAsInteger  <LI class="">'提取建议的有关数据:  <LI class=alt><FONT color=#ff0000>sName</FONT>=<FONT color=#0000ff>GetSmallField</FONT>("name")  <LI class=""><FONT color=#ff0000>sEmail</FONT>=<FONT color=#0000ff>GetSmallField</FONT>("email")  <LI class=alt><FONT color=#ff0000>sComments</FONT>=<FONT color=#0000ff>GetSmallField</FONT>("comments")  <LI class=""><FONT color=#ff0000>iLockTries</FONT>=<FONT color=#0000ff>0</FONT> <LI class=alt><FONT color=#ff0000>fn</FONT>=<FONT color=#0000ff>FreeFile</FONT> <LI class="">OnErrorGoTogLockFail  <LI class=alt>gRetryLock:  <LI class="">OpenApp.Path+"\"+BOOK_FILEFor  <LI class=alt>AppendLockReadWriteAs#fn  <LI class="">OnErrorGoTo0  <LI class=alt><FONT color=#ff0000>sDate</FONT>=<FONT color=#0000ff>Now</FONT> <LI class="">Write#fn,sDate,sName,sEmail,  <LI class=alt>sComments,CGI_RemoteAddr  <LI class="">Close#fn  <LI class=alt><FONT color=#ff0000>sFirstName</FONT>=<FONT color=#0000ff>Trim</FONT>$(Left$(sName,  <LI class="">InStr(sName,"")))  <LI class=alt>IfsFirstName<STRONG><FONT color=#006699><></FONT></STRONG>""  <LI class=""><FONT color=#ff0000>ThensFirstName</FONT>=sFirstName&","  <LI class=alt>Send("Content-type:text/html")  <LI class="">Send("")  <LI class=alt>Send("<STRONG><FONT color=#006699><HTML><HEAD><TITLE></FONT></STRONG>谢谢您!  <LI class=""><STRONG><FONT color=#006699></< SPAN>TITLE></< SPAN>HEAD></FONT></STRONG>")  <LI class=alt>Send("您的签名与建议是:<STRONG><FONT color=#006699><PRE></FONT></STRONG>")  <LI class="">Send("日期:"&sDate)  <LI class=alt>Send("姓名:"&sName)  <LI class="">Send("E-Mail:"&sEmail)  <LI class=alt>Send("Hostaddress:  <LI class="">["&CGI_RemoteAddr&"]")  <LI class=alt>Send("建议:<STRONG><FONT color=#006699></< SPAN>PRE></FONT></STRONG>")  <LI class="">Send(sComments)  <LI class=alt>Send("<STRONG><FONT color=#006699><H2></FONT></STRONG>谢谢您!<STRONG><FONT color=#006699></< SPAN>H2></FONT></STRONG>")  <LI class="">Send("<STRONG><FONT color=#006699></< SPAN>BODY></< SPAN>HTML></FONT></STRONG>")  <LI class=alt>ExitSub  <LI class="">gLockFail:  <LI class=alt>Sleep(1000)  <LI class=""><FONT color=#ff0000>iLockTries</FONT><FONT color=#0000ff>iLockTries</FONT>=iLockTries+1  <LI class=alt>ResumegRetryLock  <LI class="">EndSub  <LI class=alt>SubInter_Main()  <LI class="">MsgBox"这是CGI程序,  <LI class=alt>需要在Web服务器中运行。",16,"CGI.BAS"  <LI class="">EndSub </LI></OL></PRE> <P>VB电子教程教你的案例,学会了吗!</P> <P>【编辑推荐】</P> <OL> <LI><FONT color=#0000ff>关于VB.NET基类继承、重载、隐藏的总结归纳</FONT></LI> <LI><FONT color=#0000ff>你是否了解VB.NET集成开发环境</FONT></LI> <LI><FONT color=#0000ff>深入分析VB.NET条件语句中的两类</FONT></LI> <LI><FONT color=#0000ff>五大类VB.NET运算符全面介绍</FONT></LI> <LI><FONT color=#0000ff>VB.NET实例教程之查询系统启动信息案例剖析</FONT></LI></OL> <!--end::Text--> </div> <!--end::Description--> <div class="mt-5"> <!--关键词搜索--> </div> <div class="mt-5"> <p class="fc-show-prev-next"> <strong>上一篇:</strong><a href="/chengxu/24184.html">研讨linux Emacs使用手册</a><br> </p> <p class="fc-show-prev-next"> <strong>下一篇:</strong><a href="/chengxu/24186.html">网络购物——可信的网站身份加安全支付方式</a> </p> </div> <!--begin::Block--> <div class="d-flex flex-stack mb-2 mt-10"> <!--begin::Title--> <h3 class="text-dark fs-5 fw-bold text-gray-800">相关内容</h3> <!--end::Title--> </div> <div class="separator separator-dashed mb-9"></div> <!--end::Block--> <div class="row g-10"> </div> </div> <!--end::Table widget 14--> </div> <!--end::Col--> <!--begin::Col--> <div class="col-xl-4 mt-0"> <!--begin::Chart Widget 35--> <div class="card card-flush h-md-100"> <!--begin::Header--> <div class="card-header pt-5 "> <!--begin::Title--> <h3 class="card-title align-items-start flex-column"> <!--begin::Statistics--> <div class="d-flex align-items-center mb-2"> <!--begin::Currency--> <span class="fs-5 fw-bold text-gray-800 ">热门资讯</span> <!--end::Currency--> </div> <!--end::Statistics--> </h3> <!--end::Title--> </div> <!--end::Header--> <!--begin::Body--> <div class="card-body pt-3"> <!--begin::Item--> <div class="d-flex flex-stack mb-7"> <!--begin::Symbol--> <div class="symbol symbol-60px symbol-2by3 me-4"> <div class="symbol-label" style="background-image: url('/static/assets/images/nopic.gif')"></div> </div> <!--end::Symbol--> <!--begin::Title--> <div class="m-0"> <a href="/chengxu/241137.html" class="text-dark fw-bold text-hover-primary fs-6">如何允许远程连接到MySQL数...</a> <span class="text-gray-600 fw-semibold d-block pt-1 fs-7">[[277004]]【51CTO.com快译】默认情况下,MySQL服务器仅侦听来自localhos...</span> </div> <!--end::Title--> </div> <!--begin::Item--> <div class="d-flex flex-stack mb-7"> <!--begin::Symbol--> <div class="symbol symbol-60px symbol-2by3 me-4"> <div class="symbol-label" style="background-image: url('/static/assets/images/nopic.gif')"></div> </div> <!--end::Symbol--> <!--begin::Title--> <div class="m-0"> <a href="/chengxu/61017.html" class="text-dark fw-bold text-hover-primary fs-6">如何利用交换机和端口设置来管理...</a> <span class="text-gray-600 fw-semibold d-block pt-1 fs-7">在网络管理中,总是有些人让管理员头疼。下面我们就将介绍一下一个网管员利用交换机以及端口设置等来进行D...</span> </div> <!--end::Title--> </div> <!--begin::Item--> <div class="d-flex flex-stack mb-7"> <!--begin::Symbol--> <div class="symbol symbol-60px symbol-2by3 me-4"> <div class="symbol-label" style="background-image: url('/static/assets/images/nopic.gif')"></div> </div> <!--end::Symbol--> <!--begin::Title--> <div class="m-0"> <a href="/chengxu/119031.html" class="text-dark fw-bold text-hover-primary fs-6">施耐德电气数据中心整体解决方案...</a> <span class="text-gray-600 fw-semibold d-block pt-1 fs-7">近日,全球能效管理专家施耐德电气正式启动大型体验活动“能效中国行——2012卡车巡展”,作为该活动的...</span> </div> <!--end::Title--> </div> <!--begin::Item--> <div class="d-flex flex-stack mb-7"> <!--begin::Symbol--> <div class="symbol symbol-60px symbol-2by3 me-4"> <div class="symbol-label" style="background-image: url('https://files.pic99.top/shayuweb/202409/eb2e03366045d9f.jpg')"></div> </div> <!--end::Symbol--> <!--begin::Title--> <div class="m-0"> <a href="/chengxu/139440.html" class="text-dark fw-bold text-hover-primary fs-6">20个非常棒的扁平设计免费资源</a> <span class="text-gray-600 fw-semibold d-block pt-1 fs-7">Apple设备的平面图标PSD免费平板UI 平板UI套件24平图标Freen平板UI套件PSD径向平...</span> </div> <!--end::Title--> </div> <!--begin::Item--> <div class="d-flex flex-stack mb-7"> <!--begin::Symbol--> <div class="symbol symbol-60px symbol-2by3 me-4"> <div class="symbol-label" style="background-image: url('/static/assets/images/nopic.gif')"></div> </div> <!--end::Symbol--> <!--begin::Title--> <div class="m-0"> <a href="/chengxu/27164.html" class="text-dark fw-bold text-hover-primary fs-6">2009 IBM动态架构新动力...</a> <span class="text-gray-600 fw-semibold d-block pt-1 fs-7"></span> </div> <!--end::Title--> </div> <!--begin::Item--> <div class="d-flex flex-stack mb-7"> <!--begin::Symbol--> <div class="symbol symbol-60px symbol-2by3 me-4"> <div class="symbol-label" style="background-image: url('/static/assets/images/nopic.gif')"></div> </div> <!--end::Symbol--> <!--begin::Title--> <div class="m-0"> <a href="/chengxu/225.html" class="text-dark fw-bold text-hover-primary fs-6">通过 XML 进行内容发布</a> <span class="text-gray-600 fw-semibold d-block pt-1 fs-7"></span> </div> <!--end::Title--> </div> <!--begin::Item--> <div class="d-flex flex-stack mb-7"> <!--begin::Symbol--> <div class="symbol symbol-60px symbol-2by3 me-4"> <div class="symbol-label" style="background-image: url('/static/assets/images/nopic.gif')"></div> </div> <!--end::Symbol--> <!--begin::Title--> <div class="m-0"> <a href="/chengxu/130901.html" class="text-dark fw-bold text-hover-primary fs-6">德国电信门户网站可实时显示全球...</a> <span class="text-gray-600 fw-semibold d-block pt-1 fs-7">德国电信周三推出一个门户网站,直观地实时提供其安装在全球各地的传感器网络检测到的网络攻击状况。该网站...</span> </div> <!--end::Title--> </div> <!--begin::Item--> <div class="d-flex flex-stack mb-7"> <!--begin::Symbol--> <div class="symbol symbol-60px symbol-2by3 me-4"> <div class="symbol-label" style="background-image: url('https://files.pic99.top/shayuweb/202503/5fe82cca6c5ff78.jpg')"></div> </div> <!--end::Symbol--> <!--begin::Title--> <div class="m-0"> <a href="/chengxu/246646.html" class="text-dark fw-bold text-hover-primary fs-6">为啥国人偏爱 Mybatis,...</a> <span class="text-gray-600 fw-semibold d-block pt-1 fs-7">关于 SQL 和 ORM 的争论,永远都不会终止,我也一直在思考这个问题。昨天又跟群里的小伙伴进行...</span> </div> <!--end::Title--> </div> <!--begin::Item--> <div class="d-flex flex-stack mb-7"> <!--begin::Symbol--> <div class="symbol symbol-60px symbol-2by3 me-4"> <div class="symbol-label" style="background-image: url('https://files.pic99.top/shayuweb/202407/404021d01b8347f.jpg')"></div> </div> <!--end::Symbol--> <!--begin::Title--> <div class="m-0"> <a href="/chengxu/48727.html" class="text-dark fw-bold text-hover-primary fs-6">《非诚勿扰》红人闫凤娇被曝厕所...</a> <span class="text-gray-600 fw-semibold d-block pt-1 fs-7">【51CTO.com 综合消息360安全专家提醒说,“闫凤娇”、“非诚勿扰”已经被黑客盯上成为了“木...</span> </div> <!--end::Title--> </div> <!--begin::Item--> <div class="d-flex flex-stack mb-7"> <!--begin::Symbol--> <div class="symbol symbol-60px symbol-2by3 me-4"> <div class="symbol-label" style="background-image: url('/static/assets/images/nopic.gif')"></div> </div> <!--end::Symbol--> <!--begin::Title--> <div class="m-0"> <a href="/chengxu/133934.html" class="text-dark fw-bold text-hover-primary fs-6">2012年第四季度互联网状况报...</a> <span class="text-gray-600 fw-semibold d-block pt-1 fs-7">[[71653]]  北京时间4月25日消息,据国外媒体报道,全球知名的云平台公司Akamai Te...</span> </div> <!--end::Title--> </div> </div> <!--end::Body--> </div> <!--end::Chart Widget 35--> </div> <!--end::Col--> </div> </div> <!--end::Content container--> </div> <!--end::Content--> </div> <!--end::Content wrapper--> <!--begin::Footer--> <div id="kt_app_footer" class="app-footer"> <!--begin::Footer container--> <div class="app-container container-xxl d-flex flex-column flex-md-row flex-center flex-md-stack py-3"> <!--begin::Copyright--> <div class="text-dark order-2 order-md-1"> <span class="text-muted fw-semibold me-1">2025 ©</span> <a href="/" target="_blank" class="text-gray-800 text-hover-primary">鲨鱼网</a> <a href="https://beian.miit.gov.cn/" target="_blank" class="text-gray-800 text-hover-primary"></a> <a href="http://spbjmm.com.shayuweb.com">上品网</a><a href="http://www.zzszq.net/">深知网</a><a href="http://www.taiyangwa.net/">太阳生活网</a><a href="http://baike.taiyangwa.net/">太阳百科网</a><a href="http://ypkjmy.com.shayuweb.com/">一品科技</a><a href="http://www.yuansudz.com/news/">元素网</a><a href="http://www.xn--i6qw12a.com/">帛典网</a><a href="http://xldmm.com.shayuweb.com/">星链岛</a> </div> <!--end::Copyright--> <!--begin::Menu--> <ul class="menu menu-gray-600 menu-hover-primary fw-semibold order-1"> <li class="menu-item"> <a href="/news/" target="_blank" class="menu-link px-2">科技资讯</a> </li> <li class="menu-item"> <a href="/chengxu/" target="_blank" class="menu-link px-2">程序开发</a> </li> <li class="menu-item"> <a href="/sitemap.xml" target="_blank" class="menu-link px-2">sitemap</a> </li> </ul> <!--end::Menu--> </div> <!--end::Footer container--> </div> <!--end::Footer--> </div> <!--end:::Main--> </div> <!--end::Wrapper--> </div> <!--end::Page--> </div> <!--end::App--> <div id="kt_scrolltop" class="scrolltop" data-kt-scrolltop="true"> <!--begin::Svg Icon | path: icons/duotune/arrows/arr066.svg--> <span class="svg-icon"> <svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"> <rect opacity="0.5" x="13" y="6" width="13" height="2" rx="1" transform="rotate(90 13 6)" fill="currentColor"></rect> <path d="M12.5657 8.56569L16.75 12.75C17.1642 13.1642 17.8358 13.1642 18.25 12.75C18.6642 12.3358 18.6642 11.6642 18.25 11.25L12.7071 5.70711C12.3166 5.31658 11.6834 5.31658 11.2929 5.70711L5.75 11.25C5.33579 11.6642 5.33579 12.3358 5.75 12.75C6.16421 13.1642 6.83579 13.1642 7.25 12.75L11.4343 8.56569C11.7467 8.25327 12.2533 8.25327 12.5657 8.56569Z" fill="currentColor"></path> </svg> </span> <!--end::Svg Icon--> </div> <!--begin::Javascript--> <script>var hostUrl = "/static/default/pc/";</script> <!--begin::Global Javascript Bundle(mandatory for all pages)--> <script src="/static/default/pc/plugins/global/plugins.bundle.js"></script> <script src="/static/default/pc/js/scripts.bundle.js"></script> <!--end::Global Javascript Bundle--> <!--end::Javascript--> </body> <!--end::Body--> </html>