vb程序设计编程科学计算机,sysu计算机程序设计VB编程.docx

顺序结构:

Dim varl As Integer, var2 As String

varl = 12345

var2 = InputBox (,?输入Var2二","输入对话框")

MsgBox(var2 & Chr(13) + Chr(10) & "varl二"& Str(varl))

J MsgBox(var2 & vbCrLf & "varl二"& Str(varl))

赋值类型

一、模仿第1题的实验,通过编程运行,理解变量、表达式和函数的定义、书写规则。

(1)在变量说明语句中,将变量A、变最B……变量J分别说明成什么类型,才能与下列 的值匹配。

325、546.2、5383149> 2003-12-31 > “ABCDEF”、 false 、“123456”、

3.2434E+I00、1.2563E+12

Dim a As Short

Dim

b

As

Single

Dim

c

As

Integer

Dim

d

As

Dcite

Dim

el

.At

> Siring

Dim

f

As

Boolean

Dim

g

As

String

Dim

h

As

Double

Dim

As

Single

Dim

j'

4

3) As Integer

a =

3.

25

b =

546.2

c =

53831

49

d = #12/31/2003# el = "ABCDEF" f = False

g = "123456"

h = 3.24E+100

i = 1.2563E+15

j (0, 0) = 456

MsgBox (a & vbCrLf & b & vbCrLf & c & vbCrLf & d & vbCrLf & el & vbCrLf & f & vbCrLf & g & vbCrLf & h & vbCrLf & i & vbCrLf & j(0, 0))

二、分析F列表达式的运算结果,衣窗体单击事件过程中,通过定义与运算结果类型相 符合的变量,并将运算结果赋值给已定义的对应变量。观察程序编写过程屮的语法编译提示。

1) I 322) + 10」23-引3) - sin(30°)4) e6+ln( +2.135)

2x4

5) 89&12o 89126) "AB"+STR(32.56)+"CD”

7) mid("student",5)= 2)8) Not (6>2) Or (7<9))

Dim x21, x22, x23, x24 As Single

Dim x25, x27, x28 As Boolean

Dim x26 As String

x21 = Sqrt (32 / (2 * 4))

x22 = +Abs(0. 123 - 3)

x23 = -Sin(30 * PT / 180)

x24 = Exp (6) + Log (2. 135)

x25 = 89 & 12 <> 8912

x26 = "AB" + Str (32.56) + "CD"

'x27 = Mid("student", 5) = "ent" And (5 > 2)

x27 = Microsoft. VisualBasic. Right (,/student,\ 3) = "ent" And (5 > 2)

x28 = Not (6 > 2) Or (7 < 9)

MsgBox(x21 & vbCrLf & x22 & vbCrLf & x23 & vbCrLf & x24 & vbCrLf & x25 & vbCrLf & x26 & vbCrLf & x27 & vbCrLf & x28)

三、

1、产牛一个100以内的随机整数

Dim y As Integer

y = Tnt (Rnd () ? 100)

MsgBox(y)

2、给出任意字符串,测其长度

Dim y As Striri£

Dim yl As Tnteger

y二程序设计语言〃

yl = Len(y)

MsgBox(y & "长度为"& yl)

3、在给出的字符串中找到stu的位置

Dim y As Integer

y = InStr(^abc student", "slu")

MsgBox (y)

4、去除字符屮"Visual C ++"中两端的空格

Dim y As String

y = TrimC Visual C ++”)

MsgBox("去除左边空格〃 & y & "去除右边空格")

5、测字符“我去资料室查资料”所占字节

Private Sub Button7_Click(ByVal sendcr As System. 0bject, ByVai e As System?EventArgs) Han

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值