VB 代码如下,为何运行之后错误424,调试之后指向print #1,T1.text一句?
PrivateSubForm_Load()Form2.Controls.Add"VB.Textbox","T1",Form2WithForm2!T1.Visible=Tr...
Private Sub Form_Load()
Form2.Controls.Add "VB.Textbox", "T1", Form2
With Form2!T1
.Visible = True
.Height = 350
.Left = 6000
.Top = 960
.Width = 600
.Text = 0#
End With
Form2.Controls.Add "VB.Textbox", "T2", Form2
With Form2!T2
.Visible = True
.Height = 350
.Left = 6000
.Top = 1560
.Width = 600
.Text = 80#
End With
End Sub
Private Sub Command1_Click()
Dim a As Integer
a = MsgBox("是否确认保存数据?", vbOKCancel + vbQuestion + vbDefaultButton1, "注意")
Select Case a
Case 1
Open App.Path & "\123.txt" For Output As #1
Print #1, T1.Text
Print #1, T2.Text
Close #1
End Select
End Sub
我想要实现的是在Form2窗口启动时动态创建两个文本框,然后用Form2上已有的Commad按钮保存这两个动态创建文本框内的数据,将数据保存在TXT文件中,不知道代码有没有打错。我是新手,恳请各位指教! 展开
Form2.Controls.Add "VB.Textbox", "T1", Form2
With Form2!T1
.Visible = True
.Height = 350
.Left = 6000
.Top = 960
.Width = 600
.Text = 0#
End With
Form2.Controls.Add "VB.Textbox", "T2", Form2
With Form2!T2
.Visible = True
.Height = 350
.Left = 6000
.Top = 1560
.Width = 600
.Text = 80#
End With
End Sub
Private Sub Command1_Click()
Dim a As Integer
a = MsgBox("是否确认保存数据?", vbOKCancel + vbQuestion + vbDefaultButton1, "注意")
Select Case a
Case 1
Open App.Path & "\123.txt" For Output As #1
Print #1, T1.Text
Print #1, T2.Text
Close #1
End Select
End Sub
我想要实现的是在Form2窗口启动时动态创建两个文本框,然后用Form2上已有的Commad按钮保存这两个动态创建文本框内的数据,将数据保存在TXT文件中,不知道代码有没有打错。我是新手,恳请各位指教! 展开
展开全部
Dim T1 As TextBox, T2 As TextBox
Private Sub Form_Load()
Set T1 = Controls.Add("VB.Textbox", "T1")
With T1
.Visible = True
.Height = 350
.Left = 6000
.Top = 960
.Width = 600
.Text = 0#
End With
Set T2 = Controls.Add("VB.Textbox", "T2")
With T2
.Visible = True
.Height = 350
.Left = 6000
.Top = 1560
.Width = 600
.Text = 80#
End With
End Sub
Private Sub Command1_Click()
If MsgBox("是否确认保存数据?", vbOKCancel + vbQuestion, "注意") = vbOK Then
Open App.Path & "\123.txt" For Output As #1
Print #1, T1.Text
Print #1, T2.Text
Close #1
End If
End Sub
或者这样:
Private Sub Form_Load()
Controls.Add "VB.Textbox", "T1"
With Me!T1
.Visible = True
.Height = 350
.Left = 6000
.Top = 960
.Width = 600
.Text = 0#
End With
Controls.Add "VB.Textbox", "T2"
With Me!T2
.Visible = True
.Height = 350
.Left = 6000
.Top = 1560
.Width = 600
.Text = 80#
End With
End Sub
Private Sub Command1_Click()
If MsgBox("是否确认保存数据?", vbOKCancel + vbQuestion, "注意") = vbOK Then
Open App.Path & "\123.txt" For Output As #1
Print #1, Me!T1.Text
Print #1, Me!T2.Text
Close #1
End If
End Sub
建议尽量用第一种方法,那是标准用法
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询