想用就用,VB基础代码[2]

[入库:2005年8月18日] [更新:2007年3月24日]

本文简介:选择自 csdntoll 的 blog

msgbox datagrid1.columns(0).text
end sub

private sub form_load()
adodc1.connectionstring = "provider=sqloledb.1;persist security info=false;user id=sa;initial catalog=test;data source=server"
adodc1.commandtype = adcmdtext
adodc1.recordsource = "select * from test"
adodc1.refresh
set datagrid1.datasource = adodc1
datagrid1.allowupdate = false
end sub

'========================================================
'七、如何adodb对象绑定datagrid控件
'========================================================

private sub form_load()
dim conn as adodb.connection
dim rst as adodb.recordset

set conn = new adodb.connection
set rst = new adodb.recordset
conn.connectionstring = "provider=sqloledb.1;persist security info=false;user id=sa;initial catalog=test;data source=server"
conn.open , "sa"

rst.cursorlocation = aduseclient

rst.open "select * from table1", conn, adopendynamic, adlockoptimistic
set datagrid1.datasource = rst

end sub

'========================================================
'八、日期函数的使用以及使用fileexists判断文件是否存在
'========================================================
private sub command1_click()
if isnumeric(text1.text) and instr(text1.text, ".") = 0 and instr(text1.text, "-") = 0 then
   if clng(text1.text) > 0 and clng(text1.text) <= 12 then
      msgbox datediff("d", dateserial(year(now()), text1.text, 1), dateadd("m", 1, dateserial(year(now()), text1.text, 1)))
   else
      msgbox "error"
   end if
else
   msgbox "error, wrong value"
end if
end sub

private sub command2_click()
dim fso as object
set fso = createobject("scripting.filesystemobject")
    if fso.fileexists("c:\command.com") = true then
       msgbox "c:\command.com 文件已存在"
    else
       msgbox "c:\command.com 文件不存在"
    end if

set fso = nothing
end sub

'========================================================
'九、十进制与二进制的简单算法。
'========================================================

private sub command1_click()
dim a, b as long
dim c as string
a = text1.text
do
   if a = 0 then exit do
   if a > 1 then
      b = a mod 2
   else
      b = a
   end if
   c = cstr(b) & cstr(c)
   a = a \ 2
loop
text2.text = c
end sub

private sub command2_click()
dim a, b as string
dim i, c, d as long
a = text2.text

for i = 1 to len(a)
    c = clng(mid(a, i, 1))
    if c = 1 then
       d = d + 2 ^ (len(a) - i)
    end if
next
text3.text = d
end sub


'========================================================
'十七、在容器中移动控件
'========================================================
public ismove as boolean
public bx, by as long

private sub form_load()
ismove = false
end sub

private sub label1_mousedown(button as integer, shift as integer, x as single, y as single)
if button = 1 then
   ismove = true
   bx = x
   by = y
end if
end sub

private sub label1_mousemove(button as integer, shift as integer, x as single, y as single)
if button = 1 and ismove then
   label1.move x + label1.left - bx, y + label1.top - by
end if
end sub

private sub label1_mouseup(button as integer, shift as integer, x as single, y as single)
ismove = false
end sub

'========================================================
'十八、如何在运行程序的时候获得外部参数
'========================================================
private sub form_load()
dim paraarray() as string
dim getstring as string
dim i as long
getstring = trim(command())
if instr(getstring, "/") = 1 then
   if len(getstring) > 1 then
      getstring = right(getstring, len(getstring) - 1)
      paraarray = split(getstring, "/", -1, vbtextcompare)
      for i = 0 to ubound(paraarray())
          msgbox "parameter " & i + 1 & ": = " & trim(paraarray(i))
      next
   else
      msgbox "empty parameter!"
   end if
else
   if instr(getstring, "/") = 0 then
      msgbox "no parameter! "
   else
      msgbox "wrong format"
   end if
end if

本文关键:VB 代码
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top