从 Option Explicit 开始的零碎知识点

本文介绍了一个使用Visual Basic编写的简单程序,该程序通过输入的成绩来评定学生的等级,并给出相应的鼓励或建议。


    这两天一直在围着 Visual Basic 转,敲了一些例子,记录了一些零碎的知识点,自己都觉得自己有点小幼稚,不过还好啦,至少没有放弃!

    

Option Explicit

'定义变量X
Dim x

Private Sub Form_Load()

  '弹出窗口以及窗口上的文字
  x = Val(InputBox("请输入0-100中的数值:", "成绩等级"))
  
  
  
  'Select Case 语句开始了哦
  Select Case x
  
  '如果是90到100分,那么就回复....
  Case 90 To 100
  lblscore.Caption = "优" & Chr(13) & "成绩不错,要保持哦!"

  '如果是80到90分,那么就回复....
  Case 80 To 89
  lblscore.Caption = "良" & Chr(13) & "还可以要继续努力,想优秀靠近啊!"
  
  '如果是70到80分,那么就回复“要努力啦,不然就落后啦”
  Case 70 To 79
  lblscore.Caption = "中" & Chr(13) & "要努力啦,不然就落后了"
  
  '如果是60到70分,那么就回复“加油了,马上及不及格了”
  Case 60 To 69
  lblscore.Caption = "差" & Chr(13) & "要努力啦,不然就不及格了"
  
  '如果是0到60分,那么就回复“你不及格”
  Case 0 To 59
  lblscore.Caption = "不及格" & Chr(13) & "你不及格"
  
  End Select
  
End Sub


    Option Explicit  ‘对未声明的变量发出警告

    Dim x



    Bitmap

    在窗体中添加一副图片


    If  Index = 1 Then 

    如果命令按钮的索引值为 1 ,里面的“Index”特意查了一查,涉及到具体的环境中会是针对“数组”这一东西出来的,当然,仅仅是目前这么理解。


 

    断句符:空格+下划线

    连接符:中间加“:”

    

Option Explicit
Dim delaytime As Integer                                '定义时间延迟的变量

Private Sub Form_Load()
  With lbl1
    .ForeColor = QBColor(12)                            '将标签框中文字的颜色设置为亮红色
    .Font = "创艺简魏碑"                                '设置标签框中文字的字体
    .FontSize = 36                                      '设置标签框中文字的字号
    .FontBold = True                                    '是标签框中的文字加粗显示
    .Left = (Me.Width - lbl1.Width) / 2                 '使标签框再窗体form1中垂直居中
    .Top = (Me.Height - lbl1.Height) / 2
  End With
  
  delaytime = 0                                         '时间延迟为0
  Timer1.Enabled = True                                 '计时器可用
End Sub


Private Sub Timer1_Timer()
  If delaytime >= 15 Then                               '若时间延迟大于15秒
   Timer1.Enabled = False                               '计时器不可用
   Unload Form1                                         '卸载窗体form1
   Form2.Show                                           '显示窗体form2
  Else                                                  '若时间延迟小于15秒
   delaytime = delaytime + 1                            '时间延迟加1
  End If
End Sub


    注释:

    ’+注释的语言

    Rme +注释的语言

 

 

 

   :关键字 TO 指定范围的时候,要注意To的下限要小于上线 a To b  :  a<b

   :Alignment :文字


   Val函数:表示将字符型数据转化为数值型数据

   字符“&”:这是链接字符,用于链接字符串或函数

   Chr(13):表示回车符

   


   Label2.Caption = "计算的结果为:" & Str(sum)     '求得的和放在标签框中

   If n Mod 5 = 0 Then     '如果n与5的余数为0


   零零散散,都是一些基础痕迹,跟自己对话,不要太在乎其他的,做自己。



  





excel密码破解详细教程,Public Sub AllInternalPasswords() ' Breaks worksheet and workbook structure passwords. Bob McCormick ' probably originator of base code algorithm modified for coverage ' of workbook structure / windows passwords and for multiple passwords ' ' Norman Harker and JE McGimpsey 27-Dec-2002 (Version 1.1) ' Modified 2003-Apr-04 by JEM: All msgs to constants, and ' eliminate one Exit Sub (Version 1.1.1) ' Reveals hashed passwords NOT original passwords Const DBLSPACE As String = vbNewLine & vbNewLine Const AUTHORS As String = DBLSPACE & vbNewLine & _ "Adapted from Bob McCormick base code by" & _ "Norman Harker and JE McGimpsey" Const HEADER As String = "AllInternalPasswords User Message" Const VERSION As String = DBLSPACE & "Version 1.1.1 2003-Apr-04" Const REPBACK As String = DBLSPACE & "Please report failure " & _ "to the microsoft.public.excel.programming newsgroup." Const ALLCLEAR As String = DBLSPACE & "The workbook should " & _ "now be free of all password protection, so make sure you:" & _ DBLSPACE & "SAVE IT NOW!" & DBLSPACE & "and also" & _ DBLSPACE & "BACKUP!, BACKUP!!, BACKUP!!!" & _ DBLSPACE & "Also, remember that the password was " & _ "put there for a reason. Don't stuff up crucial formulas " & _ "or data." & DBLSPACE & "Access and use of some data " & _ "may be an offense. If in doubt, don't." Const MSGNOPWORDS1 As String = "There were no passwords on " & _ "sheets, or workbook structure or windows." & AUTHORS & VERSION Const MSGNOPWORDS2 As String = "There was no protection to " & _ "workbook structure or windows." & DBLSPACE & _ "Proceeding to unprotect sheets." & AUTHORS & VERSION Const MSGTAKETIME As String = "After pressing OK button this " & _ "will take some time." & DBLSPACE & "Amount of time " & _ "depends on how many different passwords, the " & _ "passwords, and your computer's specification." & DBLSPACE & _ "Just be patient! Make me a coffee!" & AUTHORS & VERSION Const MSGPWORDFOUND1 As String = "You had a Worksheet " & _ "Structure or Windows Password set." & DBLSPACE & _ "The password found was: " & DBLSPACE & "$$" & DBLSPACE & _ "Note it down for potential future use in other workbooks by " & _ "the same person who set this password." & DBLSPACE & _ "Now to check and clear other passwords." & AUTHORS & VERSION Const MSGPWORDFOUND2 As String = "You had a Worksheet " & _ "password set." & DBLSPACE & "The password found was: " & _ DBLSPACE & "$$" & DBLSPACE & "Note it down for potential " & _ "future use in other workbooks by same person who " & _ "set this password." & DBLSPACE & "Now to check and clear " & _ "other passwords." & AUTHORS & VERSION Const MSGONLYONE As String = "Only structure / windows " & _ "protected with the password that was just found." & _ ALLCLEAR & AUTHORS & VERSION & REPBACK Dim w1 As Worksheet, w2 As Worksheet Dim i As Integer, j As Integer, k As Integer, l As Integer Dim m As Integer, n As Integer, i1 As Integer, i2 As Integer Dim i3 As Integer, i4 As Integer, i5 As Integer, i6 As Integer Dim PWord1 As String Dim ShTag As Boolean, WinTag As Boolean Application.ScreenUpdating = False With ActiveWorkbook WinTag = .ProtectStructure Or .ProtectWindows End With ShTag = False For Each w1 In Worksheets ShTag = ShTag Or w1.ProtectContents Next w1 If Not ShTag And Not WinTag Then MsgBox MSGNOPWORDS1, vbInformation, HEADER Exit Sub End If MsgBox MSGTAKETIME, vbInformation, HEADER If Not WinTag Then MsgBox MSGNOPWORDS2, vbInformation, HEADER Else On Error Resume Next Do 'dummy do loop For i = 65 To 66: For j = 65 To 66: For k = 65 To 66 For l = 65 To 66: For m = 65 To 66: For i1 = 65 To 66 For i2 = 65 To 66: For i3 = 65 To 66: For i4 = 65 To 66 For i5 = 65 To 66: For i6 = 65 To 66: For n = 32 To 126 With ActiveWorkbook .Unprotect Chr(i) & Chr(j) & Chr(k) & _ Chr(l) & Chr(m) & Chr(i1) & Chr(i2) & _ Chr(i3) & Chr(i4) & Chr(i5) & Chr(i6) & Chr(n) If .ProtectStructure = False And _
### 回答1: Option ExplicitVBA (Visual Basic for Applications) 的一条语句,用于声明变量的类型。使用 Option Explicit 语句后,如果在代码中使用了未声明的变量,则编译器会报错。这可以帮助你避免因为打字错误或变量名拼写错误而导致的 bug。 示例: ``` Option Explicit Dim x As Integer x = "abc" ' 编译器会报错,因为 x 是整数类型,不能赋值为字符串。 ``` ### 回答2: "Option Explicit" 是一种在编写VBA(Visual Basic for Applications)代码时使用的语句。 这个语句的作用是确保变量在使用之前都已经被声明。通常情况下,VBA会自动创建变量,但有时候这可能会导致意外的错误。使用 "Option Explicit" 可以防止这种情况的发生。 当我们在代码的顶部加入 "Option Explicit" 语句后,就需要在使用变量前先进行声明。例如,如果我们声明了一个变量 "x",那么在代码的其他地方就不能再使用其他名为 "x" 的变量,这样可以避免潜在的混淆。 另外, "Option Explicit" 还有助于提高代码的可读性和可维护性。通过强制要求进行显式的变量声明,我们可以更清楚地了解在代码中使用了哪些变量,以及它们的数据类型是什么。这对于自己和其他开发人员来说都是非常有价值的,因为它可以减少错误和调试时间。 总而言之, "Option Explicit" 是一种编写VBA代码时可以使用的语句。它确保变量在使用之前都已经被声明,提高了代码的可读性和可维护性,同时也减少了潜在的错误。 ### 回答3: Option Explicit是一个用于在VBA代码中强制显式声明变量的语句。它的作用是在代码执行之前,要求开发人员明确地声明所有的变量,确保变量的类型和作用域被正确定义和使用。 在VBA中,默认情况下,可以不用明确地声明变量就可以直接使用。但是,这样的写法容易导致变量的类型错误或作用域混淆,从而引发错误和难以追踪的Bug。 使用Option Explicit语句后,VBA编译器将强制要求在代码中使用的每个变量都必须进行明确的声明。这意味着在使用变量之前,必须通过Dim、Public、Private等语句来声明该变量的类型和作用域。如果没有进行明确的声明,编译器将会报错,从而提醒开发人员进行修正。 Option Explicit语句的好处是可以提高代码的可读性和可维护性。通过明确地声明变量,有助于减少变量类型错误,使得代码更加健壮和可靠。此外,它还能够帮助开发人员更好地理解和维护大型项目或团队合作中的代码,减少代码中的混乱和错误。 总之,Option Explicit是一种良好的编程实践,它强制要求在VBA代码中明确地声明变量,从而提高代码的可读性、可维护性和可靠性。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值