不带参数的跨线程
{
{
}); t.Start(); } |
注意:Invoke应用在其他线程内部;
带参数的跨线程
{
}
{
} |
不带参数的跨线程
{
{
}); t.Start(); } |
注意:Invoke应用在其他线程内部;
带参数的跨线程
{
}
{
} |
Private Declare Function SetWindowText Lib “user32” Alias “SetWindowTextA” (ByVal hwnd As Long, ByVal lpString As String) As Long Private Sub Command1_Click() SetWindowText Form1.hwnd, “hellworld!” End Sub |
数学函数
Abs() 求绝对值
Sgn() 返回符号
字符串函数
Len(string) 获取字符串长度
Right(string,length) 截取字符串
Mid(string,start,length)截取字符串
Ltrim(string)前导去空格
RTrim(string)去后缀空格
Trim(string)去前导尾随空格
类型转换函数
Asc
Chr
Val
Str
判断函数
IsNull
IsNumeric
IsArray
日期和时间函数
Date
Now
Time
随机函数
Randomize初始化随机数生成器
Rnd
格式化函数
Format
2021年8月4日编写大纲;
《单片机编程魔法师之高级裸编程思想》 余灿基主编 张玮 张志柏 苏永刚编著 电子工业出版社。
《深入理解计算机网络》 王达著 机械工业出版社 2013年
《.NET 4.0面向对象编程漫谈 基础篇及应用篇》 金旭亮 电子工业出版社 2010年
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms;
namespace WindowsFormsApplication2 {
{
{ InitializeComponent();
f2.ShowCounter = new f2.Show(); }
{
} } }
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms;
namespace WindowsFormsApplication2 {
{
{ InitializeComponent(); }
{ counter++; ShowCounter?.Invoke(counter); } } } |
绘制图形的基本函数Plot
绘制图形步骤
1、首先定义自变量X的取值向量(横坐标)。
2、再定义函数Y的取值向量(纵坐标)。
3、用plot(x,y)命令给出平面曲线图。
单条曲线绘制
x=-2:0.01:2; y=x.^2; plot(x,y); |
单条曲线绘制
x=linspace(-2*pi,2*pi,30); y=sin(x); plot(x,y,“r*”); |
多条曲线绘制
x1=linspace(-2*pi,2*pi,30); y1=40*sin(x1); plot(x1,y1) hold on %不清除图形 x2=linspace(-2*pi,2*pi,30); y2=x.^2; plot(x2,y2); |
多条曲线绘制
x=linspace(0,50,30); y=x+20; z=2*x.^2+3*x+1; w=100*cos(x); plot(x,y,x,z,x,w); |
xml文件内容
<?xml version=”1.0″ encoding=”utf-8″ standalone=”yes”?> <library> <book> <name>笑傲江湖</name> <name1>罪与罚</name1> </book> </library> |
文件的读取
{
op.Filter = “xml文件|*.xml”; op.ShowDialog();
} |
文件的写入
{
op.Filter = “xml文件|*.xml”; op.ShowDialog();
name1.Value = “笑傲江湖“; name2.Value = “罪与罚“; document.Save(op.FileName); } |
下载文件
TextWindow.WriteLine(“开始下载……”) path=Network.DownloadFile(“https://smallbasic-publicwebsite.azurewebsites.net/assets/tutorial-downloads/CodingClub_Practice01.pdf”) TextWindow.WriteLine(path) TextWindow.WriteLine(“下载完成!”) |
这里下载的是个PDF文件,找到下载的文件,修改文件名为pdf即可打开。
下载网页文件
TextWindow.WriteLine(“开始下载……”) path=Network.GetWebPageContents(“https://www.baidu.com”) TextWindow.WriteLine(path) TextWindow.WriteLine(“下载完成!”) |
GraphicsWindow.MouseUp=OnMouseUp GraphicsWindow.Show()
Sub OnMouseUp GraphicsWindow.ShowMessage(“你点击了画面”,”提示”) EndSub |
重复相同数据类型的变量
随机存储十个数
For i=1 To 10 randnum[i]= Math.GetRandomNumber(1000) EndFor For j=1 To 10 TextWindow.WriteLine(randnum[j]) EndFor |
子程序减少重复编写相同的代码
子程序实现时间输出
PrintTime()
Sub PrintTime TextWindow.WriteLine(Clock.Time) EndSub |
这是引进的Logo语言的模式。
显示乌龟
Turtle.Show() |
乌龟移动100个像素
Turtle.Show() Turtle.Move(100) |
绘制正方形
Turtle.Show() Turtle.Move(100) Turtle.TurnLeft() Turtle.Move(100) Turtle.TurnLeft() Turtle.Move(100) Turtle.TurnLeft() Turtle.Move(100) |
我们把程序简化一下
Turtle.Show() For i=1 To 4 Turtle.Move(100) Turtle.TurnLeft() EndFor |
把直线随机修改一下颜色
Turtle.Show() For i=1 To 4 GraphicsWindow.PenColor=GraphicsWindow.GetRandomColor() Turtle.Move(100) Turtle.TurnLeft() EndFor |
图形界面
GraphicsWindow.Show() |
设置一下窗体的外观
GraphicsWindow.BackgroundColor=”Pink” GraphicsWindow.Title=”画板” GraphicsWindow.Width=400 GraphicsWindow.Height=400 GraphicsWindow.Show() |
画直线
GraphicsWindow.Title=”画板” GraphicsWindow.BackgroundColor=”LightGray” GraphicsWindow.Width=400 GraphicsWindow.Height=400 GraphicsWindow.Show() GraphicsWindow.DrawLine(0,0,400,400) GraphicsWindow.DrawLine(0,400,400,0) |
修改笔的属性
GraphicsWindow.Title=”画板” GraphicsWindow.BackgroundColor=”LightGray” GraphicsWindow.Width=400 GraphicsWindow.Height=400 GraphicsWindow.Show() GraphicsWindow.PenColor=”Red” GraphicsWindow.PenWidth=5 GraphicsWindow.DrawLine(0,0,400,400) GraphicsWindow.PenColor=”Blue” GraphicsWindow.PenWidth=10 GraphicsWindow.DrawLine(0,400,400,0) |
画图和填充图形
GraphicsWindow.Title=”画板” GraphicsWindow.BackgroundColor=”LightGray” GraphicsWindow.Width=600 GraphicsWindow.Height=600 GraphicsWindow.Show() GraphicsWindow.PenColor=”Red” GraphicsWindow.DrawRectangle(20,20,200,100) GraphicsWindow.BrushColor=”Blue” GraphicsWindow.FillRectangle(20,300,200,100) |
循环有两种语句,For和While
For实现的循环输出1到10
For i=1 To 10 TextWindow.WriteLine(i) EndFor |
While实现的循环输出1到10
i=1 While i<11 TextWindow.WriteLine(i) i=i+1 EndWhile |
不同时间的问候
If Clock.Hour<12 Then TextWindow.WriteLine(“早上好!”) EndIf If Clock.Hour>=12 Then TextWindow.WriteLine(“下午好!”) EndIf |
换种思路,再把程序实现一遍
If Clock.Hour<12 Then TextWindow.WriteLine(“早上好!”) Else TextWindow.WriteLine(“下午好!”) EndIf |
早上好,下午好,晚上好
If Clock.Hour<12 Then TextWindow.WriteLine(“早上好!”) ElseIf Clock.Hour >=12 and Clock.Hour<18 then TextWindow.WriteLine(“下午好”) Else TextWindow.WriteLine(“晚上好”) EndIf |
还有一种分支结构,不推荐使用,等我们学到微机原理与接口的课程中会发现,所有的循环本质上就是分支结构。
这里我们实现分支循环输出1到10
i=1 start: TextWindow.WriteLine(i) i=i+1 If i<11 Then Goto start EndIf |
程序中使用变量
TextWindow.Write(“your name:”) name= TextWindow.Read() TextWindow.WriteLine(name + “你好!”) |
程序中使用数字
number1=12 number2=13 number3=number1*number2 TextWindow.WriteLine(“number3=”+number3) |
Small Basic 和编程
Small Basic应该是最简单的文本编程语言了,微软为孩子准备的。
Small Basic 编程环境
我们的第一个程序
我们不能免俗的第一个程序
TextWindow.WriteLine(“Hello World!”) |
我们的第二个程序
TextWindow.ForegroundColor=”yellow” TextWindow.WriteLine(“Hello World!”) |
服务器端程序
Private Sub CommandButton1_Click() Winsock1.LocalPort = 5600 Winsock1.Listen End Sub
Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long) If Winsock1.State <> sockclosed Then Winsock1.Close Winsock1.Accept requestID End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long) Dim s As String Winsock1.GetData s TextBox1.Text = s End Sub
Private Sub TextBox2_Change() Winsock1.SendData Me.TextBox2.Text End Sub |
客户端程序
Private Sub CommandButton1_Click() Winsock1.RemoteHost = “127.0.0.1” Winsock1.RemotePort = 5600 Winsock1.Connect End Sub
Private Sub TextBox1_Change() Winsock1.SendData Me.TextBox1.Text End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long) Dim s As String Winsock1.GetData s Me.TextBox2.Text = s End Sub |
Private Sub CommandButton1_Click() Dim ctl As Control For Each ctl In Me.Controls MsgBox ctl.Name Next ctl End Sub |
结果
列表框和集合框也属于集合的范畴。
树状视图也是用集合的范畴。