程序大致如下:
 
Private   Declare   Function   GetPrivateProfileString   Lib   "kernel32 "   _ 
        Alias   "GetPrivateProfileStringA "   _ 
        (ByVal   lpApplicationName   As   String,   _ 
          ByVal   lpKeyName   As   String,   _ 
          ByVal   lpDefault   As   String,   _ 
          ByVal   lpReturnedString   As   String,   _ 
          ByVal   nSize   As   Long,   _ 
          ByVal   lpFileName   As   String)   As   Long 
------------------------------------------------------------
Dim APPNAME As String,INIfileName  As String
Dim strRet As String
Dim iSize As LongAPPNAME = "MyApp"
INIfileName = App.Path & "\FILE.INI " 
strRet =space(255)       
KeyName =  "ValMax" 
iSize = GetPrivateProfileString("Application",KeyName," ",strRet,255,INIfileName) 
If iSize = 0 Then 
   strRet = "Not   Found " 
Else 
   strRet = Left(strRet   ,   iSize) 
End   If 
MsgBox(iSize & ", " & strRet) ====================================================
当ini文件中[ValMax]字段的数值较小时,如100,1000,程序运行正常;
但是当[ValMax]字段的数值较大时,如10000000,程序运行到此处将导致CPU满负荷,99%占用率哪位大侠给把把脉?感激不尽!^_^

解决方案 »

  1.   


    Option ExplicitPrivate 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 lpFileName As String) As Long
    '------------------------------------------------------------Private Sub Command1_Click()
    Dim APPNAME     As String, INIfileName      As String
    Dim strRet     As String
    Dim iSize     As Long
    Dim KeyName As StringAPPNAME = "MyApp"
    INIfileName = "d:\FILE.INI"
    strRet = Space(255)
    KeyName = "ValMax"
    iSize = GetPrivateProfileString("Application", KeyName, "   ", strRet, 255, INIfileName)
    If iSize = 0 Then
          strRet = "Not       Found   "
    Else
          strRet = Left(strRet, iSize)
    End If
    MsgBox (iSize & ",   " & strRet)End Sub这段程序在我这里没问题,我的ini是这样写的
    [Application]
    valmax=10000000000
      

  2.   

    没发现占用cpu过高的情况,我加了10000次循环也没见过。