format后面的字符串消失了
本帖最后由 diaryfly 于 2013-08-22 15:29:02 编辑 将几个字符串(str1-str6)合并输出时碰到问题:
Text1.text = str1 & "" & str2 & "" & str3 & "" & str4 & "-" & str5 & "" & Format(time, "hh:mm") & "-" & "" & str6
文本只能输出到str5以前的字符串。format后面的就消失了。
如果换成:
Text2.text = "str1" & "" & "str2" & "" & "str3" & "" & "str4" & "-" & "str5" & "" & Format(time, "hh:mm") & "" & "str6"
又没有问题。求大侠指导。 format? 字符串 消失
[解决办法]
str1至str5 分别什么?我试了一下,我可以正常.
Private Sub Form_Load()
Dim str1
Dim str2
Dim str3
Dim str4
Dim str5
Dim Str6
str1 = 6
str2 = 7
str3 = 8
str4 = 9
str5 = 10
Str6 = 11
Text1.Text = str1 & "" & str2 & "" & str3 & "" & str4 & "-" & str5 & "" & Format(Time, "hh:mm") & "-" & "" & Str6
End Sub
Text1.Text = "abc" & Chr(0) & "def" '只显示 abc'
Private Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal pFileName As String) As Long
Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFilename As String) As Long
Private Declare Function GetPrivateProfileSection Lib "kernel32" Alias "GetPrivateProfileSectionA" (ByVal lpAppName As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFilename As String) As Long
Private Sub Form_Load()
Dim s As String, str As String, str1 As String, str2 As String, str3 As String, str4 As String, str5 As String, str6 As String
Dim i As Integer, j As Integer
On Error Resume Next
s = "F:\test.INI"
str = Space(50)
str0 = i
str1 = GetIniStr(s, "test1", "1")
str2 = GetIniStr(s, "test1", "2")
str3 = GetIniStr(s, "test1", "3")
str4 = GetIniStr(s, "test1", "4")
str5 = GetIniStr(s, "test1", "5")
str6 = GetIniStr(s, "test1", "6")
Text1.Text = str1 & "" & str2 & "" & str3 & "" & str4 & "-" & str5 & "" & Format(Time, "hh:ss") & "" & str6
End Sub
'*************************************
'目的:写入数据至Ini文件
'输入: FileName 文件名
' AppName 项目名
' In_Key 键名
' In_Data 键名上的数值
'返回: 写入成功 True
' 写入失败 False
'*************************************
Public Function WriteIniStr(ByVal FileName As String, ByVal AppName As String, ByVal In_Key As String, ByVal In_Data As String) As Boolean
On Error GoTo WriteIniStrErr
WriteIniStr = True
If VBA.Trim(In_Data) = "" Or VBA.Trim(In_Key) = "" Or VBA.Trim(AppName) = "" Then
GoTo WriteIniStrErr
Else
WritePrivateProfileString AppName, In_Key, In_Data, FileName
End If
Exit Function
WriteIniStrErr:
Err.Clear
WriteIniStr = False
End Function
'*************************************
'目的:从Ini文件中读取数据
'输入: FileName 文件名
' AppName 项目名
' In_Key 键名
'返回: 取得给定键名上的数据
'*************************************
Public Function GetIniStr(ByVal FileName As String, ByVal AppName As String, ByVal In_Key As String) As String
On Error GoTo GetIniStrErr
If VBA.Trim(In_Key) = "" Then
GoTo GetIniStrErr
End If
Dim GetStr As String
GetStr = VBA.String(128, 0)
GetPrivateProfileString AppName, In_Key, "", GetStr, 256, FileName
GetStr = VBA.Replace(GetStr, VBA.Chr(0), "")
If GetStr = "" Then
GoTo GetIniStrErr
Else
GetIniStr = GetStr
GetStr = ""
End If
Exit Function
GetIniStrErr:
Err.Clear
GetIniStr = ""
GetStr = ""
End Function