Private Function get_phonenumber() As Integer
Dim i As Integer
Dim array_dll As Variant
Dim hh As New gssf.gssfcj
Dim fname0 As String
Dim fname1 As String
Dim msg_reg As Integer
Dim xx As String
get_phonenumber = -1
msg_reg = MsgBox("按”是“将重新拨号催款,按“否”将继续上次未完的拨号催款", vbInformation + vbYesNoCancel, "操作提示")
If msg_reg = vbCancel Then
readok_reg = False
Exit Function
End If
If msg_reg = vbYes Then
Stb1.SimpleText = "系统正从数据库获取数据。。。"
fname0 = App.Path + "\ini\No_dial.ini"
Call delete_file(fname0)
fname0 = App.Path + "\ini\dial_pass.ini"
Call delete_file(fname0)
Create_file (fname0)
fname0 = App.Path + "\ini\dial_unpass.ini"
Call delete_file(fname0)
Create_file (fname0)
fname0 = App.Path + "\ini\temp.ini"
Call delete_file(fname0)
Create_file (fname0)
array_dll = hh.jfcjrecord
If UBound(array_dll) = 0 Then
readok_reg = False
Stb1.SimpleText = "系统无法正从数据库获取数据!"
Sleep 2000
Exit Function
End If
ReDim pho_info(UBound(array_dll) - 1) As PHO
Stb1.SimpleText = "系统正在把数据写入文件" + fname0 + "。。。"
For i = 0 To UBound(array_dll) - 1
' array_dll(i, 3) = "4133002"
pho_info(i).index = i
pho_info(i).comp = array_dll(i, 0)
pho_info(i).linkman = array_dll(i, 1)
pho_info(i).serial = array_dll(i, 2)
pho_info(i).code = array_dll(i, 3)
pho_info(i).sum_month = array_dll(i, 4)
pho_info(i).sum_money = array_dll(i, 5)
pho_info(i).S_index = 0
pho_info(i).E_index = UBound(array_dll) - 1
' pho_number(i) = array_dll(i, 3)
Call ReadWriteINI("write", fname0, CStr(i), "欠款单位", array_dll(i, 0))
Call ReadWriteINI("write", fname0, CStr(i), "联系人", array_dll(i, 1))
Call ReadWriteINI("write", fname0, CStr(i), "收费号码", array_dll(i, 2))
Call ReadWriteINI("write", fname0, CStr(i), "联系电话", array_dll(i, 3))
Call ReadWriteINI("write", fname0, CStr(i), "拖欠月数", array_dll(i, 4))
Call ReadWriteINI("write", fname0, CStr(i), "拖欠款额", array_dll(i, 5))
Next i
readok_reg = True
Stb1.SimpleText = "数据接收完毕。"
Sleep 2000
get_phonenumber = 0
End If
If msg_reg = vbNo Then
fname1 = App.Path + "\ini\No_dial.ini"
If file_exist(fname1) = False Then
Stb1.SimpleText = "系统无法正从文件中获取数据!"
Sleep 2000
Exit Function
End If
Stb1.SimpleText = "系统正在从" + fname1 + "文件中读取数据。。。"
start_id = 0
end_id = 0
For i = 0 To 10000
xx = ReadWriteINI("get", fname1, CStr(i), "联系电话")
If xx <> "" Then
start_id = i
Exit For
End If
Next i
For i = 10000 To 0 Step -1
xx = ReadWriteINI("get", fname1, CStr(i), "联系电话")
If xx <> "" Then
end_id = i
Exit For
End If
Next i
If start_id = 0 And end_id = 0 And xx = "" Then
readok_reg = False
Stb1.SimpleText = "系统无法正从文件中获取数据!"
Sleep 2000
Exit Function
End If
Option Explicit
Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpString As Any, ByVal lpFileName As String) As Long
Declare Function WritePrivateProfileSection Lib "kernel32" Alias "WritePrivateProfileSectionA" (ByVal lpAppName As String, ByVal lpString As String, ByVal lpFileName As String) As Long
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
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
Function ReadWriteINI(Mode As String, FileName As String, tmpSecname As String, Optional tmpKeyname As String, Optional tmpKeyValue) As String
Dim tmpString As String
Dim secname As String
Dim keyname As String
Dim keyvalue As String
Dim anInt
Dim defaultkey As String
On Error GoTo ReadWriteINIError
If IsNull(Mode) Or Len(Mode) = 0 Then
ReadWriteINI = "MODE ERROR "
Exit Function
End If
If Len(FileName) = 0 Then
ReadWriteINI = "FileName ERROR "
Exit Function
End If
If IsNull(tmpSecname) Or Len(tmpSecname) = 0 Then
ReadWriteINI = "Secname ERROR "
Exit Function
End If
If IsNull(tmpKeyname) Or Len(tmpKeyname) = 0 Then
ReadWriteINI = "Keyname ERROR "
Exit Function
End If
' WRITE MODE
If UCase(Mode) = "WRITE" Then
If IsNull(tmpKeyValue) Or Len(tmpKeyValue) = 0 Then
ReadWriteINI = "ERROR KeyValue"
Exit Function
Else
secname = tmpSecname
keyname = tmpKeyname
keyvalue = tmpKeyValue
anInt = WritePrivateProfileString(secname, keyname, keyvalue, FileName)
End If
End If
' READ MODE
If UCase(Mode) = "GET" Then
secname = tmpSecname
keyname = tmpKeyname
defaultkey = "Failed"
keyvalue = String$(50, 32)
anInt = GetPrivateProfileString(secname, keyname, defaultkey, keyvalue, Len(keyvalue), FileName)
If Left(keyvalue, 6) <> "Failed" Then
tmpString = keyvalue
tmpString = RTrim(tmpString)
tmpString = Left(tmpString, Len(tmpString) - 1)
End If
ReadWriteINI = tmpString
End If
Exit Function
ReadWriteINIError:
MsgBox Error
Stop
End Function
Public Class INIManage
#Region "API函数声明"
'写INI文件API函数
Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpString As String, ByVal lpFileName As String) As Int32
'读INI文件API函数
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 Int32, ByVal lpFileName As String) As Int32
#End Region
#Region "写INI文件函数"
Public Function Write(ByVal INIPath As String, ByVal SectionName As String, ByVal KeyName As String, ByVal Value As String) As Boolean
Try
WritePrivateProfileString(SectionName, KeyName, Value, INIPath)
Return True
Catch
Return False
End Try
End Function
#End Region
#Region "读INI文件函数"
Public Function Read(ByVal INIPath As String, ByVal SectionName As String, ByVal KeyName As String) As String
Dim intRetVal As Int32
Dim strData, Value As String
strData = Space(1024)
Try
intRetVal = GetPrivateProfileString(SectionName, KeyName, Value, strData, strData.Length, INIPath)
If intRetVal > 0 Then
Read = strData.Substring(0, intRetVal)
Else
Read = ""
End If
Catch
Read = ""
End Try
End Function
#End Region
#Region "删INI文件函数"
'删除指定的键
Public Overloads Function Delete(ByVal INIPath As String, ByVal SectionName As String, ByVal KeyName As String) As Boolean
Try
WritePrivateProfileString(SectionName, KeyName, Nothing, INIPath)
Return True
Catch
Return False
End Try
End Function
'删除指定的节
Public Overloads Function Delete(ByVal INIPath As String, ByVal SectionName As String) As Boolean
Try
WritePrivateProfileString(SectionName, Nothing, Nothing, INIPath)
Return True
Catch
Return False
End Try
End Function
#End Region
End Class
Public Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpString As String, ByVal lpFileName As String) As Long
Public Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As StringBuilder, ByVal nSize As Int32, ByVal lpFileName As String) As Int32
Private Function IniKeySet(ByVal Section As String, ByVal Key As String, ByVal Value As String, ByVal filepath As String) As Long '对ini文件进行写操作
WritePrivateProfileString(Section, Key, Value, filepath)
End Function
Private Function IniKeyRead(ByVal Section As String, ByVal key As String, ByVal filepath As String) As String '对ini文件进行读操作
Dim buffer As New StringBuilder(255)
Dim i As Int32
i = GetPrivateProfileString(Section, key, "", buffer, 255, filepath)
Console.WriteLine(buffer.ToString())
Console.WriteLine(i)
Return (buffer.ToString())
End Function
Dim filepath As String '创建文件
filepath = "e:\\temp\\db.ini"
Dim sr As StreamWriter
sr = New StreamWriter(filepath)
sr.Close()
Me.IniKeySet("ODBC 32 bit Data Sources", "MS Access Database", "skywqlker", filepath) '创建ODBC 32 bit Data Sources section,以及下面的三个key
Me.IniKeySet("ODBC 32 bit Data Sources", "dBASE Files", "Microsoft dBase Driver (*.dbf) (32 bit)", filepath)
Me.IniKeySet("ODBC 32 bit Data Sources", "Excel Files", "Microsoft Excel Driver (*.xls) (32 bit)", filepath)
Me.TextBox1.Text = Me.IniKeyRead("ODBC 32 bit Data Sources", "dBASE Files", "e:\\temp\\db.ini") '实现对ini的key的读取。