1、VB知识点基本数据类型:数值:Integer Long Single Double Currency字符:String日期:Date time now year(now)逻辑:Boolean false true逻辑与数值之间的相互转换问题Dim a as integer,b as booleanA=6B=a数值型转换到逻辑型:非零的数为真值,0为假值Dim a as integer,b as booleanB=TrueA=b逻辑型转换到数值型:真值等于-1,假值等于0True false 字符与数值之间的转换问题“12” 1212 “ 12”Val(“a12.bjjh”) 0Str( )运算
2、符:1、算术运算符: - * / mod +/-2、字符串连接:+ &3、关系运算符: = = “A” and C=65 and asc(c)=”0” and C2*a or a=c and bc or cdFalse false true false输入与输出:输入: inputbox(“输入一个数”,” 输入信息” ,” 10 ” ) 返回值是字符串类型A=val(inputbox(“”)B=intputbox()C=a+bPrint c输出:I= Msgbox(“HELLO!” ,3, “HI”)Print form1.print print Picture1.print Cls Tab
3、(5) spc(5) Print tab(5) a spc(5) bPrint tab(5) a spc(10) bFormat Print format(sin(45*3.14/180),”00.000”)00.707精确问题:1四舍五入 format2 不四舍五入: int(sin(45*3.14/180)*1000)/1000Int( b+0.5) : 四舍五入取整Int(Rnd*(b-a+1)+a :a b 范围内的随机整数 A mod 10: 取A的个位数上的值A /100: 取A的百位数上的值A/10: 取A(A是两位数)的十位数上的值控件:对象名.属性 label1.captio
4、n captionForm1的对象名可以省略字体:fontname fontsize Fontbold =true /false FontItalic =true /false Fontunderline =true /false Fontstrithru =true /false字体颜色:前景色 Forecolor 大小:height width位置:left top Text1.left=text1.left+10控制: enabled visibledAlignment: 0 1 2 Timer commondialog :本身属于后台操作的控件,没有大小位置和字体的属性Line :X1
5、 Y1 X2 Y2 来设定控件的位置和长度Command :caption=“&Exit” default( enter) cancle(Esc)label :autosize text : text seltext selstart sellength text1.selstart=4 text1.sellength=2 multiline :是否支持多行显示 scrollbar passwordText控件接受键盘输入: setfocus (文本框可见) Text1.setfocus Change:跟踪文本变化Frame option check :frame对option和check进行
6、分组 Hscroll Vscroll:水平滚动条,竖直滚动条 Value:滚动框的值 Min Max之间。 Smallchange largechangeTimer:enable interval TimerListbox:列表框 combox:组合框(text+list)Style 下拉组合框 简单组合框,下拉列表框Listindex:ListList1.list(list1.listindex) combo1.list(combo1.listindex)Listcount :list1.list(list1.listcount-1)选择结构If ab then c=a else c=bIf
7、 a=60 then Print “及格”Elseif a=70 then Print “良好”Elseif a=80 then Print “中等”Elseif a=90 then Print “优秀”Endif Select case循环结构For 循环 do 循环 while 循环For i=1 to 3 For j=1 to iA=a+1 NextNextFor i=1 to 5Print tab(5-i); Fot i=1 to 2* i-1 Print “*”; NextPrint Next1+2+3+10S=0I=11Do S=S+i: i=i+1Loop while i=10
8、Print s1、a,b范围内满足某些条件进行累加或累乘S=1 For i=101 to 200If I mod 3=0 then i/3=i3 S=s*i EndifNext素数For n= 100 to 500Flag=0For i=2 to sqrt(n) If n mod i=0 thenFlag=1Exit for EndifNext If flag=0 then print nNextN 是否是水仙花数For n=200 to 500A=n 100B=(n mod 100)10C=n mod 10If n=a3+b3+c3 then .EndifNextFor 对字符串的处理S=text1For i=1 to len(s)Ch=mid(s,I,1)If ch= “ “ then N=n+1End ifnextFor 对字符串的处理:找出所有单词S=text1 ch1=”For i=1 to len(s)Ch=mid(s,I,1)If ch“ “ then Ch1=ch1&chElse List1.additem ch1 Ch1=”End ifnext
copyright@ 2008-2023 冰点文库 网站版权所有
经营许可证编号:鄂ICP备19020893号-2