ITeye博客

vb代码2

xus799ov · 2012-01-17 06:10 · 技术杂绘 · 非技术 · Markdown

vb代码2 2010年11月21日   常用编程原码收集(二)   vb 中简单的记时效果   一个文本框,一个记数器   '程序代码   Dim a As Double   Private Sub Command1_Click()   a = Val(Trim(Text1.Text))   Timer1.Enabled = True   End Sub   Private Sub Form_Load()   Timer1.Interval = 1000   Timer1.Enabled = False   Text1 = ""   End Sub   Private Sub Timer1_Timer()   a = a + 1   Text1.Text = CStr(a)   End Sub   vb6****可以用鼠标移动无标题栏的窗体   '在设计阶段,将窗体的BorderStyle设置为0,ShowInTaskbar设置为True就可以了。移动窗体的代码如下:   Dim MoveScreen As Boolean   Dim MousX As Integer   Dim MousY As Integer   Dim CurrX As Integer   Dim CurrY As Integer   Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)   If Button = 1 Then   MoveScreen = True   MousX = X   MousY = Y   End If   End Sub   Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)   If MoveScreen Then   CurrX = Form1.Left - MousX + X   CurrY = Form1.Top - MousY + Y   Form1.Move CurrX, CurrY   End If   End Sub   Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)   MoveScreen = False   End Sub   VB6****中用什么代码判断某个文件是否存在   在编程时经常会用到判断文件是否存在,比如对文件做读写操作前,或是判断密钥文件是否存在等。判断的方法有很多,有些方法虽很实用,但有点繁琐。其实还可以有更简单的方法,就是使用vb 6.0提供的filesystemobject对象。   filesystemobject对象不是vb内置对象,使用前必须首先选择→,在出现的窗口中选择“microsoft scripting runtime”,然后利用filesystemobject的fileexists方法来判断文件是否存在。示例程序代码如下:   private sub command1_click()   ′引用filesystemobject对象   dim fs as new filesystemobject   ′利用filesystemobject对象的fileexists   ′方法判断文件是否存在   if fs.fileexists(〃c:*.gif〃) then   msgbox 〃文件存在〃   else   msgbox 〃文件不存在〃   end if   end sub   灵活运用filesystemobject对象可以解决与文件操作有关的大部分问题。   在vb中没有找到MAPI控件?打开VB的时候选择“企业版控件”就会有了。   **vb 中option控件选中的事件是什么   **   例如,控件名称是option1   那么option1.value=true表示选中   option1.value=flase表示不选.   如果全程调用或者说在模块中,要加上相应的窗体名   vb 点击按钮弹出 确认/取消对话框的方法   dim i as integer   i=msgbox ("确定删除?",vbyesno)   if i=vbyes   '确定后要执行的代码   else   '反之   end if   **VB中加一按钮想运行bat文件   **   Private Sub Command1_Click()   Shell (app.path & "\setup.bat")   End Sub   控件始终居窗口中间   Private Sub Form_Resize()
  With Text1
  .Left = (Me.ScaleWidth - .Width) / 2
  .Top = (Me.ScaleHeight - .Height) / 2
  End With
  End Sub   **vb 打开网页超级链接的方法源码   首先做一个声明   Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long   再建按钮或label等,将事件中加上下面这样的代码   **打开网页 ShellExecute hwnd, "Open", http://pc354.com", 0, 0, 0 (如果看到;,去掉;号)   发送邮件 ShellExecute hwnd, "Open", "mailto:pc354@163.com", "", App.Path, 1   在线QQ: ShellExecute hwnd, "Open", "tencent://Message/?Uin=888888&websiteName=q-zone.qq.com&Menu=yes", 0, 0, 0

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。