包含casevb.net的词条
VB中的CASE语句
在VB.NET中VB.NET CASE语句就是比较常用的一种,下面是详细的介绍和代码的演示:
大关ssl适用于网站、小程序/APP、API接口等需要进行数据传输应用场景,ssl证书未来市场广阔!成为创新互联公司的ssl证书销售渠道,可以享受市场价格4-6折优惠!如果有意向欢迎电话联系或者加微信:028-86922220(备注:SSL证书合作)期待与您的合作!
1、可以用 Select...Case 语句来替换 If...Then...Else 语句,所不同的是If 和 ElseIf 语句可在每个语句中计算不同的表达式,而 Select 语句对单个表达式只计算一次,然后将其和不同的值比较。
Function bonus(ByVal performance As Integer, _ ByVal salary As Decimal) As Decimal
Select performance
Case 1
Return salary * 0.1
Case 2
Return salary * 0.3
Case 3
Return salary * 0.7
Case 4
Return salary * 0.9
Case 5
Return salary * 1.2
End Select
End Function
2、VB.NET Case语句可包含多个值和某个范围的值,代码案例如下:
Function bonus(ByVal performance As Integer, _ ByVal salary As Decimal) As Decimal
Select performance
Case 1
Return salary * 0.1
Case 2,3
Return salary * 0.3
Case 3 To 7
Return salary * 0.7
Case 8 To 9
Return salary * 0.9
Case Is = 15
Return salary * 1.2
Case Else
Return 0
End Select
End Function
在VB.net中,使用Select Case语句,Case后能接几个判断语句吗?
select case when a1 and b2 and c3 then d=1
when a1 and b2 and c3 then d=2
... end
至于写多少,没限制,,只要你语句不卡,,,
求做一个web页面控制服务器串口,可用Mscomm控件做!满意会继续最佳。htm页面都能操作本地串口。
看了你的留言直接在这回吧,其实网页方面我也是个菜鸟。去年我做过一个类似的,当时也是自学了1个月的iis的配置,asp.net,vb串口操作等,大二假期比较闲。
做法:用DS18B20温度传感器连接51单片机,然后单片机通过串口与电脑通信,电脑成为服务器,手机连接网页,进行温度监控,开关单片机外接的继电器等等操作。
硬件端的代码对你没用,服务器端我的基本思路就是asp.net连接数据库,然后用vb实时扫描数据库,通过vb中的MScomm控件连接串口,vb的代码对你也没啥用,因为MScomm连接单片机的代码的“通信协议”我是写在单片机上的,不配套就没用了
这是网页的代码,不精简,高手莫笑...
主要功能就是连接数据库。。。里面没能直接通过asp.net控制串口,貌似也有C#直接控制的,你去CSDN看看吧,我试过是没问题的,就是操作不太方便(可能我太菜了)
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//温度
SqlConnection cnn1 = new SqlConnection(@"Data Source=YINGJHSHP541\SQLEXPRESS;Initial Catalog=test3;User ID=sa;Password=yingjh");
cnn1.Open();
//表
SqlCommand cmd1 = new SqlCommand();
cmd1.Connection = cnn1;
cmd1.CommandText = "select * from T";
SqlDataReader data1;
data1 = cmd1.ExecuteReader();
GridView1.DataSource = data1;
GridView1.DataBind();
cnn1.Close();
//图
cnn1.Open();
SqlDataAdapter Da = new SqlDataAdapter();
Da.SelectCommand = new SqlCommand("select 时间,[温度(℃)] from T", cnn1);
DataSet ds = new DataSet();
Da.Fill(ds);
DataView myView = new DataView(ds.Tables[0]);
Chart1.Series["Series1"].Points.DataBindXY(myView, "时间", myView, "温度(℃)");
cnn1.Close();
cnn1.Dispose();
//状态
SqlConnection cnn2 = new SqlConnection();
cnn2.ConnectionString = @"Data Source=YINGJHSHP541\SQLEXPRESS;Initial Catalog=test3;User ID=sa;Password=yingjh";
cnn2.Open();
SqlCommand cmd2 = new SqlCommand();
cmd2.Connection = cnn2;
cmd2.CommandText = "select * from ST";
SqlDataReader data2;
data2 = cmd2.ExecuteReader();
data2.Read();
string a = data2.GetString(0);
switch (a)
{
case "1":
Label2.Text = "打开";
break;
case "0":
Label2.Text = "预设";
break;
case "-1":
Label2.Text = "关闭";
break;
default:
break;
}
Label4.Text = data2.GetString(1) + "℃";
cnn2.Close();
cnn2.Dispose();
}
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection cnn = new SqlConnection(@"Data Source=YINGJHSHP541\SQLEXPRESS;Initial Catalog=test3;User ID=sa;Password=yingjh");
SqlCommand cmd = new SqlCommand();
cnn.Open();
cmd.Connection = cnn;
//设置开关,flag为开关控制权
switch (DropDownList1.Text)
{
case "1":
cmd.CommandText = "update ST set STATE='1'" + ",flag='1'";
break;
case "0":
cmd.CommandText = "update ST set STATE='0'" + ",STEMP='" + TextBox1.Text + "',flag='1'";
break;
case "-1":
cmd.CommandText = "update ST set STATE='-1'" + ",flag='1'";
break;
default:
cmd.CommandText = "update ST set STATE='0'" + ",STEMP='" + TextBox1.Text + "',flag='1'";
break;
}
cmd.ExecuteNonQuery();
cnn.Close();
cnn.Dispose();
//温度
SqlConnection cnn1 = new SqlConnection(@"Data Source=YINGJHSHP541\SQLEXPRESS;Initial Catalog=test3;User ID=sa;Password=yingjh");
cnn1.Open();
//表
SqlCommand cmd1 = new SqlCommand();
cmd1.Connection = cnn1;
cmd1.CommandText = "select * from T";
SqlDataReader data1;
data1 = cmd1.ExecuteReader();
GridView1.DataSource = data1;
GridView1.DataBind();
cnn1.Close();
//图
cnn1.Open();
SqlDataAdapter Da = new SqlDataAdapter();
Da.SelectCommand = new SqlCommand("select 时间,[温度(℃)] from T", cnn1);
DataSet ds = new DataSet();
Da.Fill(ds);
DataView myView = new DataView(ds.Tables[0]);
Chart1.Series["Series1"].Points.DataBindXY(myView, "时间", myView, "温度(℃)");
cnn1.Close();
cnn1.Dispose();
//状态
SqlConnection cnn2 = new SqlConnection();
cnn2.ConnectionString = @"Data Source=YINGJHSHP541\SQLEXPRESS;Initial Catalog=test3;User ID=sa;Password=yingjh";
cnn2.Open();
SqlCommand cmd2 = new SqlCommand();
cmd2.Connection = cnn2;
cmd2.CommandText = "select * from ST";
SqlDataReader data2;
data2 = cmd2.ExecuteReader();
data2.Read();
string a = data2.GetString(0);
switch (a)
{
case "1":
Label2.Text = "打开";
break;
case "0":
Label2.Text = "预设";
break;
case "-1":
Label2.Text = "关闭";
break;
default:
break;
}
Label4.Text = data2.GetString(1) + "℃";
cnn2.Close();
cnn2.Dispose();
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
文章名称:包含casevb.net的词条
网站链接:http://pwwzsj.com/article/doepccp.html