
Private Sub Command1_Click()
Dim r As Single, y As Integer
r = 13
Do While r <= 20
r = r 101
y = y + 1
Loop
Print "我国现有人口13亿,年增长率为1%," & y & "年后增加到20亿"
End Sub
MsgBox上的内容是静态静态的,如果要使它倒计时,必须自己建一个Form,然后在上面拖个Timer控件来实现。然后d出时用 Form1Show vbModal 使它像MsgBox那样作为模态窗口d出就行了~~
其实不用Hook,也不用模块,检查系统闲置时间已有专用函数,不必这么复杂。
完整代码如下:
Option Explicit
Private Declare Function GetLastInputInfo Lib "user32" (plii As LASTINPUTINFO) As Boolean
Private Declare Function GetTickCount Lib "kernel32" () As Long
Private Type LASTINPUTINFO
cbSize As Long
dwTime As Long
End Type
Dim lii As LASTINPUTINFO
Private Sub Form_Load()
Timer1Interval = 1000
liicbSize = Len(lii)
End Sub
Private Sub Timer1_Timer()
If GetLastInputInfo(lii) Then
If (GetTickCount - liidwTime) / 60000 >= 15 Then
Shell "shutdownexe -s -t 180"
Call MsgBox("由于本机15分钟没有 *** 作,如果3分钟后没有反应,系统将强制关机", vbYesNo + vbExclamation + vbDefaultButton2, "提示")
End If
End If
End Sub
vb6代码如下,添加模块,工程--属性--启动对象选择sub main
Sub main()
Open "c:\temp\25txt" For Input As #1
ClipboardClear
ClipboardSetText StrConv(InputB(LOF(1), 1), vbUnicode)
End Sub
Private Sub Command1_Click()
Text1Text = ""
Dim a As Integer
For i = 1000 To 9099
If Mid(i, 2, 1) = 0 Then
a = Val(Left(i, 1) & Right(i, 2))
If a 9 = i Then Text1Text = Text1Text & i & " "
End If
Next
End Sub
'或者是下面这种方法,可以少些执行时间。
Private Sub Command2_Click()
Text1Text = ""
Dim a As Integer
For i = 100 To 999
a = Val(Left(i, 1) & 0 & Right(i, 2))
If i 9 = a Then Text1Text = Text1Text & a & " "
Next
End Sub
都是三个2025 4050 6075
用VB做万年历,非常关键点就是农历写法,参考代码如下:
#Region " 返回农历 "
'返回农历
'cCalendarMaxSupportedDateTime 返回支持的最大日期,即2101-1-28
'cCalendarMinSupportedDateTime 返回支持的最小日期,即190-2-19
Private cCalendar As New SystemGlobalizationChineseLunisolarCalendar
Public Function PubFunGet_CNDate(ByVal sDateTime As Date) As String
cCalendar = New SystemGlobalizationChineseLunisolarCalendar
Dim lyear As Integer = cCalendarGetYear(sDateTime)
Dim lmonth As Integer = cCalendarGetMonth(sDateTime)
Dim lday As Integer = cCalendarGetDayOfMonth(sDateTime)
Dim lweek As Integer = cCalendarGetDayOfWeek(sDateTime)
'获取闰月, 0 则表示没有闰月
Dim leapMonth As Integer = cCalendarGetLeapMonth(lyear)
Dim isleap As Boolean = False
If (leapMonth > 0) Then
If (leapMonth = lmonth) Then
'闰月
isleap = True
lmonth = lmonth - 1
ElseIf (lmonth > leapMonth) Then
lmonth = lmonth - 1
End If
End If
Return StringConcat(GetLunisolarYear(lyear), IIf(isleap = True, "闰年", "年"), GetLunisolarMonth(lmonth), "月", GetLunisolarDay(lday))
End Function
'十天干
Private tiangan As String() = {"甲", "乙", "丙", "丁", "戊", "己", "庚", "辛", "壬", "癸"}
'十二地支
Private dizhi As String() = {"子", "丑", "寅", "卯", "辰", "巳", "午", "未", "申", "酉", "戌", "亥"}
'十二生肖
Private shengxiao As String() = {"鼠", "牛", "虎", "免", "龙", "蛇", "马", "羊", "猴", "鸡", "狗", "猪"}
'农历月
Private months As String() = {"正", "二", "三", "四", "五", "六", "七", "八", "九", "十", "十一", "十二(腊)"}
'农历日
Private days1 As String() = {"初", "十", "廿", "三"}
Private days As String() = {"一", "二", "三", "四", "五", "六", "七", "八", "九", "十"}
'返回农历年(天干 地支 生肖)
Private Function GetLunisolarYear(ByVal year As Integer) As String
GetLunisolarYear = ""
If (year > 3) Then
Dim tgIndex As Integer = (year - 4) Mod 10
Dim dzIndex As Integer = (year - 4) Mod 12
Return tiangan(tgIndex) & dizhi(dzIndex) & "[" & shengxiao(dzIndex) & "]"
End If
'无效的年份!
End Function
'返回生肖
Private Function GetShengXiao(ByVal sDateTime As Date) As String
Return shengxiao(cCalendarGetTerrestrialBranch(cCalendarGetSexagenaryYear(sDateTime)) - 1)
End Function
'返回农历月
Private Function GetLunisolarMonth(ByVal month As Integer) As String
GetLunisolarMonth = ""
If (month < 13 AndAlso month > 0) Then
Return months(month - 1)
End If
'无效的月份!
End Function
'返回农历日
Private Function GetLunisolarDay(ByVal day As Integer) As String
GetLunisolarDay = ""
If (day > 0 AndAlso day < 32) Then
If (day <> 20 AndAlso day <> 30) Then
Return StringConcat(days1((day - 1) \ 10), days((day - 1) Mod 10))
Else
Return StringConcat(days((day - 1) \ 10), days1(1))
End If
End If
'无效的日!
End Function
#End Region
以上就是关于请教用vb编写一个小程序、谢谢各位了全部的内容,包括:请教用vb编写一个小程序、谢谢各位了、初学请教VB小程序怎么编、小弟我用vb做 的一个小程序(检测鼠标键盘)等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)