VB组合框问题
这是窗体1:PrivateSubCommand1_Click()Form1.HideForm2.ShowEndSubPrivateSubCommand2_Click()E...
这是窗体1:Private Sub Command1_Click()
Form1.Hide
Form2.Show
End SubPrivate Sub Command2_Click()
EndEnd SubPrivate Sub Form_Load()
Dim a As IntegerCombo1.Text = ""
For a = 1949 To 2010
Combo1.AddItem a
Next
Combo1.ListIndex = 0Dim s As IntegerCombo2.Text = ""
For s = 1 To 12
Combo2.AddItem s
Next
Combo2.ListIndex = 0Dim d As IntegerCombo3.Text = ""
For d = 1 To 31
Combo3.AddItem d
Next
Combo3.ListIndex = 0End Sub这是窗体2:Private Sub Command1_Click()
End
End SubPrivate Sub Command2_Click()
Form2.Hide
Form1.Show
End SubPrivate Sub Form_Load()
Txt1.Text = ""
Txt1.Text = "你的出生日期是:" & Str(a) & Str(s) & Str(d)
End Sub想问一下,为什么点击确定之后文本框中显示“你的出生日期是:0 0 0 ”? 还有怎么把组合框list里的值提取出来? 还请高手解答。。。感谢至极!!! 展开
Form1.Hide
Form2.Show
End SubPrivate Sub Command2_Click()
EndEnd SubPrivate Sub Form_Load()
Dim a As IntegerCombo1.Text = ""
For a = 1949 To 2010
Combo1.AddItem a
Next
Combo1.ListIndex = 0Dim s As IntegerCombo2.Text = ""
For s = 1 To 12
Combo2.AddItem s
Next
Combo2.ListIndex = 0Dim d As IntegerCombo3.Text = ""
For d = 1 To 31
Combo3.AddItem d
Next
Combo3.ListIndex = 0End Sub这是窗体2:Private Sub Command1_Click()
End
End SubPrivate Sub Command2_Click()
Form2.Hide
Form1.Show
End SubPrivate Sub Form_Load()
Txt1.Text = ""
Txt1.Text = "你的出生日期是:" & Str(a) & Str(s) & Str(d)
End Sub想问一下,为什么点击确定之后文本框中显示“你的出生日期是:0 0 0 ”? 还有怎么把组合框list里的值提取出来? 还请高手解答。。。感谢至极!!! 展开
2个回答
2013-12-23
展开全部
因为你的a,s,d是在Private Sub Form_Load()中定义的,所以你把a,s,d定义成Form1私有的(Private)变量,因此不能再Form2中调用。要解决这方法你必须把a,s,d定义成公有的(Public)。你窗口2(Form2)的代码是没问题的。-------------------------------------------我下面的代码是在VB2008上运行的,有的地方和VB6.0有区别,但总体思路是一样的,如果有不明白的地方可以继续问我。Public Class Form1
Public a As Integer
Public s As Integer
Public d As Integer Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
For i = 1949 To 2010 /* 这里为3个ComboBox输入值,没必要分别用三个变量,使用一个i即可 */
ComboBox1.Items.Add(i)
Next
For i = 1 To 12
ComboBox2.Items.Add(i)
Next
For i = 1 To 31
ComboBox3.Items.Add(i)
Next
End Sub /* 这里面我把3个循环附近的Combo1.Text = ""和Combo1.ListIndex = 0两个语句都去掉了,我在我机子上去掉后,运行已经能达到你输出日期的目的,如果你这两段代码有其它用处,你自己加上 */ Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
a = ComboBox1.Text
s = ComboBox2.Text
d = ComboBox3.Text
Form1.Hide()
Form2.Show()
End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
End
End Sub
End Class-----------------------------------------------希望对你有帮助 O(∩_∩)O~
Public a As Integer
Public s As Integer
Public d As Integer Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
For i = 1949 To 2010 /* 这里为3个ComboBox输入值,没必要分别用三个变量,使用一个i即可 */
ComboBox1.Items.Add(i)
Next
For i = 1 To 12
ComboBox2.Items.Add(i)
Next
For i = 1 To 31
ComboBox3.Items.Add(i)
Next
End Sub /* 这里面我把3个循环附近的Combo1.Text = ""和Combo1.ListIndex = 0两个语句都去掉了,我在我机子上去掉后,运行已经能达到你输出日期的目的,如果你这两段代码有其它用处,你自己加上 */ Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
a = ComboBox1.Text
s = ComboBox2.Text
d = ComboBox3.Text
Form1.Hide()
Form2.Show()
End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
End
End Sub
End Class-----------------------------------------------希望对你有帮助 O(∩_∩)O~
2013-12-23
展开全部
这样肯定不行啦~因为你a,s,d的变量是定义在了窗体1里面,变量a,s,d只能在窗体1之间使用。窗体2是不能使用的。获取list里面的东西:print combo1.list(组合框的索引值)
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询