应该定义为double或者single,string类好像不能进行运算。我简单说一下控制台的方法,你要一次性输入和差积商,首先声明两个变量用来储存两个数,然后用算法一次性输出结果就ok。
成都创新互联公司-专业网站定制、快速模板网站建设、高性价比下花园网站开发、企业建站全套包干低至880元,成熟完善的模板库,直接使用。一站式下花园网站制作公司更省心,省钱,快速模板网站建设找我们,业务覆盖下花园地区。费用合理售后完善,十年实体公司更值得信赖。
Sub Main()
Dim FN As Single
Dim SN As Single
Dim ResultNum As Single
Console.WriteLine("请输入第一个数") : FN = Console.ReadLine
Console.WriteLine("请输入第二个数") : SN = Console.ReadLine
ResultNum = FN + SN
Console.WriteLine("它们的和: " ResultNum)
ResultNum = FN - SN
Console.WriteLine("它们的差: " ResultNum)
ResultNum = FN * SN
Console.WriteLine("它们的积: " ResultNum)
ResultNum = FN / SN
Console.WriteLine("它们的商: " ResultNum)
Console.ReadLine()
End Sub
加一个按钮,代码如下:
Imports System.Data.OleDb
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim myConn As OleDbConnection = New OleDbConnection '声明并实例化数据库连接对象
Dim myadpt As New OleDbDataAdapter '声明并实例化数据适配器对象
Dim myds As New DataSet '声明并实例化记录集对象
Dim myConnection As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" Application.StartupPath "\DB\SJ.mdb" '数据库连接字符串
myConn.ConnectionString = myConnection '设置数据库连接对象的数据库连接字符串属性
myConn.Open() '启动数据库连接
myadpt.SelectCommand = New OleDbCommand '声明数据适配器的查询命令对象
myadpt.SelectCommand.CommandText = "select sum(支出金额) as 支出金额 from zcb where 支出时间 like '" Text1.Text "%' " '给数据适配器的查询命令属性赋值
myadpt.SelectCommand.Connection = myConn '设置据适配器与数据库连接对象的连接
myadpt.Fill(myds)
Text13.Text = myds.Tables(0).Rows(0)("支出金额")
End Sub
End Class
软糖来回答吧,vb.net用循环是这样的
dim k = new integer(9) {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
dim 和 as integer
for i = 0 to k.count - 1
和 += k(i)
next计算数组中各元素之和更简单的方法是
使用扩展方法sum或者lambda表达式,以下两种均可
dim 和1 = k.sum()
dim 和2 = k.aggregate(function(m, n) m + n)
Dim sum As Integer
For i = 1 To 30
If i Mod 2 = 0 Then
sum = sum + i
End If
Next
html
head
meta http-equiv="Content-Type" content="text/html; charset=utf-8" /
title1到100之和/title
/head
script language="javascript"
!--
sum=0
for(i=1;i=100;i++)
{
sum=sum+i;
}
document.write("1到100之和为:"+sum)
--
/script
body
/body
/html