当前位置:网站首页>Basic syntax of VB
Basic syntax of VB
2022-06-30 20:04:00 【Rodinia lava】
Imports System
Module Program
Sub Main(args As String())
Dim a, b As Int32
a = 1
b = 2
If a < 1 Then
Console.WriteLine(" result 1")
Else
Console.WriteLine(" result 2")
End If
Console.WriteLine("========================")
For index = 1 To 10
Console.WriteLine(index)
Next
If True Then
End If
Console.WriteLine("Hello World!")
Dim c(3) As Integer
c(1) = 1
c(2) = 1
c(3) = 3
For index = 1 To 3
Console.WriteLine(c(index))
Next
Console.WriteLine("==========For Each========================")
For Each item In func1()
Console.WriteLine(item)
Next
Console.WriteLine("==========Sub function ========================")
func2()
//Public integerClass As New classHolder(Of Integer)
End Sub
Public Function func1() As Integer()
Dim a(10) As Integer
For index = 1 To 10
a.Append(index)
Next
func1 = a
End Function
Public Sub func2()
Console.WriteLine(“ This is a func2()”)
End Sub
Public Class Customer
Public Sub New()
Debug.WriteLine("setuped")
End Sub
'--------New(Byval)---------
Public Sub New(ByVal sname As String)
Name = sname
Debug.WriteLine(Name & "setuped")
End Sub
Private m_Name As String
Property Name() As String
Get
Return m_Name
End Get
Set(ByVal Value As String)
m_Name = Value
End Set
End Property
Private m_address As String
Property Address() As String
Get
Return m_address
End Get
Set(ByVal Value As String)
m_address = Value
End Set
End Property
Public Function PlaceOrder() As String
End Function
Public Function CheckOrderStatus() As String
End Function
Public Overridable Function CalculateDiscount() As String
Return "base class"
End Function
End Class
Public Class SubPro : Inherits Customer
Private m_zfjg As String
Property Zfjg() As String
Get
Return Zfjg
End Get
Set(ByVal Value As String)
m_zfjg = Value
End Set
End Property
Private m_bsc As String
Property Bsc() As String
Get
Return m_bsc
End Get
Set(ByVal Value As String)
m_bsc = Value
End Set
End Property
Public Overrides Function CalculateDiscount() As String
Return "sub class"
End Function
Public Function SubProSelf() As String
End Function
Public Sub New()
MyBase.New()
End Sub
End Class
End Module
result :
result 2
1
2
3
4
5
6
7
8
9
10
Hello World!
1
1
3
For Each==============
0
0
0
0
0
0
0
0
0
0
0
Sub function ==============
This is a func2()
D:\Csharp\VBTest\VBTest\bin\Debug\net6.0\VBTest.exe ( process 1600) Exited , The code is 0.
To automatically close the console when debugging stops , Please enable “ Tools ”->“ Options ”->“ debugging ”->“ Automatically close the console when debugging stops ”.
Press any key to close this window . . .
One 、 Insert statement
1. Normal insert
insert into tableA( Field 1, Field 2, Field 3)values( field value 1, field value 2, field value 3)
example :
insert into tableA(
userName,
userSex,
userPhone
)values(
' Zhang San ',
' male ',
'18812345678'
)
2. Table data query ( Copy ) Insert
insert into tableA( Field 1, Field 2, Field 3)select ( Field 4, Field 5, Field 6) from tableB
insert into tableA(
userName,
userSex,
userPhone
)select
memberName,
memberSex,
memberPhone
from tableB
where ……
Two 、 Query statement
1. All data queries
select Field 1, Field 2, Field 3 from tableA where ……
example :
select
userName,
userSex,
userPhone
from tableA
where ……
2. How many pieces of data before query according to a certain condition
select top n Field 1, Field 2, Field 3 from tableA where ……
(n Is the number of data pieces )
example ( front 10 Data ):
select
top 10
userName,
userSex,
userPhone
from tableA
where ……
order by userName
3、 ... and 、 UPDATE statement
1. Single table data update
update tableA set Field 1=‘ field value 1’, Field 2=‘ field value 2’, Field 3=‘ field value 3’ where……
example :
update tableA
set userName=' Li Si ',
userSex=' male ',
userPhone='13012345678'
where userName=' Zhang San '
2. Multi table joint data update
update a set a. Field 1=b. Field 4,a. Field 2=b. Field 5,a. Field 3=b. Field 6
from tableA a left join tableB b on a.userId=b.userId
where……
example :
update a
set a.userName=b.userName,
a.userSex=b.userSex,
a.userPhone=b.userPhone
from tableA a
left join tableB on a.userId=b.userId
where ……
Four 、 Delete statements
delete from tableA where ……
example :
delete from tableA where userName=' Zhang San '
1
5、 ... and 、case when……else
case when Conditions 1 then ……when Conditions 2 then……else……end
example :
select
case when sexFlag=0 then ' Woman '
when sexFlag=1 then ' male '
else ' Unrecognized '
end userSex
from tableA
6、 ... and 、left join( Left Association query )
The result set returns the left table (tableA) All the data , If the left table exists 、 Right table (tableB) If there is no data, the data in the right table will return null
example :
select
a.userName,--tableA Name of the person in the table
b.userOrderId--tableB Order No. of Chinese personnel , If not, return null
from tableA a
left join tableB b on a.userId=b.userId
7、 ... and 、right join( Right association query )
The result set returns the right table (tableB) All the data , If the right table exists 、 The left table (tableA) If there is no data, the data in the left table will return null
example :
select
a.userName,--tableA Name of the person in the table , If not, return null
b.userOrderId--tableB All order numbers in
from tableA a
right join tableB b on a.userId=b.userId
8、 ... and 、inner join( Internal association query )
The result set returns the left table (tableA) And the right watch (tableB) All existing data
example :
select
a.userName,--tableA Name of the person in the table
b.userOrderId--tableB All order numbers in
from tableA a
inner join tableB b on a.userId=b.userId
Nine 、like
Fuzzy conditional query , Query the result set of a field value containing a string
example ( The query name contains 【 countries 】 All personnel information of the word ):
select
……
from tableA
where userName like '% countries %'
Ten 、concat
Character replacement and splicing combination
example ( full name / Gender / The mobile phone number is combined into one field ):
select
-- return : Zhang San - male -18812345678
CONCAT(userName,'-',userSex,'-',userPhone) as userInfo
from tableA
where ……
11、 ... and 、charindex
Determine whether a field value contains a string , If yes, the position of the string is returned ( Greater than 0), If not, return 0, It is generally used for filtering conditions
example ( The query name contains 【 countries 】 All personnel information of the word ):
select
……
from tableA
where charindex(' countries ',userName)>0
1
2
3
4
Twelve 、substring
Intercepting string
example :
select
-- Mobile number No 4 Bit start to intercept , Co interception 4 position
substring(userPhone,4,4)
from tableA
One 、 database
1 Modify the database name & Delete database
alter database tablename_old modify name = tablename_new;
drop database tablename;
Two 、 Data type recognition
2.1 Numeric type
2.2 The date type
2.3 String type
3、 ... and 、 Modify the order ——alter
3.1 Modify field type
alter table tableA alter column name varchar(10);
alter table tableA alter column age float not null;
3.1 newly added & Delete primary key
alter table tableA add constraint KID( Primary key constraint name ) primary key(ID);
alter table tableA drop constraint KID;
3.1 change & Add field name
exec sp_rename 'tableA .age','userage','column';
alter table tableA add grade varchar(10) not null;
Four 、 Primary key & Foreign keys ( A little )
5、 ... and 、 Insert new record ——insert
5.1 Insert new row
insert into tableA ('column1','column2','column3','column4') values ('value1','value2','value3','value4'),('value1','value2','value3','value4'),...('value1','value2','value3','value4');
insert into tableA ('column1','column2','column3','column4') select column1,column2,column3,column4 from tableB ;
6、 ... and 、 Modify the record ——updata
6.1 updata tableA set Field = value where Field = value ( Limiting conditions )
7、 ... and 、 Delete record ——delete
7.1 delete from tableA where Field = value ( Limiting conditions )
8、 ... and 、 Conditionality ——where
8.1 Exact conditions
where Field = ' value '
8.2 Fuzzy conditions
where Field like '% value %'
Nine 、between¬ between grammar
select * from tableA where ID between 10 and 20;
select * from tableA where ID not between 10 and 20;
Ten 、 Subquery in¬ in grammar
select * from tableA where name in ('zhangsan',''lisi) ;
select * from tableA where name not in ('zhangsan',''lisi);
select * from tableA where name in (select name from tableB );
select * from tableA where name not in (select name from tableB );
11、 ... and 、 Return the result sort ——order by
select * from tableA order by ID desc; # according to ID Descending
select * from tableA order by ID asc ;# according to ID Ascending
select * from tableA order by ID asc ,age desc ;# First according to ID Ascending , And then ID On the basis of ascending order age Descending ;
Twelve 、 Relational query
12.1 inner join—— Internal connection
select * from tableA inner join tableB on tableA.ID = tableB.ID;
12.2 left join—— Left connection
select * from tableA left join tableB on tableA.ID = tableB.ID;
12.3 right join—— The right connection
select * from tableA right join tableB on tableA.ID = tableB.ID;
12.4 full join—— Full connection
select * from tableA full join tableB on tableA.ID = tableB.ID;
Twelve 、 function
12.1 Returns the number of characters in a string ——len()
12.2 Return current time ——getdate()、getutcdata()
12.3 Convert date format ——convert(datetype,date_to_be_converted,style)
convert(verchar(10),getdate(),110)
12.4 Calculate the time difference ——datediff(datepart,startdate,enddate)
#datepart Constant value :day,month,year,hour,minute
select datediff(day,'2020-05-01','2020-05-03') ; # result 2
select datediff(month,'2020-05-01','2020-06-03') ; # result 1
12.5 Add dates ——dateadd(datepart,number,date)
select dateadd(day,3,'2020-05-01') ; # result 2020-05-04
select dateadd(day,-3,'2020-05-01') ; # result 2020-04-28
12.6 Get a separate part of the date ——datepart(datepart,number,date)
select datepart(day,getdate());#select datepart(dd,getdate()); The return type is int integer
select datename(day,getdate());#select datename(dd,getdate()); The return type is varchar type
select day(getdate();select month(getdate();select year(getdate();
12.7 Returns the position of a character in another string ——charindex()、patindex()
select charindex('cc','aabbccdd');# Return results 5;
select patindex('%dd','aabbccdd');# Return results 7(%dd: Whether or not to dd ending );
12.8 Delete & Replace the specified length of characters ——stuff( character string , Starting position , length , Alternative string )
select stuff('aabbccdd',5,2,'ee');# Return results aabbeedd;
12.9 Intercepts a string of specified length ——substring( character string , Starting position , length )
select substring('aabbccdd',5,2);# Return results cc;
12.10 Intercepting string ——left()、right()
select left('aabbccdd',5);# Return results aabbc;
select right('aabbccdd',5);# Return results bccdd;
12.10 Divide the string by spaces ——ltrim()、rtrim()
select ltrim(' aabbccdd ');# Return results 'aabbccdd ';
select rtrim(' aabbccdd ');# Return results ' aabbccdd ';
12.11 String case conversion ——lower()、upper()
select lower('Abc');# Return results abc
select upper('Abc');# Return results ABC
12.12 String substitution ——replace()
select replace('aabbccddcc','cc','ee');# Return results aabbeeddee;
12.13 Duplicate string ——replicate() 、space()
select replicate('aab',3);# Return results aabaabaab;
select 'a'+space(5)+'a';# Return results 'a a';
12.14 Invert string position ——reverse()
select reverse('aab');# Return results baa;
12.15 Change field type ——cast()
select cast(123 as varchar(10));# Integer to character ;
select cast(12.5 as decimal(18,2));# Return results 12.50;
12.16 Conditional judgment conversion function ——case()
select case when sex='1' then ' Woman ' else ' male ' end as sex from tableA;
边栏推荐
- 广州股票开户选择手机办理安全吗?
- FH6908A负极关断同步整流模拟低压降二极管控制IC芯片TSOT23-6超低功耗整流器 1w功耗 <100uA静态 替代MP6908
- 英语没学好到底能不能做coder,别再纠结了先学起来
- Data intelligence - dtcc2022! China database technology conference is about to open
- Cartoon | has Oracle been abandoned by the new era?
- 超视频时代的音视频架构建设|Science和英特尔联袂推出“架构师成长计划”第二季
- CADD课程学习(2)-- 靶点晶体结构信息
- neo4j load csv 配置和使用
- 线下门店为什么要做新零售?
- Graduates
猜你喜欢

网易云签到可抽奖?那一年我能签到365天。不信?你看。

Kubernetes为什么会赢,容器圈的风云变幻!

Friends in Guangzhou can join us if they have the opportunity

微信小程序开发实战 云音乐

昔日果汁大王,16个亿卖了

CADD课程学习(1)-- 药物设计基础知识

数据智能——DTCC2022!中国数据库技术大会即将开幕

ABAQUS 2022最新版——完善的现实仿真解决方案

为什么一定要从DevOps走向BizDevOps?

Application of VoIP push in overseas audio and video services
随机推荐
MQ advantages and disadvantages (2022.5.2-5.8)
暑期实训21组第一周个人工作总结
FH6908A负极关断同步整流模拟低压降二极管控制IC芯片TSOT23-6超低功耗整流器 1w功耗 <100uA静态 替代MP6908
【NLP】【TextCNN】 文本分类
VR全景中特效是如何编辑的?细节功能如何展示?
A detailed explanation of the implementation principle of go Distributed Link Tracking
Redis ziplist 压缩列表的源码解析
qt中toLocal8Bit和toUtf8()有什么区别
腾讯会议应用市场正式上线,首批入驻超20款应用
将 EMQX Cloud 数据通过公网桥接到 AWS IoT
实现各种效果和功能的按钮,读这篇文章就够了
杭州炒股开户选择手机办理安全吗?
Kubevela 1.4: make application delivery safer, easier to use, and more transparent
Filebeat custom indexes and fields
VR全景添加对比功能,让差异化效果展示更直观!
Character class of regular series
A necessary tool for testing -- postman practical tutorial
Buttons to achieve various effects and functions. Reading this article is enough
超视频时代的音视频架构建设|Science和英特尔联袂推出“架构师成长计划”第二季
【450. 删除二叉搜索树中的节点】