vb.net函数定义代码,VB定义函数
用VB.NET程序编写代码
Delphi代码如下:
创新互联公司是一家专注于网站设计、成都网站建设与策划设计,忠县网站建设哪家好?创新互联公司做网站,专注于网站建设十年,网设计领域的专业建站公司;建站业务涵盖:忠县等地区。忠县做网站价格咨询:18982081108
procedure TForm1.Button1Click(Sender: TObject);
var
购物总价:Integer;
折扣:Extended;
begin
购物总价:=StrToInt(Edit1.Text);
if 购物总价250 then
begin
折扣:=0;
end
else if 购物总价500 then
begin
折扣:=0.05;
end
else if 购物总价1000 then
begin
折扣:=0.075;
end
else if 购物总价2000 then
begin
折扣:=0.1;
end
{
此段的折扣是多少?
else if 购物总价3000 then
begin
折扣:=0.05;
end
}
else if 购物总价=3000 then
begin
折扣:=0.15;
end;
ShowMessage('您享受的折扣是:'+FloatToStr(折扣)
+' 原价:'+IntToStr(购物总价)
+' 折后总价:'+FloatToStr(购物总价*(1-折扣)));
end;
VB.NET自定义函数
很简单,在end select前再多加一种情况case else return "XXXx",因为你只提供了0-9这10种情况
Public Function Zuhe(ByVal qa As String) As String
Select Case qa
Case "0"
Return "1"
Case "1"
Return "3"
Case "2"
Return "4"
Case "3"
Return "6"
Case "4"
Return "2"
Case "5"
Return "8"
Case "6"
Return "9"
Case "7"
Return "7"
Case "8"
Return "5"
Case "9"
Return "0"
Case else
Return "XXXX"
End Select
End Function
vb.net 如何能获取到 自定义函数的代码内容
首先新建一个类库项目,把你的代码以类(需要实例)或模块(静态)的形式封装好,生成过后在输出目录(bin/debug或bin/release)里面会有个项目名.dll文件,就是它了。
在调用方项目里,右键解决方案资源管理器中的引用,添加引用,浏览到你的dll文件。接着到你的代码中,代码最上面写:
Imports 项目名
然后调用这个类或模块即可。
根据你的情况,可能用模块封装更适合一些。比如:
Public Module MatrixSolve
Public Function Solve(para1 As Double,para2 As Double) As Double
'一些代码
Return result
End Function
End Module
调用起来只要这样即可:
Dim num As Double = MatrixSolve.Solve(x,y)
注意模块和函数的访问级别都用Public,否则外面无法访问。
在vb中。如何进行三角函数的程序代码编写
有几个地方要注意:
1、VB中的三角函数的角度全部是用弧度制表示的,如果是度数的话,应先乘以180再除以π转成弧度,再用函数计算结果。
2、VB中直接支持的三角函数有:Sin()、Cos()、Tan(),如果涉及到其它三角函数,可以从下面列出的代码中自己选择相应的函数:
Function
Sec(X)
As
Double
'正割
Sec
=
1
/
Cos(Angle)
End
Function
Function
Csc(X)
As
Double
'余割
Csc
=
1
/
Sin(Angle)
End
Function
Function
Cot(X)
As
Double
'余切
Cot
=
1
/
Tan(Angle)
End
Function
Function
ArcSin(X)
As
Double
'反正弦
ArcSin
=
Atn(X
/
Sqr(-X
*
X
+
1))
End
Function
Function
ArcCos(X)
As
Double
'反余弦
ArcCos
=
Atn(-X
/
Sqr(-X
*
X
+
1))
+
2
*
Atn(1)
End
Function
Function
ArcSec(X)
As
Double
'反正割
ArcSec
=
Atn(X
/
Sqr(X
*
X
-
1))
+
Sgn((X)
-
1)
*
(2
*
Atn(1))
End
Function
Function
ArcCsc(X)
As
Double
'反余割
ArcCsc
=
Atn(X
/
Sqr(X
*
X
-
1))
+
(Sgn(X)
-
1)
*
(2
*
Atn(1))
End
Function
Function
ArcCot(X)
As
Double
'反余切
ArcCot
=
Atn(X)
+
2
*
Atn(1)
End
Function
Function
HSin(X)
As
Double
'双曲正弦
HSin
=
(Exp(X)
-
Exp(-X))
/
2
End
Function
Function
HCos(X)
As
Double
'双曲余弦
HCos
=
(Exp(X)
+
Exp(-X))
/
2
End
Function
Function
HTan(X)
As
Double
'双曲正切
HTan
=
(Exp(X)
-
Exp(-X))
/
(Exp(X)
+
Exp(-X))
End
Function
Function
HSec(X)
As
Double
'双曲正割
HSec
=
2
/
(Exp(X)
+
Exp(-X))
End
Function
Function
HCsc(X)
As
Double
'双曲余割
HCsc
=
2
/
(Exp(X)
-
Exp(-X))
End
Function
Function
HCot(X)
As
Double
'双曲余切
HCot
=
(Exp(X)
+
Exp(-X))
/
(Exp(X)
-
Exp(-X))
End
Function
Function
HArcsin(X)
As
Double
'反双曲正弦
HArcsin
=
Log(X
+
Sqr(X
*
X
+
1))
End
Function
Function
HArccos(X)
As
Double
'反双曲余弦
HArccos
=
Log(X
+
Sqr(X
*
X
-
1))
End
Function
Function
HArctan(X)
As
Double
'反双曲正切
HArctan
=
Log((1
+
X)
/
(1
-
X))
/
2
End
Function
Function
HArcsec(X)
As
Double
'反双曲正割
HArcsec
=
Log((Sqr(-X
*
X
+
1)
+
1)
/
X)
End
Function
Function
HArccsc(X)
As
Double
'反双曲余割
HArccsc
=
Log((Sgn(X)
*
Sqr(X
*
X
+
1)
+
1)
/
X)
End
Function
Function
HArccot(X)
As
Double
'反双曲余切
HArccot
=
Log((X
+
1)
/
(X
-
1))
/
2
End
Function
使用vb.net编写一个函数,函数只有一个参数
首先在窗体上添加Button1,ListBox1,下面是完整代码
Public Class Form1
Public Sub BubbleSort(ByVal arr() As Integer) '冒泡法排序
Dim temp As Double
Dim i, j As Integer
For i = 0 To arr.GetUpperBound(0) - 1
For j = i + 1 To arr.GetUpperBound(0) - 1
If arr(i) arr(j) Then
temp = arr(j)
arr(j) = arr(i)
arr(i) = temp
End If
Next
Next
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click '调用
Dim arr() As Integer = {55, 22, 33, 11, 77, 88}
BubbleSort(arr) '调用排序过程
Me.ListBox1.Items.Clear()
For i = 0 To arr.GetUpperBound(0) - 1 '显示排序后结果
Me.ListBox1.Items.Add(arr(i).ToString)
Next
End Sub
End Class
当前题目:vb.net函数定义代码,VB定义函数
文章位置:http://azwzsj.com/article/hcjgdg.html