重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
首先,要知道3次根号下 x ,就是x^(1/3),知道这个就可以写代码了: private sub form_load() x=inputbox("请输入要开三次方的数值") msgbox x^(1/3) end sub
创新互联-专业网站定制、快速模板网站建设、高性价比柳北网站开发、企业建站全套包干低至880元,成熟完善的模板库,直接使用。一站式柳北网站制作公司更省心,省钱,快速模板网站建设找我们,业务覆盖柳北地区。费用合理售后完善,10余年实体公司更值得信赖。
绝对值是“|”,可以直接显示,同理对数可用log(x)代替,根号和其他不支持显示。
如果要显示数学式子,只能画吧。
计算时可用“^”求幂或求根,“/”表示除法和分数线,还有math类。
VB的运算顺序是:先乘除、后加减,有括号的先算括号内,有负号的先算负号。
请你比较一下这个运算中x和y的值:
Dim n As Single = 4
Dim x As Single
Dim y As Single
x = n + 1
x = x / n
x = x - 1
x = Math.Sqrt(x)
y = Math.Sqrt((n + 1) / n - 1)
这样就会发现,你的代码中括号的位置错了。
正确的应该是: Math.Sqrt((n + 1) / n - 1)
效果如图,代码如下:
Public Class Form1
'Circle类
Class Circle
Public Center As Point
Public Radius As Single
Public Sub New(c As Point, r As Single)
Center = c
Radius = r
End Sub
'绘制
Public Sub Draw(g As Graphics, pen As Pen)
g.DrawEllipse(pen, New RectangleF(Center.X - Radius, Center.Y - Radius, Radius * 2, Radius * 2))
End Sub
End Class
Private downPoint As Point '记录鼠标按下位置
Private circleList As New List(Of Circle) '已存放圆的列表
Private tmpCircle As Circle '临时圆(正在拖动)
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
DoubleBuffered = True '启用双缓冲绘图,避免闪烁
End Sub
Private Sub Form1_MouseDown(sender As Object, e As MouseEventArgs) Handles Me.MouseDown
downPoint = e.Location '记下位置
End Sub
Private Sub Form1_MouseMove(sender As Object, e As MouseEventArgs) Handles Me.MouseMove
If e.Button Windows.Forms.MouseButtons.Left Then Return '左键没按下则退出
Dim r As Single = Math.Sqrt((e.X - downPoint.X) ^ 2 + (e.Y - downPoint.Y) ^ 2) '算出半径
tmpCircle = New Circle(downPoint, r) '更新临时圆
Refresh() '先刷新掉之前绘制的临时圆
tmpCircle.Draw(Me.CreateGraphics, Pens.Black) '绘制临时圆
End Sub
Private Sub Form1_MouseUp(sender As Object, e As MouseEventArgs) Handles Me.MouseUp
circleList.Add(tmpCircle) '鼠标弹起,把临时圆加入圆列表
End Sub
Private Sub Form1_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint
For Each c As Circle In circleList
c.Draw(e.Graphics, Pens.Black) '绘制出每个圆
Next
End Sub
End Class
VB.NET是采用了.NET技术的VB语言,而VB2008,2010是VB语言的版本。从VB6.0以后的VB都采用了.NET技术,所以,VB2008,2010都是VB.NET。在Visual Studio2008里的VB就是VB2008,以此类推。
Visual Studio是开发工具,在这个开发工具里,除了能编VB外,还能编VC++,C#,ASP.NET等。
不知道这样讲,你是否理解?