⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.frm

📁 vbAPIini.rar
💻 FRM
字号:
VERSION 5.00
Begin VB.Form Form1 
   ClientHeight    =   3090
   ClientLeft      =   60
   ClientTop       =   450
   ClientWidth     =   4680
   LinkTopic       =   "Form1"
   ScaleHeight     =   3090
   ScaleWidth      =   4680
   StartUpPosition =   3  '窗口缺省
   Begin VB.CommandButton Command2 
      Caption         =   "Command2"
      Height          =   1215
      Left            =   2520
      TabIndex        =   1
      Top             =   720
      Width           =   1695
   End
   Begin VB.CommandButton Command1 
      Caption         =   "Command1"
      Height          =   1215
      Left            =   360
      TabIndex        =   0
      Top             =   720
      Width           =   1695
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'利用API函数,VB可以方便的读取和改写INI文件。
    '读文件用到GetPrivateProfileString,写文件需要用到WritePrivateProfileString。
    '在窗体放置两个命令按钮Command1与Command2,分别用来执行写操作与读操作。
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 lpFileName 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 Sub Command1_Click()
Dim S As Long
Dim U As Long
Dim PW As Long
Dim Server As String
Dim User As String
Dim Password As String
Server = "NO.1"
User = "NO.2"
Password = "NO.3"
'写信息
'修改SYSTEM.INI文件中TIP字段中START的值为当前系统时间
'如果该文件不存在会自动建立,当函数返回值为0时说明修改不成功
S = WritePrivateProfileString("GetServer", "Server", Server, App.Path & "\system.ini")
U = WritePrivateProfileString("GetServer", "User", User, App.Path & "\system.ini")
PW = WritePrivateProfileString("GetServer", "Password", Password, App.Path & "\system.ini")
If S = 0 Or U = 0 Or PW = 0 Then MsgBox ("写文件时出错")
End Sub


Private Sub Command2_Click()
Dim T1 As String
Dim T2 As String
Dim T3 As String
'读取信息
T1 = Space$(1000) '事先定义读取值的字串宽度
T2 = Space$(1000)
T3 = Space$(1000)
'读取SYSTEM.INI文件中TIP字段中START的值并打印出来
'当函数返回值为0时说明读取数据出错
S = GetPrivateProfileString("GetServer", "Server", "", T1, 1000, App.Path & "\system.ini")
U = GetPrivateProfileString("GetServer", "User", "", T2, 1000, App.Path & "\system.ini")
PW = GetPrivateProfileString("GetServer", "Password", "", T3, 1000, App.Path & "\system.ini")
If S = 0 Or U = 0 Or PW = 0 Then MsgBox "找不到所需字段": Exit Sub
MsgBox S & vbCrLf & U & vbCrLf & PW
MsgBox Left$(T1, Len(Trim$(T1)) - 1) & "Q"
MsgBox Left$(T2, Len(Trim$(T2)) - 1) & "Q"
MsgBox Left$(T3, Len(Trim$(T3)) - 1) & "Q"
'Print Left$(T1, Len(Trim$(T1)) - 1)



End Sub

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -