用VB编一个钟表,表针运动程序怎么编

用VB编一个钟表,表针运动程序怎么编,第1张

Const π As Single = 3.1415926

Dim t As Date, t0 As Date, t1 As Date, t2 As Date, k As Integer

Private Sub Command1_Click()

  Picture1.Cls

  For i = 0 To 59

    Picture1.Line ((90 * Cos(π / 2 + 6 * i * π / 180)), 90 * Sin(π / 2 + 6 * i * π / 180))-(95 * Cos(π / 2 + 6 * i * π / 180), 95 * Sin(π / 2 + 6 * i * π / 180)), vbBlue

  Next i

  Timer1.Interval = 1000

  k = 0

  Picture1.Line (0, 0)-(80 * Cos(π / 2 + 6 * k * π / 180), 80 * Sin(π / 2 + 6 * k * π / 180)), vbRed

  t0 = Time

End Sub

Private Sub Command2_Click()

  Timer1.Interval = 0

End Sub

Private Sub Form_Load()

  Picture1.AutoRedraw = True

  Picture1.Scale (-100, 100)-(100, -100)

  Picture1.PSet (0, 0)

  For i = 0 To 59

    Picture1.Line ((90 * Cos(π / 2 + 6 * i * π / 180)), 90 * Sin(π / 2 + 6 * i * π / 180))-(95 * Cos(π / 2 + 6 * i * π / 180), 95 * Sin(π / 2 + 6 * i * π / 180)), vbBlue

  Next i

  Picture1.Line (0, 0)-(80 * Cos(π / 2 + 6 * k * π / 180), 80 * Sin(π / 2 + 6 * k * π / 180)), vbRed

End Sub

Private Sub Timer1_Timer()

  Picture1.Cls

  Label1.Caption = CDate(Time - t0)

  For i = 0 To 59

    Picture1.Line ((90 * Cos(π / 2 + 6 * i * π / 180)), 90 * Sin(π / 2 + 6 * i * π / 180))-(95 * Cos(π / 2 + 6 * i * π / 180), 95 * Sin(π / 2 + 6 * i * π / 180)), vbBlue

  Next i

  k = k + 1

  Picture1.Line (0, 0)-(80 * Cos(π / 2 - 6 * k * π / 180), 80 * Sin(π / 2 - 6 * k * π / 180)), vbRed

  If k >= 59 Then k = 0

End Sub

为了程序的易用性,我建议,表格采用excel,但是表格个格式必须固定。建议格式:

第一列:序号;第二列:H;第三列:B

程序实现过程:

1、打开excel文件,可以添加一个通用对话框组件。

2、使用VB打开制定excel文件,示范如下:

Dim excelApp, ExcelBook, ExcelSheet

Set excelApp = CreateObject("Excel.Application")

Set ExcelBook = excelApp.Workbooks.Open(App.Path &"\excel\模板.xls")

excelApp.Visible = True

Set ExcelSheet = ExcelBook.Worksheets(1) '添加工作页

ExcelSheet.Activate

excelApp.DisplayAlerts = False

3、建立一个二维数组BH,循环读取BH对应数值

4、查询部分,根据H值遍历数组BH,给出对应B值。

5、注意事项

程序启动前excelApp, ExcelBook, ExcelSheet 清空,数组清空,这个是考虑连续打开若干个表格时候,避免出错。

数组需要采用动态数组,要用到Redim

Dim xm As String, nl As String, xb As String, xl As String, zy As String

Dim ah1 As String, ah2 As String, ah3 As String, ah4 As String

Private Sub Check1_Click()

If Check1.Value = 1 Then ah1 = "旅游" Else ah1 = ""

End Sub

Private Sub Check2_Click()

If Check2.Value = 1 Then ah2 = "体育" Else ah2 = ""

End Sub

Private Sub Check3_Click()

If Check3.Value = 1 Then ah3 = "音乐" Else ah3 = ""

End Sub

Private Sub Check41_Click()

If Check4.Value = 1 Then ah4 = "集邮" Else ah4 = ""

End Sub

Private Sub Command1_Click()

Text3.Text = "简历" & vbCrLf & "姓名:" & xm & vbCrLf & "年龄:" & nl & vbCrLf & "性别:" & xb & vbCrLf & "学历:" & xl & vbCrLf & "职业:" & zy & vbCrLf & "爱好:" & ah1 & ah2 & ah3 & ah4

End Sub

Private Sub Command2_Click()

Text1 = "": xm = ""

Text2 = "": nl = ""

Text3 = ""

Check1.Value = 0: ah1 = ""

Check2.Value = 0: ah2 = ""

Check3.Value = 0: ah3 = ""

Check4.Value = 0: ah4 = ""

End Sub

Private Sub Form_Load()

End Sub

Private Sub Option1_Click()

If Option1.Value = True Then xb = "男"

End Sub

Private Sub Option2_Click()

If Option2.Value = True Then xb = "女"

End Sub

Private Sub Option3_Click()

If Option3.Value = True Then xl = "大学"

End Sub

Private Sub Option4_Click()

If Option4.Value = True Then xl = "本科"

End Sub

Private Sub Option5_Click()

If Option5.Value = True Then xl = "研究生"

End Sub

Private Sub Option6_Click()

If Option6.Value = True Then zy = "教师"

End Sub

Private Sub Option7_Click()

If Option7.Value = True Then zy = "医生"

End Sub

Private Sub Option8_Click()

If Option8.Value = True Then zy = "公务员"

End Sub

Private Sub Text1_Change()

xm = Text1.Text

End Sub

Private Sub Text2_Change()

nl = Text2.Text

End Sub


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/yw/7963812.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-12
下一篇2023-04-12

发表评论

登录后才能评论

评论列表(0条)

    保存