我打算练习用代码首先自定义一个坐标系 再用Line 方法画好X轴Y轴 和 sin(x)正弦函数图象 。 代码我列在下面 。 我想问一下 为什么 第6行: Private Sub InitDraw() 始终在调试的时候提示变量未定义呢 ?? 求教育啊 。。
Option Explicit
Const PI = 3.1415926
Private Sub Form_Load()
InitDraw
End Sub
Private Sub InitDraw()
picDraw.Scale (-1, 10)-(10, -10)
picDraw.CurrentX = -1
picDraw.CurrentY = 0
picDraw.Line (0, 10)-(10, 0)
picDraw.CurrentX = 0
picDraw.CurrentY = 10
picDraw.Line (0, 10)-(0, -10)
picDraw.CurrentX = 0
picDraw.CurrentY = 0
picDraw.CurrentX = 0
picDraw.CurrentY = 0
End Sub
Private Sub cmdDraw_Click()
Dim i As Double
Dim amp As Double
Dim freq As Double
Dim phase As Double
picDraw.Cls
InitDraw
amp = Trim(txtAmp.Text)
freq = Trim(txtFre.Text)
phase = Trim(txtPhase.Text)
For i = 0 To 2 * PI Step 0.01
picDraw.Line -(i, amp * Sin(freq * i * phase))
Next i
End Sub
初学Vb 有一段代码始终提示变量未定义 ,求高手鉴定指导 !
答案:2 悬赏:30
解决时间 2021-03-06 02:55
- 提问者网友:久伴不朽
- 2021-03-05 21:16
最佳答案
- 二级知识专家网友:萌萌哒小可爱
- 2021-03-05 22:24
在Form1上添加1个PictureBox控件命名为picDraw,并设置其AutoRedraw属性为True
再要添加1个按钮控件命名为cmdDraw
添加3个TextBox控件分别命名为txtAmp,txtFre,txtPhase
LZ的书本代码有错误:
修改如下
Option Explicit
Const PI = 3.1415926
Private Sub Form_Load()
InitDraw
picDraw.AutoRedraw = True
End Sub
Private Sub InitDraw()
picDraw.Scale (-1, 10)-(10, -10)
picDraw.CurrentX = -1
picDraw.CurrentY = 0
picDraw.Line (0, 10)-(10, 0)
picDraw.CurrentX = 0
picDraw.CurrentY = 10
picDraw.Line (0, 10)-(0, -10)
picDraw.CurrentX = 0
picDraw.CurrentY = 0
picDraw.CurrentX = 0
picDraw.CurrentY = 0
End Sub
Private Sub cmdDraw_Click()
Dim i As Double
Dim amp As Double
Dim freq As Double
Dim phase As Double
picDraw.Cls
InitDraw
amp = Val(txtAmp.Text)
freq = Val(txtFre.Text)
phase = Val(txtPhase.Text)
For i = 0 To 2 * PI Step 0.01
picDraw.Line -(i, amp * Sin(freq * i * phase))
Next i
End Sub
再要添加1个按钮控件命名为cmdDraw
添加3个TextBox控件分别命名为txtAmp,txtFre,txtPhase
LZ的书本代码有错误:
修改如下
Option Explicit
Const PI = 3.1415926
Private Sub Form_Load()
InitDraw
picDraw.AutoRedraw = True
End Sub
Private Sub InitDraw()
picDraw.Scale (-1, 10)-(10, -10)
picDraw.CurrentX = -1
picDraw.CurrentY = 0
picDraw.Line (0, 10)-(10, 0)
picDraw.CurrentX = 0
picDraw.CurrentY = 10
picDraw.Line (0, 10)-(0, -10)
picDraw.CurrentX = 0
picDraw.CurrentY = 0
picDraw.CurrentX = 0
picDraw.CurrentY = 0
End Sub
Private Sub cmdDraw_Click()
Dim i As Double
Dim amp As Double
Dim freq As Double
Dim phase As Double
picDraw.Cls
InitDraw
amp = Val(txtAmp.Text)
freq = Val(txtFre.Text)
phase = Val(txtPhase.Text)
For i = 0 To 2 * PI Step 0.01
picDraw.Line -(i, amp * Sin(freq * i * phase))
Next i
End Sub
全部回答
- 1楼网友:厭世為王
- 2021-03-06 00:02
你好!
PicDraw定义了吗?
普通的变量可以隐式声明,但是像数组、结构体是不可以的。
……Scale???是VB .Net???
如果对你有帮助,望采纳。
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯