如何编写VB实验代码按照要求,使用VB编写鸡兔同笼问题的代码

laoshi 心理科普 2023-11-13 19:39:07

导读:本文介绍了如何使用VB编写鸡兔同笼问题的代码,并提供了完整的代码样本。还介绍了如何编写“角谷猜想”的VB程序,以及如何编写“原始数据为”和“以下是计算结果”两道题目。如下为有关如何写vb实验代码,怎么用VB编写鸡兔同笼问题的代码,按下面图片中的要求写的文章内容,供大家参考。

1、如何写vb实验代码

Private Sub Command1_Click()

Dim s

For i = 1 To 6

If i Mod 2 = 0 Then

s = “-“

Else

s = “ “

End If

For j = 1 To i

s = s & Trim(Str(j))

Print s;

Next j

Print

Next i

End Sub

如何写vb实验代码

2、怎么用VB编写鸡兔同笼问题的代码,按下面图片中的要求写

Private Sub Command1_Click()

Dim tmp1 As Single, tmp2 As Integer

tmp1 = (Val(Text2) - 2 * Val(Text1)) / 2

tmp2 = Val(Text1) - tmp1

If Int(tmp1) tmp1 Or tmp1 < 0 Or tmp2 < 0 Then

Label1 = “wu jie“

Else

Label1 = “tu:“ & tmp1 & “ ji:“ & tmp2

End If

怎么用VB编写鸡兔同笼问题的代码,按下面图片中的要求写

3、用VB,下面的2道题怎么编程啊,求编码

呵呵,写了个代码,参考一下吧:

Private Function FirstName(Name As String) As String

Dim AAA As String

Dim I As Integer

For I = 1 To Len(Name)

AAA = Mid(Name, I, 1)

If AAA “ “ Then

FirstName = FirstName + AAA

Else

Exit Function

End If

Next

End Function

Private Function Hypotenuse(A As Single, B As Single) As Single

Hypotenuse = Sqr(A ^ 2 + B ^ 2)

End Function

Private Sub Command1_Click()

Dim N As String, M As String

N = InputBox(“请输入英文全名:“)

MsgBox (“全名中的名字为: “ & FirstName(N))

End Sub

Private Sub Command2_Click()

Dim A As Single, B As Single, C As Single

A = InputBox(“输入一条直角边长:“)

B = InputBox(“输入另一条直角边长:“)

C = Hypotenuse(A, B)

MsgBox (“直角三角形的斜边长:“ & C)

End Sub

用VB,下面的2道题怎么编程啊,求编码

4、如何编写“角谷猜想“的VB程序?

Private Sub Command1_Click()

Dim Num As Long

Dim I As Integer

Randomize

Num = Int(Rnd * 10000)

Picture1。Cls

Picture1。Print “原始数据为:“ & Num

Picture1。Print “以下是计算结果:“

I = 0

Do While Num 1

If Num Mod 2 = 0 Then

Num = Num / 2

Else

Num = Num * 3 + 1

End If

Picture1。Print Num;

I = I + 1

If I Mod 10 = 0 Then Picture1。Print

Loop

End Sub

5、用vb怎样编写哥德巴赫猜想的函数??

‘字符串,判断其是否为回文

Private Sub Command1_Click()

Cls

If Len(Text1。Text) Mod 2 = 0 Then

If Left(Text1。Text, Len(Text1。Text) / 2) = StrReverse(Right(Text1。Text, Len(Text1。Text) / 2)) Then

Print “““ & Text1。Text & “”是回文“

Else

Print “““ & Text1。Text & “”不是回文“

End If

Else

If Left(Text1。Text, (Len(Text1。Text) + 1) / 2) = StrReverse(Right(Text1。Text, (Len(Text1。Text) + 1) / 2)) Then

Print “““ & Text1。Text & “”是回文“

Else

Print “““ & Text1。Text & “”不是回文“

End If

End If

End Sub

6、用VB编写一个与RS232有关的测试程序

VB 6。0的测试代码如下: 可以做参考,用MSComm1控件

Dim i As Integer

Dim a As Integer

Dim t() As Byte

Private Sub Command1_Click()

If Command1。Caption = “打开串口“ Then

‘Shape1。Visible = True

Shape1。FillColor = &HFF&

Shape1。BackColor = &HFF&

Shape1。BorderColor = &HFF&

Command2。Enabled = True

Command3。Enabled = True

Command1。Caption = “关闭串口“

‘MSComm1。CommPort = 1 ‘设定Com1口

MSComm1。CommPort = Combo1。Text ‘设定Com1口

If MSComm1。PortOpen = False Then

‘MSComm1。Settings = “4800,N,8,1“ ‘4800波特率,无校验,8位数据位,1位停止位

MSComm1。Settings = Combo2。Text & “,“ & Combo3。Text & “,“ & Combo4。Text & “,“ & Combo5。Text ‘4800波特率,无校验,8位数据位,1位停止位

MSComm1。InputLen = 1 ‘读取接收缓冲区的所有字符

MSComm1。InputLen = 5

MSComm1。InBufferSize = 5 ‘设置接收缓冲区为1024字节

MSComm1。OutBufferSize = 5 ‘设置发送缓冲区为512字节

MSComm1。SThreshold = 0 ‘不触发发送事件

MSComm1。RThreshold = 1 ‘每一个字符到接收缓冲区都触发接收事件

MSComm1。PortOpen = True ‘打开串口

End If

MSComm1。OutBufferCount = 0 ‘清空发送缓冲区

MSComm1。InBufferCount = 0 ‘清空接收缓冲区

Dim temp() As Byte

Else

‘Option2。Value = False

‘Option1。Value = False

‘Shape1。Visible = False

Shape1。BackColor = &H808080

Shape1。BorderColor = &H808080

Shape1。FillColor = &H808080

Command2。Enabled = False

‘Command3。Enabled = False

MSComm1。PortOpen = False

Command1。Caption = “打开串口“

End If

End Sub

Private Sub Command2_Click()

‘Command2。Enabled = False

‘Option2。Value = False

‘Option1。Value = False

‘Shape2。Visible = False

MSComm1。OutBufferCount = 0 ‘清空发送缓冲区

MSComm1。InBufferCount = 0 ‘清空接收缓冲区

‘t(0) = “255“

‘ MSComm1。Output = t

MSComm1。Output = Text2。Text

End Sub

Private Sub Command3_Click()

Text1。Text = ““

End Sub

Private Sub Command5_Click() ‘退出

End

End Sub

Private Sub Command6_Click()

Text2。Text = ““

End Sub

Private Sub Command7_Click()

If Command7。Value Then

‘Command7。Visible = False

Command1。Visible = True

Command2。Visible = True

Command3。Visible = True

Command6。Visible = True

Label1。Visible = True

Label2。Visible = True

Label3。Visible = True

Label4。Visible = True

Label5。Visible = True

Label6。Visible = True

Label7。Visible = True

Combo1。Visible = True

Combo2。Visible = True

Combo3。Visible = True

Combo4。Visible = True

Combo5。Visible = True

Text1。Visible = True

Text2。Visible = True

Frame1。Visible = True

Frame2。Visible = False

‘Command3。Visible = False

‘Option1。Value = False

Shape1。Visible = True

Else

Label1。Visible = False

Label2。Visible = False

Label3。Visible = False

Label4。Visible = False

Label5。Visible = False

Label6。Visible = False

Label7。Visible = False

Combo1。Visible = False

Combo2。Visible = False

Combo3。Visible = False

Combo4。Visible = False

Combo5。Visible = False

Command1。Visible = False

Command2。Visible = False

Command3。Visible = False

Text1。Visible = False

Text2。Visible = False

Frame1。Visible = False

Frame2。Visible = False

End If

End Sub

Private Sub Form_Load()

MSComm1。InBufferCount = 0 ‘清除发送缓冲区数据

MSComm1。OutBufferCount = 0 ‘清除接收缓冲区数据

ReDim t(0)

t(0) = “0“

Combo1。AddItem “1“

Combo1。AddItem “2“

Combo1。AddItem “3“

Combo1。AddItem “4“

‘Combo1。Text = “1“

Combo2。AddItem “300“

Combo2。AddItem “600“

Combo2。AddItem “1200“

Combo2。AddItem “2400“

Combo2。AddItem “4800“

Combo2。AddItem “9600“

Combo2。AddItem “19200“

Combo3。AddItem “N“

Combo3。AddItem “O“

Combo3。AddItem “E“

Combo4。AddItem “8“

Combo4。AddItem “7“

Combo4。AddItem “6“

Combo5。AddItem “1“

Combo5。AddItem “2“

Combo5。AddItem “3“

End Sub

Private Sub Frame2_DragDrop(Source As Control, X As Single, Y As Single)

End Sub

Private Sub MSComm1_OnComm()

Dim s1 As String

Dim s2 As String

Select Case MSComm1。CommEvent

Case comEventOverrun ‘数据丢失

Text_SEND。Text = ““ ‘清空发送缓冲区

Text_RECV。Text = ““ ‘清空接收缓冲区

Text_SEND。SetFocus

Exit Sub

Case comEventRxOver ‘接收缓冲区溢出

Text_SEND。Text = ““ ‘清空发送缓冲区

Text_RECV。Text = ““ ‘清空接收缓冲区

Text_SEND。SetFocus

Exit Sub

Case comEventTxFull ‘发送缓冲区已满

Text_SEND。Text = ““ ‘清空发送缓冲区

Text_RECV。Text = ““ ‘清空接收缓冲区

Text_SEND。SetFocus

Exit Sub

Case comEvReceive ‘接收字符数据

Dim Buffer As Variant

MSComm1。InputLen = 1

MSComm1。InputMode = comInputModeBinary ‘二进制传输

Buffer = MSComm1。Input

‘Text1。Text = Buffer(0)

‘s2 = Buffer(1)

Text1。Text = Text1。Text & (Val(MSComm1。Input)) & “ “

Case Else

End Select

End Sub

Private Sub Option1_Click()

End Sub

心理学(XLX.NET)文章,转载需注明出处 https://www.xlx.net/xinlikepu/37357.html

AI角色模拟

AI心理咨询师
您好,我是心语者,一名资深心理咨询师,愿倾听您的困扰并提供支持与建议。

开启对话

我是AI女友
嗨,我是你的恋爱女友,一个小少女,爱撒娇卖萌,偶尔耍点小脾气,快来聊吧!

开启对话