Public Class Form1
創(chuàng)新互聯(lián)堅(jiān)持“要么做到,要么別承諾”的工作理念,服務(wù)領(lǐng)域包括:網(wǎng)站制作、成都網(wǎng)站設(shè)計(jì)、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣等服務(wù),滿足客戶于互聯(lián)網(wǎng)時代的任城網(wǎng)站設(shè)計(jì)、移動媒體設(shè)計(jì)的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡(luò)建設(shè)合作伙伴!
Private Function jc1(ByVal q)
Dim i%, p%
p = 1
For i = 1 To q Step 1
p = p * i
Next
Return p
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim m!, n!, info1$, info2, C!, title$
title = "組合數(shù)計(jì)算小能手"
info1 = "請輸入m的值"
info2 = "請輸入n的值"
m = Val(InputBox(info1, title))
n = Val(InputBox(info2, title))
C = jc1(m) / jc1(n) / jc1(m - n)
Label1.Text = "結(jié)果是" " " C
End Sub
點(diǎn)擊重新生成,應(yīng)該會在工具欄頂部出現(xiàn)的,也可以用代碼定義,但運(yùn)行前不會在界面出現(xiàn)
public withevent a as new rowmergeview
Function ByteToBin(m As Byte) As String ' 將字節(jié)型數(shù)據(jù)轉(zhuǎn)換成八位二進(jìn)制字符串
Dim c$
c$ = ""
Do While m 0
r = m Mod 2
m = m \ 2
c$ = r c$
Loop
c$ = Right("00000000" c$, 8)
ByteToBin = c$
End Function
Function Reverse(m As String) As String ' 將八位二進(jìn)制字符串顛倒順序
Dim i%, x$
x = ""
For i = 1 To 8
x = Mid(m, i, 1) x
Next i
Reverse = x
End Function
Function BinToByte(m As String) As Byte ' 將八位二進(jìn)制串轉(zhuǎn)換成十進(jìn)制
Dim x As String * 1, y%, z%
z = 0
For i = 1 To 8
x = Mid(m, i, 1)
y = x * 2 ^ (8 - i)
z = z + y
Next i
BinToByte = z
End Function
Private Sub Command1_Click()
Dim x As Byte, i%, fname$
fname = InputBox("請輸入要加密的文件名!注意加上路徑名:")
If Dir(fname) = "" Then
MsgBox "文件不存在!"
Exit Sub
End If
Open fname For Binary As #1 ' 以二進(jìn)制訪問模式打開待加密文件
For i = 1 To LOF(1) ' LOF函數(shù)是求文件長度的內(nèi)部函數(shù)
Get #1, i, x ' 取出第i個字節(jié)
x = BinToByte(Reverse(ByteToBin(x))) ' 這里調(diào)用了三個自定義函數(shù)
Put #1, i, x ' 將加密后的這個字節(jié)寫回到文件原位置
Next i
Close
MsgBox "完成!"
End Sub
退出:Unload Me
網(wǎng)上幫你找的,如果不符合你的要求,你可以再去網(wǎng)上在搜搜,有很多代碼的。
代碼已測試。
一、測試需要的INI文件。名稱為“setinfo.ini”,存放路徑為你解決方案里“Bin“文件夾的”Debug“文件夾里。
內(nèi)容:
[Location]
pnlTime.Location.X=787
pnlTime.Location.Y=0
[TopMost]
Top=True
二、操作INI文件的類。新建一個類,類中內(nèi)容為:
Public?Class?Class1
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?Int32,?_
ByVal?lpFileName?As?String?_
)?As?Int32
End?Class
三、界面代碼:
Imports?System.IO?'for?path
Public?Class?Form1
Private?Sub?Button1_Click(ByVal?sender?As?System.Object,?ByVal?e?As?System.EventArgs)?Handles?Button1.Click
getINI()
End?Sub
Private?Sub?getINI()
Dim?iniclass?As?New?Class1?'
Dim?myBf?As?String?'get?set_info?開辟存儲的內(nèi)存
myBf?=?New?String(CChar(""),?256)
Dim?myFN?As?String?'配置文件的文件路徑
myFN?=?Path.Combine(My.Application.Info.DirectoryPath,?"setinfo.ini")
Dim?myAN?As?String?'Application_NAME,也是Section名稱
myAN?=?Me.TextBox1.Text
Dim?myKN?As?String?'KEY_NAME,關(guān)鍵字名稱
myKN?=?Me.TextBox2.Text
Class1.GetPrivateProfileString(myAN,?myKN,?"",?myBf,?myBf.Length,?myFN)?'調(diào)用讀取INI文件的操作
TextBox3.Text?=?Microsoft.VisualBasic.Left(myBf,?InStr(myBf,?Chr(0))?-?1)?'截取有用部分,有必要
End?Sub
End?Class
四、測試截圖如下
用戶的自定義設(shè)置一般可以存在app.config文件中
在程序開啟后可以定義全局變量存儲這些配置,這樣就不必每次都讀配置文件了
你可以在你的項(xiàng)目屬性里面找到資源選項(xiàng),里面可以直接添加靜態(tài)的配置(此處添加的項(xiàng)會直接存儲在app.config中)
Private Function a%(b)
s = 1
For i = 1 To b
s = s * i
Next i
a = s
End Function
Private Sub Form_activate()
For i = 1 To 10
n = n + a(i)
Next i
Print n
End Sub