图集1/1

正文 3593字数 549,760阅读


Public i As Integer Public j As Integer Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long Private Sub Form_Load() SetWindowPos Me.hwnd, -1, 0, 0, 0, 0, 3 ss = addition() Timer1.Enabled = True End Sub Private Function addition() Label1.Caption = Format(Now(), "HH时MM分") Label2.Caption = Format(Now(), "yyyy年m月d日") Dim i As Long i = Weekday(Now) Select Case i Case 1 Label2.Caption = Label2.Caption & " 周日" Case 2 Label2.Caption = Label2.Caption & " 周一" Case 3 Label2.Caption = Label2.Caption & " 周二" Case 4 Label2.Caption = Label2.Caption & " 周三" Case 5 Label2.Caption = Label2.Caption & " 周四" Case 6 Label2.Caption = Label2.Caption & " 周五" Case 7 Label2.Caption = Label2.Caption & " 周六" End Select End Function Private Sub Timer1_Timer() i = i + 1 j = j + 1 Label3.Caption = j If i = "50" Then i = 0 ss = addition() End If End Sub
Run code
Cut to clipboard


    vb的窗口运行时位于最前端
    在VB6.0里要先在最前面进行如下声明 Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long 在过程中加入 SetWindowPos Me.hwnd, -1, 0, 0, 0, 0, 3
    Run code
    Cut to clipboard

      就可以了,还原把 -1 改为 -2 。

      如果是VB.net就容易了,直接在窗体属性中设置TopMost属性就行了

      vb中日期显示格式
      Print Format(Now(), "yyyy年m月d日 HH时MM分SS秒")
      Run code
      Cut to clipboard


        VB函数if
        Dim aa as String '定义一个字符变量 aa="123" '字符变量定义 If aa="123" Then '判断aa的值是否与字符"123"相同 Msgbox "aa的内容是123。" Else Msgbox "aa的内容不是123。" End If
        Run code
        Cut to clipboard


          VB如何调用函数
          private Function fn1() as string '函数fn1,返回字符串类型的值 '函数体 fn1 = "你好" end Function private Function fn2(n as boolean) as string '函数fn2 fn2 = iif(n,"真","假") end function 调用时: dim str as string str = fn1 'str = "你好" str = fn2(true) 'str = "真"
          Run code
          Cut to clipboard


            VB编程显示星期几
            Private Sub Command1_Click() Dim i As Long i = Weekday(Now) Select Case i Case 1 Label1.Caption = " 星期天" Case 2 Label1.Caption = "星期一" Case 3 Label1.Caption = "星期二" Case 4 Label1.Caption = "星期三" Case 5 Label1.Caption = "星期四" Case 6 Label1.Caption = "星期五" Case 7 Label1.Caption = "星期六" End Select End Sub
            Run code
            Cut to clipboard


              vb语言获得系统时间
              Now:系统日期及时间 Date:系统日期 Time:系统时间 如text1.text=Now ‘显示系统日期及时间 text1.text=Date ‘显示系统日期 text1.text=Time ‘显示系统时间 用NOW()获得现在时间 data()获得年月日 weekday()获得星期 Option Explicit Private WithEvents Timer1 As Timer Private Sub Form_Load() Set Timer1 = Controls.Add("vb.timer", "timer1") Timer1.Interval = 1000 End Sub Private Sub Timer1_Timer() Cls Print Now End Sub 直接贴代码运行就可以看到了
              Run code
              Cut to clipboard