VB文档读写和数据库读写的相关总结

来源:互联网 发布:mac设置iphone铃声2017 编辑:程序博客网 时间:2024/05/01 20:15

1.检查文档中文件夹是否存在,不存在就生成文件夹

if dir(“C:\ABC”)<>""  then

        文件存在

else

    文件不存在

     mkdir(“C:\ABC”)

end if

 

 

 2. 例如判断C:\Windows\System32\cmd.exe是否存在,如存在,就调用它 

If Dir("C:\Windows\System32\cmd.exe")<>"" Then 

    Shell "C:\Windows\System32\cmd.exe"

  End If   

 

2.2,文件的读取和写入

写到文件夹中:  Open CurrentDirect&"\Parent\Setup.txt" For Output As #1

                                Print #1 ,X1;Tab;X2

                               Print#1,X3;Tab;X2

                              Close #1

从文件夹中读取:Open CurrentDirect&"\Parent\Setup.txt" For Input As #1

                                Input#1 ,X1,X2

                                Input#1,X3,X2

                                Close #1

 

 

 

 

 

 

3,常用的格式化函数format

string1=format(Now(),“yyy-mmm-ddd”)

string2=format(a/33,"#0.000")

string3=format(“My Name is %6s”,“wind”)

 

4,如何从资料库中抓取东西

       相关资料: ADODB 是 Active Data Objects Data Base 的简称,它是一种 PHP 存取数据库的中间函式组件。 
       目前 ADODB最新版本是V5.16,支持的数据库种类非常的多,例如:MySQL, PostgreSQL, Interbase, Informix, Oracle, MS SQL 7, Foxpro, Access, ADO, Sybase, DB2 以及一般的 ODBC (其中 PostgreSQL、Informix、Sybase 的driver 是由自由软件社群发展之后贡献出来的)。
     
         实际使用时候:
Dim a  As New ADODB.Recordset
Dim b As New   xxxx.read()
   Set a=b.xxxx.out  //其中B为一个数据库接口
 
可以进行显示:
Set DataGrid.DataSource =a
DataGrid.Refresh
 
 
5,使用数据库元件ActiceX之前需要完成一些准备
1,首先需要讲元件放到C盘目录,最好是system32中
2,注册元件
        regsvr32  xxx.dll
(注销元件)
          regsvr32     /U  xxx.dll
 
 
6,对数据库做一些简单的操作之获得指定元素值
    a.Filter=“PNLNUM ' " +"1"+" ‘ and Serial ' ” +“1”+“ ' ”
    if a.RecordCount=1 then      // 说明找到了一笔资料
   string1=a.Fields(“lanwei1”).value       //获得PNLNUM 是1并且Serial 也是1 的那一条的 “lanwei1”的数值
获得之后我们可以将a复原:a.Filter=“”
 
7,Filter可以用来获得满足条件的资料
   dim iLen  as interger
   iLen=a.RecordCount     //获得了总共满足a条件的数据笔数
 
 
8,保存从数据库中读到的资料的方法
a.Save"D:\"+string1+Format(NOW,“yyyMMddhhmmss”)+“.xml”,adPersistXML 
 上面就以.XML的格式进行了保存
  

 

 

 

 

 

 

 

 

0 0
原创粉丝点击