VB知识点.docx
《VB知识点.docx》由会员分享,可在线阅读,更多相关《VB知识点.docx(8页珍藏版)》请在冰点文库上搜索。
VB知识点
基本数据类型:
数值:
IntegerLongSingleDoubleCurrency
字符:
String
日期:
Datetimenowyear(now)
逻辑:
Booleanfalsetrue
逻辑与数值之间的相互转换问题
Dimaasinteger,basboolean
A=6
B=a
数值型转换到逻辑型:
非零的数为真值,0为假值
Dimaasinteger,basboolean
B=True
A=b
逻辑型转换到数值型:
真值等于-1,假值等于0
True>false
字符与数值之间的转换问题
“12”12
12“12”
Val(“a12.bjjh”)0
Str()
运算符:
1、算术运算符:
^-*/\mod+/-
2、字符串连接:
+&
3、关系运算符:
><<=>=><=
A=b的问题:
单独成行赋值语句
=或print后面
A=1:
b=2
Printa=b
C=a=b
字符串大小比较ascii
C>=“A”andC<=”Z”asc(c)>=65andasc(c)<=90
C>=”0”andC<=”9”4857
97122
32
4、逻辑运算符:
notandorXor
A=2b=3c=4d=5
3>2*aora=candb<>corc>d
Falsefalsetruefalse
输入与输出:
输入:
inputbox(“输入一个数”,”输入信息”,”10”)
返回值是字符串类型
A=val(inputbox(“”))
B=intputbox(‘’)
C=a+b
Printc
输出:
I=Msgbox(“HELLO!
”,3,“HI”)
Printform1.printprint
Picture1.print
Cls
Tab(5)spc(5)
Printtab(5)aspc(5)b
Printtab(5)aspc(10)b
Format
Printformat(sin(45*3.14/180),”00.000”)
00.707
精确问题:
1四舍五入format
2不四舍五入:
int(sin(45*3.14/180)*1000)/1000
Int(b+0.5):
四舍五入取整
Int(Rnd*(b-a+1))+a:
[ab]范围内的随机整数
Amod10:
取A的个位数上的值
A/100:
取A的百位数上的值
A/10:
取A(A是两位数)的十位数上的值
控件:
对象名.属性label1.captioncaption
Form1的对象名可以省略
字体:
fontnamefontsize
Fontbold=true/false
FontItalic=true/false
Fontunderline=true/false
Fontstrithru=true/false
字体颜色:
前景色Forecolor
大小:
heightwidth
位置:
lefttop
Text1.left=text1.left+10
控制:
enabledvisibled
Alignment:
012
Timercommondialog:
本身属于后台操作的控件,没有大小位置和字体的属性
Line:
X1Y1X2Y2来设定控件的位置和长度
Command:
caption=“&Exit”
default(enter)cancle(Esc)
label:
autosize
text:
text
seltextselstartsellength
text1.selstart=4
text1.sellength=2
multiline:
是否支持多行显示
scrollbar
password
Text控件接受键盘输入:
setfocus(文本框可见)
Text1.setfocus
Change:
跟踪文本变化
Frameoptioncheck:
frame对option和check进行分组
HscrollVscroll:
水平滚动条,竖直滚动条
Value:
滚动框的值
MinMax之间。
Smallchangelargechange
Timer:
enableinterval
Timer
Listbox:
列表框combox:
组合框(text+list)
Style下拉组合框简单组合框,下拉列表框
Listindex:
List
List1.list(list1.listindex)combo1.list(combo1.listindex)
Listcount:
list1.list(list1.listcount-1)
选择结构
Ifa>bthenc=aelsec=b
Ifa>=60then
Print“及格”
Elseifa>=70then
Print“良好”
Elseifa>=80then
Print“中等”
Elseifa>=90then
Print“优秀”
Endif
Selectcase
循环结构
For循环do循环while循环
Fori=1to3
Forj=1toi
A=a+1
Next
Next
Fori=1to5
Printtab(5-i);
Foti=1to2*i-1
Print“*”;
Next
Print
Next
1+2+3+…10
S=0
I=11
Do
S=S+i:
i=i+1
Loopwhilei<=10
Prints
1、[a,b]范围内满足某些条件进行累加或累乘
S=1
Fori=101to200
IfImod3=0theni/3=i\3
S=s*i
Endif
Next
素数
Forn=100to500
Flag=0
Fori=2tosqrt(n)
Ifnmodi=0then
Flag=1
Exitfor
Endif
Next
Ifflag=0thenprintn
Next
N是否是水仙花数
Forn=200to500
A=n\100
B=(nmod100)\10
C=nmod10
Ifn=a^3+b^3+c^3then
…..
Endif
Next
For对字符串的处理
S=text1
Fori=1tolen(s)
Ch=mid(s,I,1)
Ifch=““then
N=n+1
Endif
next
For对字符串的处理:
找出所有单词
S=text1ch1=””
Fori=1tolen(s)
Ch=mid(s,I,1)
Ifch<>““then
Ch1=ch1&ch
Else
List1.additemch1
Ch1=””
Endif
next