• 首页>范文 > 范文
  • vb代码怎么写

    1.vb代码怎么写

    Private Sub Command1_Click()

    If Option1.Value = True Then

    Text2 = Sin(Val(Text1))

    End If

    If Option2.Value = True Then

    Text2 = Exp(Val(Text1))

    End If

    If Option3.Value = True Then

    Text2 = Sqr(Val(Text1))

    End If

    If Check1.Value = 1 Then

    Text2.FontBold = True

    End If

    If Check2.Value = 1 Then

    Text2.FontItalic = True

    End If

    End Sub

    Private Sub Form_Load()

    Label1.Caption = "参数"

    Label2.Caption = "结果"

    Command1.Caption = "计算"

    frame1.Caption = ""

    frame2.Caption = ""

    Option1.Caption = "sin"

    Option2.Caption = "exp"

    Option3.Caption = "sqr"

    Check1.Caption = "粗体"

    Check2.Caption = "斜体"

    Text1 = 4

    Text2 = ""

    Text2.BackColor = &H80000006

    Text2.BorderStyle = 0

    Text2.FontSize = 20

    Option3.Value = True

    End Sub

    2.关于vb的程序代码怎么写

    '能产生霓虹灯效果的代码'在窗体上添加控件 Picture1、Timer1'在窗体上添加控件 Shape1,并在属性窗口设置 Shape1 的属性 Name=Sha , Index=0'在窗体上添加控件 Combo1,并在属性窗口设置 Combo1 的属性 Name=Comb , Index=0'将以下代码添加到窗体代码中 Dim ctP As Single, ctLei As Long, ctX0 As Single, ctY0 As Single, ctSize As Single Dim ctRefresh As Boolean, ctA As Single, ctB As Single, ctX1 As Single, ctY1 As Single Private Sub Form_Load() Dim I As Long, K As Long Me.Caption = "闪光函数" Set Sha(0).Container = Picture1 Sha(0).Visible = False: Timer1.Enabled = False Picture1.AutoRedraw = True For I = 1 To 3 Load Comb(I): Comb(I).Visible = True Next K = 0 For I = 0 To 19 If I < 10 Then Comb(K).AddItem I & " 个光点" Else Comb(K).AddItem (I - 9) * 10 & " 个光点" Next Comb(K).ListIndex = 10 K = 1 Comb(K).List(0) = "圆" Comb(K).List(1) = "椭圆" Comb(K).List(2) = "正弦" Comb(K).ListIndex = 1 K = 2 For I = 0 To 29 If I < 10 Then Comb(K).AddItem I & " 变速" Else Comb(K).AddItem (I - 9) * 10 & " 变速" Next Comb(K).ListIndex = 15 K = 3 For I = 0 To 9 Comb(K).AddItem I & " 线宽" Next Comb(K).ListIndex = 1 ctRefresh = True Call StartFlash End Sub Private Sub Form_Resize() Dim I As Long, L As Single, T As Single, W As Long, H As Long, Jg As Single Jg = Comb(0).Height * 0.2 T = Jg L = Jg For I = 0 To Comb.Count - 1 Comb(I).Move L, T L = L + Comb(I).Width + Jg Next T = Comb(0).Top + Comb(0).Height + Jg W = Me.ScaleWidth: H = Me.ScaleHeight - T Picture1.Move 0, T, W, H Call SetXY0 End Sub Private Sub SetXY0() ctA = Picture1.ScaleHeight * 0.4 '短轴 ctB = Picture1.ScaleWidth * 0.4 '长轴 Select Case ctLei Case 0, 1 '圆,椭圆 ctX0 = Picture1.ScaleWidth * 0.5 - ctSize: ctY0 = Picture1.ScaleHeight * 0.5 - ctSize Case 2 '正弦 ctX0 = Picture1.ScaleWidth * 0.05 - ctSize: ctY0 = Picture1.ScaleHeight * 0.5 - ctSize ctB = ctB * 1.1 End Select End Sub Private Sub Comb_Change(Index As Integer) Call StartFlash End Sub Private Sub Comb_Click(Index As Integer) Call StartFlash End Sub Private Sub StartFlash() Dim I As Long If Not ctRefresh Then Exit Sub ctLei = Comb(1).ListIndex '函数类型 ctP = 3.1415926 '圆周率 ctY1 = Val(Comb(2).Text) '短轴变换率(半径,位置等) ctX1 = ctY1 I = Val(Comb(3).Text) If I < 1 Then I = 1 If I > 9 Then I = 9 Picture1.DrawWidth = I If I < 5 Then I = 5 ctSize = I * 15 '60 '光点大小 Sha(0).FillColor = 255 '&HFFFFFF Call SetXY0 Timer1.Tag = "1" Timer1.Interval = 25 Timer1.Enabled = True End Sub Private Sub Timer1_Timer() Static n As Single, Ci As Long Dim X As Single, Y As Single, S As Single If Timer1.Tag <> "" Then Call LoadSha ctA = ctA + ctY1 If ctA > ctY0 Then ctY1 = -Abs(ctY1) If ctA <= 0 Then ctY1 = Abs(ctY1) ctB = ctB + ctX1 If ctLei = 2 Then '正弦 If ctB > Picture1.ScaleWidth * 0.45 Then ctX1 = -Abs(ctX1) Else If ctB > ctX0 Then ctX1 = -Abs(ctX1) End If If ctB <= 0 Then ctX1 = Abs(ctX1) Picture1.Cls If Val(Comb(3).Text) > 0 Then Call GetXY(0, X, Y) Picture1.PSet (X, Y) For S = 0 To ctP * 2 Step ctP / 270 Call GetXY(S, X, Y) Picture1.Line -(X, Y) Next End If n = n + ctP / 90 '180 If n > ctP * 2 Then n = 0 For I = 0 To Sha.Count - 1 S = n + I * ctP * 2 / Sha.Count If S > ctP * 2 Then S = S - ctP * 2 Call GetXY(S, X, Y) Sha(I).Move X - ctSize, Y - ctSize, ctSize * 2, ctSize * 2 Next' Timer1.Tag = "" End Sub Private Sub GetXY(n As Single, X As Single, Y As Single) Select Case ctLei Case 0 '圆 X = ctX0 + ctA * Sin(n) Y = ctY0 + ctA * Cos(n) Case 1 '椭圆 X = ctX0 + ctB * Sin(n) Y = ctY0 + ctA * Cos(n) Case 2 '正弦 X = ctX0 + n * ctB / ctP Y = ctY0 - ctA * Sin(n) End Select End Sub Private Sub LoadSha() Dim I As Long, S As Long Timer1.Tag = "" S = Val(Comb(0).Text) Sha(0).Shape = 3: Sha(0).Move 0, 0, ctSize, ctSize Sha(0).FillStyle = 0 If S > 0 Then Sha(0).Visible = True Else Sha(0).Visible = False For I = Sha.Count - 1 To 1 Step -1 Unload Sha(I) Next For I = 1 To S - 1 '光点数 Load Sha(I): Sha(I).Visible = True Next End Sub。

    3.vb代码怎么写

    Private Sub Command1_Click()

    Text1.Text = Replace(Text1.Text, [要查找的字符], [要替换的字符])

    End Sub

    '--------------------------------

    'Replace函数

    '描述

    '返回一个字符串,该字符串中指定的子字符串已被替换成另一子字符串,并且替换发生的次数也是指定的。

    '语法

    'Replace(expression, find, replacewith[, start[, count[, compare]]])

    'Replace函数语法有如下几部分:

    '部分 描述

    'expression 必需的。字符串表达式,包含要替换的子字符串。

    'find 必需的?要搜索到的子字符串?

    'replacewith 必需的?用来替换的子字符串?

    'start 可选的。在表达式中子字符串搜索的开始位置。如果忽略,假定从1开始。

    'count 可选的。子字符串进行替换的次数。如果忽略,缺省值是 –1,它表明进行所有可能的替换。

    'compare 可选的。数字值,表示判别子字符串时所用的比较方式。关于其值,请参阅“设置值”部分。

    '设置值

    'compare参数的设置值如下:

    '常数 值 描述

    'vbUseCompareOption –1 使用Option Compare语句的设置值来执行比较。

    'vbBinaryCompare 0 执行二进制比较。

    'vbTextCompare 1 执行文字比较。

    'vbDatabaseCompare 2 仅用于Microsoft Access。基于您的数据库的信息执行比较。

    '返回值

    'Replace的返回值如下:

    '如果 Replace返回值

    'expression长度为零 零长度字符串("")。

    'expression为Null 一个错误

    'find长度为零 expression的复本

    'replacewith长度为零 expression的复本,其中删除了所有出现的find 的字符串。

    'start > Len(expression) 长度为零的字符串。

    'ount is 0 expression.的复本。

    '说明

    'Replace函数的返回值是一个字符串,但是,其中从start所指定的位置开始,到expression字符串的结尾处的一段子字符串已经发生过替换动作。并不是原字符串从头到尾的一个复制。

    4.求VB代码怎么写,

    'check1、check2、check3为checkbox控件数组'check1、check2、check3的style属性设置为1 Private Sub Form_Load() Dim i As Integer Check1(0).Caption = "除7余0" For i = 1 To 6 Load Check1(i) Check1(i).Left = Check1(i - 1).Left + 800 Check1(i).Top = Check1(i - 1).Top Check1(i).Caption = "除7余" & i Check1(i).Visible = True Next i Check2(0).Caption = "除8余0" For i = 1 To 7 Load Check2(i) Check2(i).Left = Check2(i - 1).Left + 800 Check2(i).Top = Check2(i - 1).Top Check2(i).Caption = "除8余" & i Check2(i).Visible = True Next i Check3(0).Caption = "1到5" For i = 1 To 3 Load Check3(i) Check3(i).Left = Check3(i - 1).Left + 1500 Check3(i).Top = Check3(i - 1).Top Check3(i).Caption = i * 5 + 1 & "到" & (i + 1) * 5 Check3(i).Visible = True Next i Command1.Caption = "清除" Command2.Caption = "统计" Text1.Text = "" Text2.Text = "" End Sub Private Sub Command1_Click() Dim i As Integer For i = 0 To Check1.UBound Check1(i).Value = vbUnchecked Next For i = 0 To Check2.UBound Check2(i).Value = vbUnchecked Next For i = 0 To Check3.UBound Check3(i).Value = vbUnchecked Next Text1.Text = "" Text2.Text = "" End Sub Private Sub Command2_Click() Dim i As Integer, j As Integer, m As Integer Dim s As String Dim n(1 To 20) As Integer For i = 0 To Check1.UBound If Check1(i).Value = vbChecked Then s = s & " " & Check1(i).Caption For j = 1 To 20 If j Mod 7 = i Then n(j) = n(j) + 1 End If Next j End If Next For i = 0 To Check2.UBound If Check2(i).Value = vbChecked Then s = s & " " & Check2(i).Caption For j = 1 To 20 If j Mod 8 = i Then n(j) = n(j) + 1 End If Next j End If Next For i = 0 To Check3.UBound If Check3(i).Value = vbChecked Then s = s & " " & Check3(i).Caption For j = i * 5 + 1 To (i + 1) * 5 n(j) = n(j) + 1 Next j End If Next Text1.Text = Trim(s) s = "" j = 0 For i = 1 To 20 If n(i) > m Then m = n(i) End If Next For i = 0 To m If s = "" Then s = i & "次:" Else s = s & vbCrLf & i & "次:" End If For j = 1 To 20 If n(j) = i Then s = s & j & "," End If Next Next Text2.Text = s End Sub。

    5.下面的VB代码怎么写

    假设评委的分数在数组pingwei(10)中,代码如下:

    private sub cmd1_click()

    dim i,max,min,avc

    for i=1 to 10

    if i=1 then

    max=pingwei(i)

    min=pingwei(i)

    end if

    if max&lt;pingwei(i) then max=pingwei(i)

    if min&gt;pingwei(i) then min=pingwei(i)

    avc=avc+pingwei(i)

    next

    text1.text=max

    text2.text=min

    text3.text=(avc-max-min)/8

    end sub

    end if

    private sub cmd2_click()

    text1.text=""

    text2.text=""

    text3.text=""

    end sub

    private sub cmd3_click()

    end

    end sub

    6.这个vb代码怎样写

    楼上2位,题目要求是直到前后两项之差小于10^(-5)为止,而不是输入n的值来求。

    Private Sub Command1_Click()

    Dim i As Integer

    Dim f As Double

    Dim e As Double

    i = 1

    f = 1

    e = 2

    Do

    i = i + 1

    f = f / i

    e = e + f

    Loop While (f * i - f) >= 10 ^ -5

    Print e

    End Sub

    发表评论

    登录后才能评论