VB里怎么把文本的值赋给变量。
PublictxtPriceAsCurrencyPublictxtQYTAsCurrencyPublictxtSumAsCurrencyPublictxtDisCount...
Public txtPrice As Currency
Public txtQYT As Currency
Public txtSum As Currency
Public txtDisCount As Currency
Public txtRsum As Currency
Private Sub Command1_Click()
txtPrice = CInt(Text1.Text)
txtQYT = CInt(Text2.Text)
txtSum = CInt(Text3.Text)
txtDisCount = CInt(Text4.Text)
txtRsum = CInt(Text5.Text)
txtSum = Val(txtPrice) * Val(txtQYT)
If txtSum > 200 Then
txtDisCount = Val(txtSum) * 0.1
txtRsum = Val(txtSum) - Val(txtDisCount)
Else
txtRsum = txtSum
End If
End Sub
我最近才刚开始学VB,请各位大侠指教!
大家看看是哪出了问题了!谢谢 展开
Public txtQYT As Currency
Public txtSum As Currency
Public txtDisCount As Currency
Public txtRsum As Currency
Private Sub Command1_Click()
txtPrice = CInt(Text1.Text)
txtQYT = CInt(Text2.Text)
txtSum = CInt(Text3.Text)
txtDisCount = CInt(Text4.Text)
txtRsum = CInt(Text5.Text)
txtSum = Val(txtPrice) * Val(txtQYT)
If txtSum > 200 Then
txtDisCount = Val(txtSum) * 0.1
txtRsum = Val(txtSum) - Val(txtDisCount)
Else
txtRsum = txtSum
End If
End Sub
我最近才刚开始学VB,请各位大侠指教!
大家看看是哪出了问题了!谢谢 展开
1个回答
展开全部
文本指的是什么? 如果是字符串,那么可以直接赋值,只要变量是String类型就可以.
如果是文本文件,可以用Open语句打开,然后用Input语句将内容读入变量.如:
Dim txt as String
Open "文件名" For Input As #1
Input #1, txt
Close #1
如果是文本文件,可以用Open语句打开,然后用Input语句将内容读入变量.如:
Dim txt as String
Open "文件名" For Input As #1
Input #1, txt
Close #1
追问
这个设计界面如图,代码如下:
Private Sub Command1_Click()
Price = Int(Val(Text1.Text))
QYT = Int(Val(Text2.Text))
Sum = Int(Val(Text3.Text))
DisCount = Int(Val(Text4.Text))
Rsum = Int(Val(Text5.Text))
Sum = Val(Price) * Val(QYT)
If Sum > 200 Then
txtDisCount = Val(Sum) * 0.1
txtRsum = Val(Sum) - Val(DisCount)
Else
Rsum = Sum
End If
End Sub
计算无法得到数据,请问是什么原因啊!
追答
因为你的计算结果在变量中,并没有设置到各文本框的Text属性.你应该在计算出结果以后将变量的值写回对应的文本框.比如在End Sub前加入下面的代码.
Text3.Text = Sum
Text4.Text = txtDisCount
Text5.Text = txtRsum
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |