Dim str As String = 20020206
If str.Length = "8" Then
Dim str1 As String = str.Substring(4, 8)
Me.Label1.Text = str1
End If
其他信息: 索引和长度必须引用该字符串内的位置。
Dim str As String = 20020206
If str.Length = "8" Then
Dim str1 As String = str.Substring(0, 4) & "/" & str.Substring(4, 6) & "/" & str.Substring(6)
Me.Label1.Text = str1
End If
其他信息: 索引和长度必须引用该字符串内的位置。
为什么不能插入啊 我想把20020206变成 2002/02/06
If str.Length = "8" Then
Dim str1 As String = str.Substring(4, 8)
Me.Label1.Text = str1
End If
其他信息: 索引和长度必须引用该字符串内的位置。
Dim str As String = 20020206
If str.Length = "8" Then
Dim str1 As String = str.Substring(0, 4) & "/" & str.Substring(4, 6) & "/" & str.Substring(6)
Me.Label1.Text = str1
End If
其他信息: 索引和长度必须引用该字符串内的位置。
为什么不能插入啊 我想把20020206变成 2002/02/06
解决方案 »
- 画图程序中关于~~~~改变字体
- 谁能帮我修改这段使图片居中显示的代码
- 如何将日期型专程字段类型??怎么将日期类型拆分?比如2008-7-6通过什么函数能将其分开变成3列 年,月,日,然后各自进各自所属列??
- VB控制I/O板卡的问题
- MSFlexGrid中如何按实际的行数和列数来显示表格的大小
- 关于弹出菜单的一个难题
- 有人研究出来了vb下切换声道的办法了吗?请注意不是关半个声道不是balance
- 有没有人知道如何把数据库中的两个空表合并起来?????
- 初始化提供者中发生错误,测试连接失败(初学者)
- 为何WIN2k下做的安装程序在WINDOWSxP下无法安装,在安装过程中总出现找不到文件的错
- dll怎么调用其他程序传参数?像点击"用迅雷下载"时,自动开启迅雷并新建下载任务
- 如何将EXCEL文件批量生成ADO记录集?
(1)标准模块中自定义函数'函数名称:GetLastDateInMonth
'编写时间:2004-08-26
'最后更新:2004-08-26
'编写人:
'功能:某月的最后一天是多少号Public Function GetLastDateInMonth(ByVal MyDate As Date) As Integer
On Error Resume Next GetLastDateInMonth = (31 - Day(DateSerial(Year(MyDate), Month(MyDate), 31)))
If GetLastDateInMonth = 0 Then GetLastDateInMonth = 31
End Function
'函数名称:CheckDate
'编写时间:2004-08-26
'最后更新:2004-08-26
'编写人:
'功能:检查日期格式是否合法,如果不合法,是哪一部分出错Public Function CheckDate(ByVal split As String, _
ByVal s As String) As Boolean
'split 为日期格式分隔符
's为传入的待判断的字符串 Dim dd As Date, i As Integer
Dim strDate As String
If Len(s) <> 8 Then
MsgBox "请输入8位数字!", vbExclamation + vbOKOnly
Exit Function
End If
For i = 1 To Len(s)
If Asc(Mid(s, i, 1)) > 57 Or Asc(Mid(s, i, 1)) < 48 Then
MsgBox "您输入的日期字符中的[" & Mid(s, i, 1) & "]不是数字!"
Exit Function
End If
Next
strDate = Mid(s, 1, 4) & split & Mid(s, 5, 2) & split & Mid(s, 7, 2)
If Not IsDate(strDate) Then
If CLng(Mid(s, 5, 2)) > 12 Then
MsgBox "月份不可大于12", vbExclamation + vbOKOnly
Exit Function
End If
dd = DateSerial(Mid(s, 1, 4), Mid(s, 5, 2), 1)
i = GetLastDateInMonth(dd)
If CLng(Mid(s, 7, 2)) > i Then
MsgBox "日期不可大于" & i, vbExclamation + vbOKOnly
Exit Function
End If
End If
CheckDate = TrueEnd Function(2)窗体引用时,例:
Private Sub temp_Click()Dim str As Stringstr = InputBox("请输入代表日期的数字")
CheckDate "/", trim(str)End Sub
---------------------------------------------------注:If Asc(Mid(s, i, 1)) > 57 Or Asc(Mid(s, i, 1)) < 48 Then ……
这里之所以不用IsNumeric函数,是因为IsNumeric(3e5)也为真.