将http://community.csdn.net/Expert/topic/5435/5435787.xml?temp=.5303614答铁中 For i = 0 To 100 xx = (i - 50) / 10 yy(i) = 0.5 * xx ^ 2 + 3 * xx - 2 Next 改为: For i = 0 To 100 xx = (i - 50) / 10 yy(i) = (xx - 5) / 12 Next
zdingyun()你好,我将for i=0 to 100 改为200就不好用了 是因为程序里有数组么,试中xx为何意。 yy(i)可以定义为任何公式么
xx仅为了表示(i - 50) / 10 Option Explicit Dim i As Integer Dim yy(100) As Single Dim xx As Single Dim colvb As Long Dim x As Integer Dim y As Integer Dim txt As String Dim dy As Variant Public Function xp(colvb As Variant, x As Variant, y As Variant, txt As Variant) Me.ForeColor = colvb 'QBColor(14) Me.CurrentX = x Me.CurrentY = y Me.Print txt ' End FunctionPrivate Sub Command1_Click() 'x = 6 / y * 2 + 5 'y = (x - 5) / 12 For i = 0 To 100 'xx = (i - 50) / 10 'yy(i) = 0.5 * xx ^ 2 + 3 * xx - 2 yy(i) = ((i - 50) / 10 - 5) / 12 Next Line (0, 4000)-(10000, 4000) Line (5000, 0)-(5000, 8000) Line (6000, 3950)-(6000, 4000) Line (4000, 3950)-(4000, 4000) Line (5000, 3000)-(5100, 3000) Line (5000, 5000)-(5100, 5000)For i = 1 To 100 PSet ((i - 50) * 10 + 5000, -1 * yy(i) * 100 + 4000), vbRed Next x = 9000 y = 3900 txt = "X轴" colvb = vbBlue dy = xp(colvb, x, y, txt) x = 5100 y = 500 txt = "y轴" colvb = vbBlue dy = xp(colvb, x, y, txt) x = 5000 y = 4000 txt = "0" dy = xp(colvb, x, y, txt) x = 6000 - 70 y = 4000 txt = "10" dy = xp(colvb, x, y, txt) x = 4000 - 70 y = 4000 txt = "-10" dy = xp(colvb, x, y, txt) x = 5100 y = 2930 txt = "10" dy = xp(colvb, x, y, txt) x = 5100 y = 4930 txt = "-10" dy = xp(colvb, x, y, txt)End Sub 将for i=0 to 100 改为200就不好用了,这是算法发生变化,与坐标对应不一致。
zdingyun()如何让图象上的掉多一点啊,是用xx控制么
公式导错,先更正如下: Private Sub Command1_Click() 'x = 6 / y * 2 + 5 'y = 12 / (x - 5) For i = 0 To 100 xx = (i - 50) / 10 If xx - 5 <> 0 Then yy(i) = 12 / (xx - 5) End If Next Line (0, 4000)-(10000, 4000) Line (5000, 0)-(5000, 8000) Line (6000, 3950)-(6000, 4000) Line (4000, 3950)-(4000, 4000) Line (5000, 3000)-(5100, 3000) Line (5000, 5000)-(5100, 5000)'。。 End Sub
完整显示Y=12/(X+5)的代码: Option Explicit Dim i As Integer Dim yy(1000) As Single Dim xx As Single Dim colvb As Long Dim x As Integer Dim y As Integer Dim txt As String Dim dy As Variant Public Function xp(colvb As Variant, x As Variant, y As Variant, txt As Variant) Me.ForeColor = colvb 'QBColor(14) Me.CurrentX = x Me.CurrentY = y Me.Print txt ' End Function Private Sub Command1_Click() For i = 0 To 1000 xx = (i - 500) / 10 If xx - 5 <> 0 Then yy(i) = 12 / (xx - 5) End If Next For i = 1 To 1000 PSet ((i - 50) * 5 + 3000, -1 * yy(i) * 200 + 4000), vbRed Next End SubPrivate Sub Form_Load() Line (0, 4000)-(10000, 4000) Line (5000, 0)-(5000, 8000) Line (6000, 3950)-(6000, 4000) Line (4000, 3950)-(4000, 4000) Line (5000, 3000)-(5100, 3000) Line (5000, 5000)-(5100, 5000) x = 9000 y = 3900 txt = "X轴" colvb = vbBlue dy = xp(colvb, x, y, txt) x = 5100 y = 500 txt = "y轴" colvb = vbBlue dy = xp(colvb, x, y, txt) x = 5000 y = 4000 txt = "0" dy = xp(colvb, x, y, txt) x = 6000 - 70 y = 4000 txt = "10" dy = xp(colvb, x, y, txt) x = 4000 - 70 y = 4000 txt = "-10" dy = xp(colvb, x, y, txt) x = 5100 y = 2930 txt = "10" dy = xp(colvb, x, y, txt) x = 5100 y = 4930 txt = "-10" dy = xp(colvb, x, y, txt) End Sub
很难吗?可能是我理解错了 你看对不对 式子: x=6/y*2+5 我直接画图 大家看行吗?Dim i As Long Picture1.DrawWidth = 1 Picture1.Scale (0, 10000)-(5000, 0) For i = 2 To Picture1.Height If i <> 1000 Then Picture1.Line (6 / ((i / 1000) - 1) * 2 + 5, i)-(6 / (i / 1000) * 2 + 5, i), QBColor(1) End If Next 简单的也可以应该
你的方法可以画曲线,但坐标及曲线走向符合要求较难算准,代码修改如下: Private Sub Form_Load() Dim i As Long Picture1.DrawWidth = 1 Picture1.Line (4000, 8000)-(4000, 0) Picture1.Line (0, 4000)-(8000, 4000) For i = 1 To 8000 If i <> 1000 Then Picture1.PSet (-12 / (i / 1000 - 1) + 5 * 100 + 4000, i + 3000), vbRed End If Next End Sub我将我给出的代码纠正错误附下,倍率作法不一,供参考: Option Explicit Dim i As Integer Dim yy(1000) As Single Dim xx As Single Dim colvb As Long Dim x As Integer Dim Y As Integer Dim txt As String Dim dy As Variant Public Function xp(colvb As Variant, x As Variant, Y As Variant, txt As Variant) Me.ForeColor = colvb 'QBColor(14) Me.CurrentX = x Me.CurrentY = Y Me.Print txt ' End Function Private Sub Command1_Click() '画Y=12/(X-5) For i = 0 To 1000 xx = (i - 500) / 10 If xx - 5 <> 0 Then yy(i) = 12 / (xx - 5) End If Next For i = 1 To 1000 PSet ((i - 500) * 5 + 5250, -1 * yy(i) * 200 + 4000), vbRed Next End SubPrivate Sub Command2_Click() '画Y=10/X For i = 0 To 1000 xx = (i - 500) / 10 If xx <> 0 Then yy(i) = 10 / (xx) End If Next For i = 1 To 500 PSet ((i - 500) * 5 + 5000, -1 * yy(i) * 200 + 4000), vbYellow NextEnd SubPrivate Sub Command3_Click() '画Y=10/X For i = 0 To 1000 xx = (i - 500) / 10 If xx <> 0 Then yy(i) = 10 / (xx) End If Next For i = 501 To 1000 PSet ((i - 500) * 5 + 5000, -1 * yy(i) * 200 + 4000), vbBlue NextEnd SubPrivate Sub Command4_Click() '画Y=10/X For i = 0 To 1000 xx = (i - 500) '/ 10 If xx <> 0 Then yy(i) = 10 / (xx) End If Next For i = 1 To 500 PSet ((i - 500) * 50 + 5000, -1 * yy(i) * 200 + 4000), vbBlack Next End Sub Private Sub Form_Load() 'Line (0, 4000 - 316)-(10000, 4000 - 316) 'y=0 Line (0, 4000)-(10000, 4000) 'y=0 'Line (0, 3000)-(10000, 3000)'y=10 'Line (0, 3900)-(10000, 3900) 'y=1 'Line (5000 + 316, 0)-(5000 + 316, 8000) 'x=0 Line (5000, 0)-(5000, 8000) 'x=0 'Line (5500, 0)-(5500, 8000) 'x=5 'Line (6000, 0)-(6000, 8000) 'x=10 Line (6000, 3950)-(6000, 4000) Line (4000, 3950)-(4000, 4000) Line (5000, 3000)-(5100, 3000) Line (5000, 5000)-(5100, 5000) x = 9000 Y = 3900 txt = "X轴" colvb = vbBlue dy = xp(colvb, x, Y, txt) x = 5100 Y = 500 txt = "y轴" colvb = vbBlue dy = xp(colvb, x, Y, txt) x = 5000 Y = 4000 txt = "0" dy = xp(colvb, x, Y, txt) x = 6000 - 70 Y = 4000 txt = "10" dy = xp(colvb, x, Y, txt) x = 4000 - 70 Y = 4000 txt = "-10" dy = xp(colvb, x, Y, txt) x = 5100 Y = 2930 txt = "10" dy = xp(colvb, x, Y, txt) x = 5100 Y = 4930 txt = "-10" dy = xp(colvb, x, Y, txt) End Sub
zdingyun() 谢谢你的关注,谢谢你了。
我画坐标的代码可简化,用scale 我发现vb只要用心很好学,不想别的语言
Option Explicit Dim x As Single Dim y As Single Dim i As Single Private Sub Command1_Click() Picture1.Scale (0, 200)-(200, 0) For i = 0 To 200 Step 0.5 x = i - 100 If x <> 5 Then y = 12 / (x - 5) End If Picture1.PSet (x + 105, y + 100), vbRed Next End SubPrivate Sub Command2_Click() Dim d As Single Dim k As Single Dim h As Single Picture1.Scale (0, 100)-(100, 0) d = 90 * 3.1416 / 180 k = -0.1 h = 3 For x = 0 To 3.1416 * 10 Step 0.1 y = h * Sin(x + d) * Exp(-k * x) Picture1.PSet (x, y + 50) Next End Sub
vb不能解决的是涉及到vb本身的局限的东西,如要做出运行在ring0上的东西,vb就不能。算法的问题,任何语言都能实现。
For i = 0 To 100
xx = (i - 50) / 10
yy(i) = 0.5 * xx ^ 2 + 3 * xx - 2
Next
改为:
For i = 0 To 100
xx = (i - 50) / 10
yy(i) = (xx - 5) / 12
Next
是因为程序里有数组么,试中xx为何意。
yy(i)可以定义为任何公式么
Option Explicit
Dim i As Integer
Dim yy(100) As Single
Dim xx As Single
Dim colvb As Long
Dim x As Integer
Dim y As Integer
Dim txt As String
Dim dy As Variant
Public Function xp(colvb As Variant, x As Variant, y As Variant, txt As Variant)
Me.ForeColor = colvb 'QBColor(14)
Me.CurrentX = x
Me.CurrentY = y
Me.Print txt '
End FunctionPrivate Sub Command1_Click()
'x = 6 / y * 2 + 5
'y = (x - 5) / 12
For i = 0 To 100
'xx = (i - 50) / 10
'yy(i) = 0.5 * xx ^ 2 + 3 * xx - 2
yy(i) = ((i - 50) / 10 - 5) / 12
Next
Line (0, 4000)-(10000, 4000)
Line (5000, 0)-(5000, 8000)
Line (6000, 3950)-(6000, 4000)
Line (4000, 3950)-(4000, 4000)
Line (5000, 3000)-(5100, 3000)
Line (5000, 5000)-(5100, 5000)For i = 1 To 100
PSet ((i - 50) * 10 + 5000, -1 * yy(i) * 100 + 4000), vbRed
Next
x = 9000
y = 3900
txt = "X轴"
colvb = vbBlue
dy = xp(colvb, x, y, txt)
x = 5100
y = 500
txt = "y轴"
colvb = vbBlue
dy = xp(colvb, x, y, txt)
x = 5000
y = 4000
txt = "0"
dy = xp(colvb, x, y, txt)
x = 6000 - 70
y = 4000
txt = "10"
dy = xp(colvb, x, y, txt)
x = 4000 - 70
y = 4000
txt = "-10"
dy = xp(colvb, x, y, txt)
x = 5100
y = 2930
txt = "10"
dy = xp(colvb, x, y, txt)
x = 5100
y = 4930
txt = "-10"
dy = xp(colvb, x, y, txt)End Sub
将for i=0 to 100 改为200就不好用了,这是算法发生变化,与坐标对应不一致。
Private Sub Command1_Click()
'x = 6 / y * 2 + 5
'y = 12 / (x - 5)
For i = 0 To 100
xx = (i - 50) / 10
If xx - 5 <> 0 Then
yy(i) = 12 / (xx - 5)
End If
Next
Line (0, 4000)-(10000, 4000)
Line (5000, 0)-(5000, 8000)
Line (6000, 3950)-(6000, 4000)
Line (4000, 3950)-(4000, 4000)
Line (5000, 3000)-(5100, 3000)
Line (5000, 5000)-(5100, 5000)'。。
End Sub
Option Explicit
Dim i As Integer
Dim yy(1000) As Single
Dim xx As Single
Dim colvb As Long
Dim x As Integer
Dim y As Integer
Dim txt As String
Dim dy As Variant
Public Function xp(colvb As Variant, x As Variant, y As Variant, txt As Variant)
Me.ForeColor = colvb 'QBColor(14)
Me.CurrentX = x
Me.CurrentY = y
Me.Print txt '
End Function
Private Sub Command1_Click()
For i = 0 To 1000
xx = (i - 500) / 10
If xx - 5 <> 0 Then
yy(i) = 12 / (xx - 5)
End If
Next
For i = 1 To 1000
PSet ((i - 50) * 5 + 3000, -1 * yy(i) * 200 + 4000), vbRed
Next
End SubPrivate Sub Form_Load()
Line (0, 4000)-(10000, 4000)
Line (5000, 0)-(5000, 8000)
Line (6000, 3950)-(6000, 4000)
Line (4000, 3950)-(4000, 4000)
Line (5000, 3000)-(5100, 3000)
Line (5000, 5000)-(5100, 5000)
x = 9000
y = 3900
txt = "X轴"
colvb = vbBlue
dy = xp(colvb, x, y, txt)
x = 5100
y = 500
txt = "y轴"
colvb = vbBlue
dy = xp(colvb, x, y, txt)
x = 5000
y = 4000
txt = "0"
dy = xp(colvb, x, y, txt)
x = 6000 - 70
y = 4000
txt = "10"
dy = xp(colvb, x, y, txt)
x = 4000 - 70
y = 4000
txt = "-10"
dy = xp(colvb, x, y, txt)
x = 5100
y = 2930
txt = "10"
dy = xp(colvb, x, y, txt)
x = 5100
y = 4930
txt = "-10"
dy = xp(colvb, x, y, txt)
End Sub
为什么((i - 50) * 5 + 3000, -1 * yy(i) * 200 + 4000), 着要乘以5
而yy乘以200,这样和坐标就不对应了
你看对不对
式子: x=6/y*2+5
我直接画图 大家看行吗?Dim i As Long
Picture1.DrawWidth = 1
Picture1.Scale (0, 10000)-(5000, 0)
For i = 2 To Picture1.Height
If i <> 1000 Then
Picture1.Line (6 / ((i / 1000) - 1) * 2 + 5, i)-(6 / (i / 1000) * 2 + 5, i), QBColor(1)
End If
Next
简单的也可以应该
Private Sub Form_Load()
Dim i As Long
Picture1.DrawWidth = 1
Picture1.Line (4000, 8000)-(4000, 0)
Picture1.Line (0, 4000)-(8000, 4000)
For i = 1 To 8000
If i <> 1000 Then
Picture1.PSet (-12 / (i / 1000 - 1) + 5 * 100 + 4000, i + 3000), vbRed
End If
Next
End Sub我将我给出的代码纠正错误附下,倍率作法不一,供参考:
Option Explicit
Dim i As Integer
Dim yy(1000) As Single
Dim xx As Single
Dim colvb As Long
Dim x As Integer
Dim Y As Integer
Dim txt As String
Dim dy As Variant
Public Function xp(colvb As Variant, x As Variant, Y As Variant, txt As Variant)
Me.ForeColor = colvb 'QBColor(14)
Me.CurrentX = x
Me.CurrentY = Y
Me.Print txt '
End Function
Private Sub Command1_Click() '画Y=12/(X-5)
For i = 0 To 1000
xx = (i - 500) / 10
If xx - 5 <> 0 Then
yy(i) = 12 / (xx - 5)
End If
Next
For i = 1 To 1000
PSet ((i - 500) * 5 + 5250, -1 * yy(i) * 200 + 4000), vbRed
Next
End SubPrivate Sub Command2_Click() '画Y=10/X
For i = 0 To 1000
xx = (i - 500) / 10
If xx <> 0 Then
yy(i) = 10 / (xx)
End If
Next
For i = 1 To 500
PSet ((i - 500) * 5 + 5000, -1 * yy(i) * 200 + 4000), vbYellow
NextEnd SubPrivate Sub Command3_Click() '画Y=10/X
For i = 0 To 1000
xx = (i - 500) / 10
If xx <> 0 Then
yy(i) = 10 / (xx)
End If
Next
For i = 501 To 1000
PSet ((i - 500) * 5 + 5000, -1 * yy(i) * 200 + 4000), vbBlue
NextEnd SubPrivate Sub Command4_Click() '画Y=10/X
For i = 0 To 1000
xx = (i - 500) '/ 10
If xx <> 0 Then
yy(i) = 10 / (xx)
End If
Next
For i = 1 To 500
PSet ((i - 500) * 50 + 5000, -1 * yy(i) * 200 + 4000), vbBlack
Next
End Sub
Private Sub Form_Load()
'Line (0, 4000 - 316)-(10000, 4000 - 316) 'y=0
Line (0, 4000)-(10000, 4000) 'y=0
'Line (0, 3000)-(10000, 3000)'y=10
'Line (0, 3900)-(10000, 3900) 'y=1
'Line (5000 + 316, 0)-(5000 + 316, 8000) 'x=0
Line (5000, 0)-(5000, 8000) 'x=0
'Line (5500, 0)-(5500, 8000) 'x=5
'Line (6000, 0)-(6000, 8000) 'x=10
Line (6000, 3950)-(6000, 4000)
Line (4000, 3950)-(4000, 4000)
Line (5000, 3000)-(5100, 3000)
Line (5000, 5000)-(5100, 5000)
x = 9000
Y = 3900
txt = "X轴"
colvb = vbBlue
dy = xp(colvb, x, Y, txt)
x = 5100
Y = 500
txt = "y轴"
colvb = vbBlue
dy = xp(colvb, x, Y, txt)
x = 5000
Y = 4000
txt = "0"
dy = xp(colvb, x, Y, txt)
x = 6000 - 70
Y = 4000
txt = "10"
dy = xp(colvb, x, Y, txt)
x = 4000 - 70
Y = 4000
txt = "-10"
dy = xp(colvb, x, Y, txt)
x = 5100
Y = 2930
txt = "10"
dy = xp(colvb, x, Y, txt)
x = 5100
Y = 4930
txt = "-10"
dy = xp(colvb, x, Y, txt)
End Sub
我发现vb只要用心很好学,不想别的语言
Dim x As Single
Dim y As Single
Dim i As Single
Private Sub Command1_Click()
Picture1.Scale (0, 200)-(200, 0)
For i = 0 To 200 Step 0.5
x = i - 100
If x <> 5 Then
y = 12 / (x - 5)
End If
Picture1.PSet (x + 105, y + 100), vbRed
Next
End SubPrivate Sub Command2_Click()
Dim d As Single
Dim k As Single
Dim h As Single
Picture1.Scale (0, 100)-(100, 0)
d = 90 * 3.1416 / 180
k = -0.1
h = 3
For x = 0 To 3.1416 * 10 Step 0.1
y = h * Sin(x + d) * Exp(-k * x)
Picture1.PSet (x, y + 50)
Next
End Sub