ini文件vb点虐 INI文件是什么

VB点虐 2005中到底怎么读取ini文件

用API吧

创新互联建站专注为客户提供全方位的互联网综合服务,包含不限于成都网站建设、网站建设、长白网络推广、微信平台小程序开发、长白网络营销、长白企业策划、长白品牌公关、搜索引擎seo、人物专访、企业宣传片、企业代运营等,从售前售中售后,我们都将竭诚为您服务,您的肯定,是我们最大的嘉奖;创新互联建站为所有大学生创业者提供长白建站搭建服务,24小时服务热线:18982081108,官方网址:www.cdcxhl.com

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 Int32, ByVal lpFileName As String) As Int32

Private 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

'读

Public Function GetINI(ByVal Section As String, ByVal AppName As String, ByVal lpDefault As String, ByVal FileName As String) As String

Dim Str As String = LSet(Str, 256)

GetPrivateProfileString(Section, AppName, lpDefault, Str, Len(Str), FileName)

Return Microsoft.VisualBasic.Left(Str, InStr(Str, Chr(0)) - 1)

End Function

'写

Public Function WriteINI(ByVal Section As String, ByVal AppName As String, ByVal WriteString As String, ByVal FileName As String) As Long

WriteINI = WritePrivateProfileString(Section, AppName, WriteString, FileName)

End Function

其中,Section是像[ip]那样的(填里面的就可以了),AppName是“=”前面的项名称,lpDefault是如果没有可用的值,就返回lpDefault,FileName是文件名,WriteString是要写入的值

你所希望的:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

MsgBox(GetINI("ip", "user_id", "", "D:\DataBase.ini"))

'返回sa

End Sub

VB.NET怎么删除INI文件里的一个字段或键值?

1,对于INI文件,可以当做像TXT文件一样来进行读取和写入。

2,先把整个文件度出来,然后找到相应行删除(抛弃)以后,再重新写入文件。

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim MyStr As String = ""

Dim AllStr As String = ""

'获取一个可用的文件号

Dim MyFileNum As Integer = FreeFile()

'打开指定的文件,进行读取操作

FileOpen(MyFileNum, "C:\My.ini", OpenMode.Input)

Do While Not EOF(MyFileNum)

'读取一行

MyStr = LineInput(MyFileNum)

If MyStr  "b=2" Then

If AllStr = "" Then

AllStr = AllStr  MyStr

Else

AllStr = AllStr  vbCrLf  MyStr

End If

End If

Loop

FileClose(MyFileNum)   '关闭文件

'写文件

Dim MyStream As New System.IO.FileStream("C:\My.ini", IO.FileMode.Create)

Dim MyWriter As New System.IO.StreamWriter(MyStream, System.Text.Encoding.UTF8)

MyWriter.WriteLine(AllStr)

MyWriter.Flush()

MyWriter.Close()

MyStream.Close()

End Sub

End Class

vb点虐 如何读取ini文件定义的ForeColor颜色值

你好,我不知道你是用什么方法保存的,不过点虐 里的color有一个方法是Color.FromArgb 你可以这么做,dim

c

as

color=richtextbox1.ForeColor dim

colorstring

as

string=c.ToArgb().ToString

colorstring就是颜色的值(字符串)再把colorstring保存到ini文件加载颜色的时候,从ini里读取colorstring 具体是:dim

RtextColor

as

color=Color.FromArgb(cint(colorstring))richtextbox1.ForeColor

=RtextColor

vb点虐 读写ini文件问题

以下是我的办法:OK!

Public 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 Integer, ByVal lpFileName As String) As Integer

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 Integer

写:

WritePrivateProfileString("存储", "账号", textbox1, Application.StartupPath "\song.ini")

读:

dim s as string

s = string(255," ")

GetPrivateProfileString("存储", "账号", s, s.Length, Application.StartupPath + "\song.ini")

textbox1 =s


网站题目:ini文件vb点虐 INI文件是什么
链接分享:http://myzitong.com/article/ddecohe.html