把要显示的字符串放到一个.ini的配置文件里,然后用GetProfile这个函数去读
比如:
// Name = "宋体"
-> Name = GetProfile("c:\aa.ini", "font", "font1")
Function GetProfile(strFileName As String, strSection As String, strName As String) As String
strSectionTemp = ""
strNameTemp = ""
strreturn = ""
On Error GoTo ErrReadFile
Open strFileName For Input As #1
'find node
Do While Not EOF(1)
strCharA = Input(1, #1)
If strCharA = "[" Then
Do While Not EOF(1)
strCharB = Input(1, #1)
If strCharB = "]" Then Exit Do
strSectionTemp = strSectionTemp & strCharB
Loop
End If
If strSectionTemp = strSection Then
strCharA = Input(2, #1)
Exit Do
Else
strSectionTemp = ""
End If
Loop
On Error GoTo ErrSrchSection
aa:
'find field
strNameTemp = ""
Do While Not EOF(1)
strCharA = Input(1, #1)
If strCharA <> "=" Then
strNameTemp = strNameTemp & strCharA 'gained name
Else
Exit Do
End If
Loop
If strNameTemp = strName Then
Line Input #1, strreturn
Else
Line Input #1, strreturn
GoTo aa
End If
Close #1
GetProfile = strreturn
Exit Function
ErrReadFile:
Dim inrRet As Integer
intret = MsgBox("read 'test.ini' failed!" & Chr(10) & "a file is missing or invalid", vbAbortRetryIgnore + vbExclamation, "error")
Select Case intret
Case vbAbort
GetProfile = ""
Close #1
End
Exit Function
Case vbRetry
Resume
Case vbIgnore
Resume Next
End Select
ErrSrchSection:
MsgBox "no node in 'ini' file", vbOKOnly + vbExclamation, "error"
GetProfile = ""
Close #1
End
End Function