大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
Public Class Form1
创新互联坚持“要么做到,要么别承诺”的工作理念,服务领域包括:网站制作、成都网站设计、企业官网、英文网站、手机端网站、网站推广等服务,满足客户于互联网时代的任城网站设计、移动媒体设计的需求,帮助企业找到有效的互联网解决方案。努力成为您成熟可靠的网络建设合作伙伴!
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 = "组合数计算小能手"
info1 = "请输入m的值"
info2 = "请输入n的值"
m = Val(InputBox(info1, title))
n = Val(InputBox(info2, title))
C = jc1(m) / jc1(n) / jc1(m - n)
Label1.Text = "结果是" " " C
End Sub
点击重新生成,应该会在工具栏顶部出现的,也可以用代码定义,但运行前不会在界面出现
public withevent a as new rowmergeview
Function ByteToBin(m As Byte) As String ' 将字节型数据转换成八位二进制字符串
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 ' 将八位二进制字符串颠倒顺序
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 ' 将八位二进制串转换成十进制
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 ' 以二进制访问模式打开待加密文件
For i = 1 To LOF(1) ' LOF函数是求文件长度的内部函数
Get #1, i, x ' 取出第i个字节
x = BinToByte(Reverse(ByteToBin(x))) ' 这里调用了三个自定义函数
Put #1, i, x ' 将加密后的这个字节写回到文件原位置
Next i
Close
MsgBox "完成!"
End Sub
退出:Unload Me
网上帮你找的,如果不符合你的要求,你可以再去网上在搜搜,有很多代码的。
代码已测试。
一、测试需要的INI文件。名称为“setinfo.ini”,存放路径为你解决方案里“Bin“文件夹的”Debug“文件夹里。
内容:
[Location]
pnlTime.Location.X=787
pnlTime.Location.Y=0
[TopMost]
Top=True
二、操作INI文件的类。新建一个类,类中内容为:
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 开辟存储的内存
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,关键字名称
myKN = Me.TextBox2.Text
Class1.GetPrivateProfileString(myAN, myKN, "", myBf, myBf.Length, myFN) '调用读取INI文件的操作
TextBox3.Text = Microsoft.VisualBasic.Left(myBf, InStr(myBf, Chr(0)) - 1) '截取有用部分,有必要
End Sub
End Class
四、测试截图如下
用户的自定义设置一般可以存在app.config文件中
在程序开启后可以定义全局变量存储这些配置,这样就不必每次都读配置文件了
你可以在你的项目属性里面找到资源选项,里面可以直接添加静态的配置(此处添加的项会直接存储在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