解答上面问题的同时也看看下面语句那里有错误 rs.Open " select * from sendrecord where 发送站号 = '" & Combo2.Text & "' and 日期 between '#" & DTPicker1 & "'# and '#" & DTPicker2 & "#'", conn, 1, 1初步判断是“日期”后面的语句出错 但是不懂怎么改 请高手指点!
先要将datagrid的属性allowupdate、allowDelete设置成true 然后:给你个例子 Private Sub DataGrid2_BeforeDelete(Cancel As Integer) Dim msg Dim strsql As String msg = MsgBox("您确定要删除本条记录吗?", vbOKCancel, "提示") If msg = vbCancel Then Cancel = True Else Cancel = False End If End Sub 执行的时候选中一条记录,按下键盘上的Delete键,就可以了
楼主赚大发了,一个贴三个问题,你该给谁分好呢,替你担心。如果取字符串中的数值的话用Val(),例如: Val("1998年,有一个春天")会返回1988但是取"那年春天小美刚18"中的数怎么办?我写了一个RevVal()你参考: '反向的Val函数 Public Function RevVal(ByVal pStrNum As String)as String If IsNumeric(pStrNum) Then RevVal = pStrNum Exit Function End If Dim i As Integer For i = 1 To Len(pStrNum) If Not IsNumeric(Right(pStrNum, i)) Then If i = 1 Then RevVal = "0" Exit Function Else RevVal = Right(pStrNum, i - 1) Exit Function End If End If NextEnd Function
先要将datagrid的属性allowupdate、allowDelete设置成true 然后:给你个例子 Private Sub DataGrid2_BeforeDelete(Cancel As Integer) Dim msg Dim strsql As String msg = MsgBox("您确定要删除本条记录吗?", vbOKCancel, "提示") If msg = vbCancel Then Cancel = True Else Cancel = False End If End Sub 执行的时候选中一条记录,按下键盘上的Delete键,就可以了这样就OK了
我写了改进版,只要它包含数字,总是返回该字符串中包含的数字字符串uuVal(): 对出现两个以上小数点或者负号的情况,没有提供错误检测,你应该针对这种情况完善之。Private Function IsNumChar(pChar As String) As Boolean Select Case pChar Case "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" IsNumChar = True
Case ".", "-" IsNumChar = True '因为小数点和负号涉及到更多的考虑,比如如果出现两个小数点或者两个负号 '你可以来完善这部分,我由于时间关系就不加了。
Case Else End Select End FunctionPrivate Function RevMid(pStr As String, pStart As Long, Optional pLen As Long) As String Dim iStart As Long Dim iEnd As Long Dim iLen As Long Dim pEnd As Long
If pLen = 0 Then '没有指定长度 pEnd = Len(pStr) Else pEnd = pStart + pLen - 1 End If
iStart = Len(pStr) - pEnd + 1 iEnd = Len(pStr) - pStart + 1 iLen = iEnd - iStart + 1 RevMid = Mid(pStr, iStart, iLen) End Function Private Function MyMid(pType As Integer, pStr As String, pStart As Long, Optional pLen As Long) As String Const uuLeft As Integer = 0 Const uuRight As Integer = 1
Select Case pType Case uuLeft If pLen = 0 Then MyMid = Mid(pStr, pStart) Else MyMid = Mid(pStr, pStart, pLen) End If
Case uuRight If pLen = 0 Then MyMid = RevMid(pStr, pStart) Else MyMid = RevMid(pStr, pStart, pLen) End If
Case Else Exit Function End Select End Function'uu的Val函数:只要字符串中包含数字,总是返回该字符串中的数字 Public Function uuVal(ByVal pStrNum As String, Optional pType As Integer) As String Const uuLeft As Integer = 0 Const uuRight As Integer = 1 If IsMissing(pType) Then pType = uuLeft If pType <> uuLeft And pType <> uuRight Then Exit Function If Len(pStrNum) = 0 Then Exit Function
If IsNumeric(pStrNum) Then uuVal = pStrNum Exit Function End If
Dim iNumStart As Long Dim iNumEnd As Long Dim i As Long Dim iLen As Long Dim str As String iLen = Len(pStrNum)
For i = 1 To iLen '找到第一个数字 If IsNumChar(MyMid(pType, pStrNum, i, 1)) Then iNumStart = i Exit For End If Next
'没找到数字 If iNumStart = 0 Then Exit Function
For i = iNumStart + 1 To iLen '找到从iNumStart开始第一个非数字字符 If Not IsNumChar(MyMid(pType, pStrNum, i, 1)) Then iNumEnd = i - 1 Exit For End If Next
'得到数字字符串 If iNumEnd > 0 Then '找到非数字字符 str = MyMid(pType, pStrNum, iNumStart, iNumEnd - iNumStart + 1) Else iNumEnd = iLen str = MyMid(pType, pStrNum, iNumStart) End If
If IsNumeric(str) Then uuVal = str Exit Function Else If iNumEnd < iLen Then '如果没有到字符串最后,则继续寻找 str = MyMid(pType, pStrNum, iNumEnd + 1) uuVal = uuVal(str) End If End If End Function把这4个函数放到标准模块中,例子: 默认从左边寻找数字: msgbox uuVal("他是1998年生的") 指定从左边寻找数字: msgbox uuVal("他是1998年生的",0) 指定从右边寻找数字: msgbox uuVal("他是1998年生的",1)一旦从指定方向找到数字字符串,则返回。
rs.Open " select * from sendrecord where 发送站号 = '" & Combo2.Text & "' and 日期 between #" & DTPicker1 & "# and #" & DTPicker2 & "#", conn, 1, 1初步判断是“日期”后面的语句出错 但是不懂怎么改 请高手指点!
鼠标右击datagrid,先选择 ‘编辑’,再次右击它,选择’属性‘ ,在’通用‘拦把’允许删除‘勾上就可以了
rs.Open " select * from sendrecord where 发送站号 = '" & Combo2.Text & "' and 日期 between '#" & DTPicker1 & "'# and '#" & DTPicker2 & "#'", conn, 1, 1初步判断是“日期”后面的语句出错 但是不懂怎么改 请高手指点!
然后:给你个例子
Private Sub DataGrid2_BeforeDelete(Cancel As Integer)
Dim msg
Dim strsql As String
msg = MsgBox("您确定要删除本条记录吗?", vbOKCancel, "提示")
If msg = vbCancel Then
Cancel = True
Else
Cancel = False
End If
End Sub
执行的时候选中一条记录,按下键盘上的Delete键,就可以了
更新数据库, 着一段 怎么实现?
比如buffer=" x=9022 "我想取等号后面的数据怎么取
right(buffer,4) 可以 但是只能娶4个字符 ,如果数据变化就不行了
该用什么函数 怎么实现?
Val("1998年,有一个春天")会返回1988但是取"那年春天小美刚18"中的数怎么办?我写了一个RevVal()你参考:
'反向的Val函数
Public Function RevVal(ByVal pStrNum As String)as String
If IsNumeric(pStrNum) Then
RevVal = pStrNum
Exit Function
End If
Dim i As Integer For i = 1 To Len(pStrNum)
If Not IsNumeric(Right(pStrNum, i)) Then
If i = 1 Then
RevVal = "0"
Exit Function
Else
RevVal = Right(pStrNum, i - 1)
Exit Function
End If
End If
NextEnd Function
buffer= comm.input
text1.text= val(buffer) 只能得到buffer 中数值的最后一个字符 如s=9600
显示的只有个0
然后:给你个例子
Private Sub DataGrid2_BeforeDelete(Cancel As Integer)
Dim msg
Dim strsql As String
msg = MsgBox("您确定要删除本条记录吗?", vbOKCancel, "提示")
If msg = vbCancel Then
Cancel = True
Else
Cancel = False
End If
End Sub
执行的时候选中一条记录,按下键盘上的Delete键,就可以了这样就OK了
很好办就从左边第3个字符开始取就可以了。
另 sequh(夏克) ,你的那个函数可以解决数字在中间的问题吗?
比如 他是1998年生的
value1=instr(buffer,"=")
value2=mid(buffer,value1+1,len(buffer)-value1)此时这个VALUE2的值就是你要取的那个等号后的数值,遇到类似的问题,就可以触类旁通。
为什么单片机发回的s=9600就截取不到呢 只显示一个0
为什么?? 关键时刻就出错了 郁闷 高手接着指点啊
对出现两个以上小数点或者负号的情况,没有提供错误检测,你应该针对这种情况完善之。Private Function IsNumChar(pChar As String) As Boolean
Select Case pChar
Case "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"
IsNumChar = True
Case ".", "-"
IsNumChar = True
'因为小数点和负号涉及到更多的考虑,比如如果出现两个小数点或者两个负号
'你可以来完善这部分,我由于时间关系就不加了。
Case Else
End Select
End FunctionPrivate Function RevMid(pStr As String, pStart As Long, Optional pLen As Long) As String
Dim iStart As Long
Dim iEnd As Long
Dim iLen As Long
Dim pEnd As Long
If pLen = 0 Then
'没有指定长度
pEnd = Len(pStr)
Else
pEnd = pStart + pLen - 1
End If
iStart = Len(pStr) - pEnd + 1
iEnd = Len(pStr) - pStart + 1
iLen = iEnd - iStart + 1
RevMid = Mid(pStr, iStart, iLen)
End Function
Private Function MyMid(pType As Integer, pStr As String, pStart As Long, Optional pLen As Long) As String
Const uuLeft As Integer = 0
Const uuRight As Integer = 1
Select Case pType
Case uuLeft
If pLen = 0 Then
MyMid = Mid(pStr, pStart)
Else
MyMid = Mid(pStr, pStart, pLen)
End If
Case uuRight
If pLen = 0 Then
MyMid = RevMid(pStr, pStart)
Else
MyMid = RevMid(pStr, pStart, pLen)
End If
Case Else
Exit Function
End Select
End Function'uu的Val函数:只要字符串中包含数字,总是返回该字符串中的数字
Public Function uuVal(ByVal pStrNum As String, Optional pType As Integer) As String
Const uuLeft As Integer = 0
Const uuRight As Integer = 1
If IsMissing(pType) Then pType = uuLeft
If pType <> uuLeft And pType <> uuRight Then Exit Function If Len(pStrNum) = 0 Then Exit Function
If IsNumeric(pStrNum) Then
uuVal = pStrNum
Exit Function
End If
Dim iNumStart As Long
Dim iNumEnd As Long
Dim i As Long
Dim iLen As Long
Dim str As String iLen = Len(pStrNum)
For i = 1 To iLen
'找到第一个数字
If IsNumChar(MyMid(pType, pStrNum, i, 1)) Then
iNumStart = i
Exit For
End If
Next
'没找到数字
If iNumStart = 0 Then Exit Function
For i = iNumStart + 1 To iLen
'找到从iNumStart开始第一个非数字字符
If Not IsNumChar(MyMid(pType, pStrNum, i, 1)) Then
iNumEnd = i - 1
Exit For
End If
Next
'得到数字字符串
If iNumEnd > 0 Then
'找到非数字字符
str = MyMid(pType, pStrNum, iNumStart, iNumEnd - iNumStart + 1)
Else
iNumEnd = iLen
str = MyMid(pType, pStrNum, iNumStart)
End If
'如果该字符串是数字,则返回,否则,继续寻找
'例如.abcd123jkjkl,则应该忽略.继续寻找。
If IsNumeric(str) Then
uuVal = str
Exit Function
Else
If iNumEnd < iLen Then
'如果没有到字符串最后,则继续寻找
str = MyMid(pType, pStrNum, iNumEnd + 1)
uuVal = uuVal(str)
End If
End If
End Function把这4个函数放到标准模块中,例子:
默认从左边寻找数字: msgbox uuVal("他是1998年生的")
指定从左边寻找数字: msgbox uuVal("他是1998年生的",0)
指定从右边寻找数字: msgbox uuVal("他是1998年生的",1)一旦从指定方向找到数字字符串,则返回。