VB与数据库高手请进,急!(改改程序)

来源:百度知道 编辑:UC知道 时间:2024/06/07 01:11:22
有下面的VB程序,帮我改改程序,要求:那些“加/减/乘/除”至少这四个算符是和数据库中匹配提取,顺便说明下你的数据库结构。
Private Sub Form_Load()
dim n as double
s = Trim(Text1.Text) '从外部输入如s = "23减6加5等于多少"
Dim re As Object
Set re = CreateObject("VBScript.RegExp")
re.IgnoreCase = True
re.Global = True
re.Pattern = "([加减乘除])?(\-?\d+(?:\.\d+)?)"
n = 0
For Each i In re.Execute(s)
Select Case i.SubMatches(0)
Case ""
n = i.SubMatches(1)
Case "加"
n = n + i.SubMatches(1)
Case "减"
n = n - i.SubMatches(1)
Case "乘"
n = n * i.SubMatches(1)
Case "除"
n = n / i.SubMatches(1)
End Select
Next i
MsgBox n
End Sub
我也想问可以在上面的“"([加减乘除])”中改为数据库连接吗?怎么改?我很菜,不知道说明白了不
我想把上面那个程序大改下。如:在TEXT1里输入“用100.5加60等于多少?”运行程序,程序自动把两个数之间的字符与SQL数据库中的各字符匹配后才知道它是“加法运算”,然后再进行加运算得出结果。而不是象上面那个程序那样就在程序里已经有了,因为我想必要的时候可以增加关键字,如:“他刚才有10

先建一个Access文件Test.mdb
建一个表TabTest
三个字段
Id,自动编号
TypeId,长整型
Text,文本

数据
Id TypeId Text
1 0
2 1 加
3 1 得到
4 2 减
5 3 乘
6 4 除

窗体
Dim strPattern As String

Private Sub Command1_Click()
Dim n As Double
s = "他刚才有100.5元钱,现在又得到60元,请问他现在有多少钱"
Dim re As Object
Set re = CreateObject("VBScript.RegExp")
re.IgnoreCase = True
re.Global = True
re.Pattern = "(" & strPattern & ")?(\-?\d+(?:\.\d+)?)"
n = 0
For Each i In re.Execute(s)
If i.SubMatches(0) = "" Then
x = 0
Else
Dim rs As Recordset
Set rs = OpenRecordset("select typeid from tabtest where text='" & i.SubMatches(0) & "'")
x = rs!typeid
End If
Select Case x
Case 0
n = i.SubMatches(1)
Case 1
n = n + i.SubMatches(1)
Case 2
n = n - i.SubMatches(1)