應該定義為double或者single,string類好像不能進行運算。我簡單說一下控制臺的方法,你要一次性輸入和差積商,首先聲明兩個變量用來儲存兩個數(shù),然后用算法一次性輸出結果就ok。
成都創(chuàng)新互聯(lián)公司-專業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設、高性價比下花園網(wǎng)站開發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫,直接使用。一站式下花園網(wǎng)站制作公司更省心,省錢,快速模板網(wǎng)站建設找我們,業(yè)務覆蓋下花園地區(qū)。費用合理售后完善,十年實體公司更值得信賴。
Sub Main()
Dim FN As Single
Dim SN As Single
Dim ResultNum As Single
Console.WriteLine("請輸入第一個數(shù)") : FN = Console.ReadLine
Console.WriteLine("請輸入第二個數(shù)") : 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 '聲明并實例化數(shù)據(jù)庫連接對象
Dim myadpt As New OleDbDataAdapter '聲明并實例化數(shù)據(jù)適配器對象
Dim myds As New DataSet '聲明并實例化記錄集對象
Dim myConnection As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" Application.StartupPath "\DB\SJ.mdb" '數(shù)據(jù)庫連接字符串
myConn.ConnectionString = myConnection '設置數(shù)據(jù)庫連接對象的數(shù)據(jù)庫連接字符串屬性
myConn.Open() '啟動數(shù)據(jù)庫連接
myadpt.SelectCommand = New OleDbCommand '聲明數(shù)據(jù)適配器的查詢命令對象
myadpt.SelectCommand.CommandText = "select sum(支出金額) as 支出金額 from zcb where 支出時間 like '" Text1.Text "%' " '給數(shù)據(jù)適配器的查詢命令屬性賦值
myadpt.SelectCommand.Connection = myConn '設置據(jù)適配器與數(shù)據(jù)庫連接對象的連接
myadpt.Fill(myds)
Text13.Text = myds.Tables(0).Rows(0)("支出金額")
End Sub
End Class
軟糖來回答吧,vb.net用循環(huán)是這樣的
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計算數(shù)組中各元素之和更簡單的方法是
使用擴展方法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