往文件中写入数据,当是英文名称时,不会出错 ,当输入中文名时,Text4.text会显示不出来,不知什么原因,请高手指教,谢谢!!
Private Type Product
Name As String * 10
Price As Integer
Number As Integer
End TypePrivate Sub Command1_Click()
Static count As Integer
Dim prod As ProductWith prod
.Name = Text1.Text
.Price = Val(Text2.Text)
.Number = Val(Text3.Text)
End Withcount = count + 1
Open App.Path & "\product.dat" For Random As #1
Put #1, count, prod
Close #1Text1.Text = ""
Text2.Text = ""
Text3.Text = ""End Sub
Private Sub Command2_Click()
Dim i As Integer
Dim n As Integer
Dim prod As ProductOpen App.Path & "\product.dat" For Random As #1
n = LOF(1) / Len(prod)For i = 1 To n
Get #1, i, prod
Debug.Print Trim(prod.Price)
If Trim(prod.Name) = Trim(Text5.Text) Then
Text4.Text = "产品:" & prod.Name & Chr(13) & Chr(10) & "数量:" & prod.Number & Chr(13) & Chr(10) & "单价:" & prod.Price
'Text3.Text = prod.Price
End If
Next iClose #1End Sub界面如下:
Private Type Product
Name As String * 10
Price As Integer
Number As Integer
End TypePrivate Sub Command1_Click()
Static count As Integer
Dim prod As ProductWith prod
.Name = Text1.Text
.Price = Val(Text2.Text)
.Number = Val(Text3.Text)
End Withcount = count + 1
Open App.Path & "\product.dat" For Random As #1
Put #1, count, prod
Close #1Text1.Text = ""
Text2.Text = ""
Text3.Text = ""End Sub
Private Sub Command2_Click()
Dim i As Integer
Dim n As Integer
Dim prod As ProductOpen App.Path & "\product.dat" For Random As #1
n = LOF(1) / Len(prod)For i = 1 To n
Get #1, i, prod
Debug.Print Trim(prod.Price)
If Trim(prod.Name) = Trim(Text5.Text) Then
Text4.Text = "产品:" & prod.Name & Chr(13) & Chr(10) & "数量:" & prod.Number & Chr(13) & Chr(10) & "单价:" & prod.Price
'Text3.Text = prod.Price
End If
Next iClose #1End Sub界面如下:
解决方案 »
- jhone99请进,有新的要求2。
- 老大啊,我读取记录的时候,我设置了个播放进度条的动画,但是却不动哦.
- 思路:在2k中屏蔽ctrl+alt+del三键
- VB 如何获得SQL server 服务器的日期时间?
- 我的分快干了,有谁能救我吗?给我点分吧...
- 给100分请大家帮忙,有没有vb的经销存软件或者别的(适合于毕业设计)
- 用vb程序存取web库(.mdb)的方法!请大家讨论,提供代码,up有分!
- fpspread控件中如何改变列首的高度及行首内容不换行
- 请提供几个好的vb网站,希望有大量控件下载
- 用vb如何写一个转换数字为人民币的函数
- 如何用VBCODE找到我所要的文件?
- 判断数组元素是否重复的问题
.Name = Text1.Text
.Price = Val(Text2.Text)
.Number = Val(Text3.Text)去掉val
Option Explicit'Private Type Product
'Name As String * 10
'Price As Integer
'Number As Integer
'End Type
Private Const NAMELEN As Long = 30 'Name字段字节数
Private Type ProductForOut
strName As String
Price As Integer
Number As Integer
End Type
Private Type ProductForInput
NA As Integer '用于吃掉多余的信息
bName(NAMELEN - 1) As Byte '因为默认下标从0开始
Price As Integer
Number As Integer
End TypePrivate Sub Command1_Click() Static count As Integer
'Dim prod As Product
Dim prod As ProductForOut
Dim strTemp$, i&
strTemp = Text1.Text
i = LenB(StrConv(Text1.Text, vbFromUnicode))
If (i > 20) Then
MsgBox "Name字段输入过长!", 16, "错误"
Exit Sub
End If
With prod
.strName = strTemp & Space$(NAMELEN - i)
.Price = Val(Text2.Text)
.Number = Val(Text3.Text)
End With
count = count + 1
Open App.Path & "\product.dat" For Random As #1
Put #1, count, prod
Close #1
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""End SubPrivate Sub Command2_Click()
Dim i As Integer
Dim n As Integer
'Dim prod As Product
Dim prod As ProductForInput
Dim strTemp$ Open App.Path & "\product.dat" For Random As #1
n = LOF(1) / Len(prod)
For i = 1 To n
Get #1, i, prod
Debug.Print Trim(prod.Price)
strTemp = StrConv(prod.bName, vbUnicode)
If (Trim(strTemp) = Trim(Text5.Text)) Then
Text4.Text = "产品:" & strTemp & vbCrLf & "数量:" & prod.Number & vbCrLf & "单价:" & prod.Price
End If
Next i
Close #1End Sub
在这行下面加上 msgbox "aaa" 确认上面的等式已成立上面的等式如不成立原因可能有二1.改为 If Ucase(Trim(prod.Name)) = Ucase(Trim(Text5.Text)) Then
VB 的 "ABC" 是不等于 "abc" 的2.Name As String * 10
改为 * 20 因为一个汉字等于英文字的两倍 有可能出错 或取到的内容长度不对
只是变量名要定义好类型,如果是variant的话,存进去的内容会带变量类型,不是你想要的结果.
prod.Name = Trim(Replace(prod.Name, Chr(0), ""))
If Trim(prod.Name) = Trim(Text5.Text) Then