用VB编辑程序应该怎么写
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了用VB编辑程序应该怎么写相关的知识,希望对你有一定的参考价值。
条件:X A B C E D F 都是自然数 数字互不相等 要求X=A+B+C+D+E+F输出 ABCDEF放在一个LIST就好
有9个控件就可以了 7个TXET 一个LIST 一个Command 在TEXT1中任意输入一个数字LIST就会出现所有可能满足条件的6个自然数 ABCDEF都不大于33 其他的6个TEXT可以任意输入做条件
最好数字可以选择复制出去 个人感觉还是1楼的精实在
Dim a As Integer
Dim b As Integer
Dim c As Integer
Dim e As Integer
Dim f As Integer
Dim x As Integer
x = Val(Text1)
List1.Clear
For a = IIf(Val(Text2) = 0, 1, Val(Text2)) To IIf(Val(Text2) = 0, 28, Val(Text2))
For b = IIf(Val(Text3) = 0, a + 1, Val(Text3)) To IIf(Val(Text3) = 0, 29, Val(Text3))
For c = IIf(Val(Text4) = 0, b + 1, Val(Text4)) To IIf(Val(Text4) = 0, 30, Val(Text4))
For d = IIf(Val(Text5) = 0, c + 1, Val(Text5)) To IIf(Val(Text5) = 0, 31, Val(Text5))
For e = IIf(Val(Text6) = 0, d + 1, Val(Text6)) To IIf(Val(Text6) = 0, 32, Val(Text6))
For f = IIf(Val(Text7) = 0, e + 1, Val(Text7)) To IIf(Val(Text7) = 0, 33, Val(Text7))
DoEvents
If a + b + c + d + e + f = x Then List1.AddItem Str(a) + Str(b) + Str(c) + Str(d) + Str(e) + Str(f)
Next f
Next e
Next d
Next c
Next b
Next a
End Sub
Private Sub Command2_Click()
Dim Tmp As String
Clipboard.Clear
For i = 0 To List1.ListCount - 1
Tmp = Tmp + List1.List(i) + vbCrLf
Next
Clipboard.SetText Tmp
End Sub
Private Sub List1_DblClick()
Clipboard.Clear
Clipboard.SetText List1.Text
End Sub 参考技术A 拼谁代码短,精简是王道
Dim a, b, c, e, f, x As Integer
x = Text1.Text
List1.Clear
For a = 1 To 33
For b = a + 1 To 33
For c = b + 1 To 33
For d = c + 1 To 33
For e = d + 1 To 33
For f = e + 1 To 33
If a + b + c + d + e + f = x Then List1.AddItem a & b & c & d & e & f
Next
Next
Next
Next
Next
Next 参考技术B 如果上面两位选择一个的话,还是选择 ruo_qi_yu 好吧,清一点
二楼的精简到那里去?
Dim a, b, c, e, f, x As Integer VB这样定义真实上是没效。 参考技术C Private Sub Command1_Click() '要排除六个数出现相同的数字
Dim a%, b%, c%, d%, e%, f%, x%
x = Val(Text1.Text)
List1.Clear
Me.Caption = "正在生成中,请稍候..."
For a = 1 To 28
For b = a + 1 To 29
For c = b + 1 To 30
For d = c + 1 To 31
For e = d + 1 To 32
For f = e + 1 To 33
DoEvents
If (a + b + c + d + e + f) = x Then List1.AddItem Str(a) + Str(b) + Str(c) + Str(d) + Str(e) + Str(f)
Next f
Next e
Next d
Next c
Next b
Next a
If List1.ListCount > 0 Then
Me.Caption = "已生成结束,请点击列表框,复制其中所有数据..."
Else
Me.Caption = "已生成结束,没有符合的数据..."
End If
MsgBox "已生成结束!"
End Sub
Private Sub List1_Click() '单击生成数据的列表框,即可复制列表框中所有的数据,粘贴到别的地方去
Dim temp As String, i As Integer
If List1.ListCount > 0 Then
For i = 0 To List1.ListCount - 1
temp = temp & List1.List(i) & vbCrLf
Next i
Clipboard.Clear
Clipboard.SetText temp
End If
End Sub 参考技术D 怎么感觉像是双色球的彩票投注呀?
定义一个文本框数组txtNum(6)然后里面的数随机出现,且不重复,没有顺序之分,按从小到大排序。
Sub AutoSel()
Dim I, J As Integer
Dim Temp As Integer
Dim A(6) As Integer
Dim Z0 As String
Dim Z1, Z2, Z3 As Integer
'随机产生6个不大于33的自然数
L0:
Randomize
A(0) = Int(Rnd * 17)
If A(0) = 0 Then GoTo L0 Else txtNum(0).Text = A(0)
L1:
Randomize
A(1) = Int(Rnd * 33)
If A(1) = 0 Or A(1) = A(0) Then GoTo L1 Else txtNum(1).Text = A(1)
L2:
Randomize
A(2) = Int(Rnd * 33)
If A(2) = 0 Or A(2) = A(1) Or A(2) = A(0) Then GoTo L2 Else txtNum(2).Text = A(2)
L3:
Randomize
A(3) = Int(Rnd * 33)
If A(3) = 0 Or A(3) = A(2) Or A(3) = A(1) Or A(3) = A(0) Then GoTo L3 Else txtNum(3).Text = A(3)
L4:
Randomize
A(4) = Int(Rnd * 33)
If A(4) = 0 Or A(4) = A(3) Or A(4) = A(2) Or A(4) = A(1) Or A(4) = A(0) Then GoTo L4 Else txtNum(4).Text = A(4)
L5:
Randomize
A(5) = Int(Rnd * 33)
If A(5) = 0 Or A(5) = A(4) Or A(5) = A(3) Or A(5) = A(2) Or A(5) = A(1) Or A(5) = A(0) Then GoTo L5 Else txtNum(5).Text = A(5)
L6:
Randomize
A(6) = Int(Rnd * 33)
If A(6) = 0 Or A(6) = A(5) Or A(6) = A(4) Or A(6) = A(3) Or A(6) = A(2) Or A(6) = A(1) Or A(6) = A(0) Then GoTo L6 Else txtNum(6).Text = A(6)
'排序这6个数
For I = 1 To 6
For J = I + 1 To 6
If A(I) > A(J) Then Temp = A(I): A(I) = A(J): A(J) = Temp
Next J
Next I
txtNum(0).Text = Format(A(0), "0#")
For I = 1 To 6
txtNum(I).Text = Format(A(I), "0#")
Select Case A(I)
Case Is <= 11
Z1 = Z1 + 1
Case Is <= 22
Z2 = Z2 + 1
Case Is <= 33
Z3 = Z3 + 1
Case Else
End Select
Next I
'显示单双号
If A(0) Mod 2 = 0 Then Z0 = "双号" Else Z0 = "单号"
'统计大中小号个数
lblR1.Caption = Str(Z1) & "小" & Str(Z2) & "中" & Str(Z3) & "大" & "+" & Z0
End Sub
vb怎么做个vb编译器?
就是让vb能解释vb工程文件(.vbp)
软件能把vb源文件给编译出来
在调用之前已经在临时目录下生成了一堆看不懂的东西。
但你可以调用VB主程序的命令行来生成程序,如你要生成的程序在D盘根目录,工程文件为
1.vbp那你可以在CMD里打VB6.exe /make D:\1.vbp
具体的可以参照VB6.exe /?
附:
VB的编译过程大致如下,当我们在编辑环境中编写完代码后,VB调用C2将所有的模块(包括CLASS)编译成OBJ文件(能够为机器语言识别的代码)。一下是C2的一些编译参数说明(E文):
- the the name of the prefixed one used for the names of the rowscontaining ' precompilato', one
risen of intermediate tails (from which name of the switch) temporary; these rows are 5 and finish withi suffissi GL, SY, FORMER, IN and DB; they contained are not documented
- f the name of the rows to compile
- W3 warning level 3, level of ' attenzione' dedicating to i warnings
- Gy it qualifies the connection to level of function (function-level linking)
- G5 optimization for the Pentium
- Gs4096 it allows not to insert the code for the control of stack (stack probe) if a function does not
use more than 4096 byte of stack
- dos not documented
- Z1 it removes the name of the bookcase of default from the rows.OBJ
- Fofileobj the name of rows OBJ to generate (rows output)
- Qifdiv it puts in action the corrections for the bug of the division of the Pentium (FDIV bug)
- MILILITER it creates rows eseguibile single-threaded
- basic it indicates the compiler C2 the fact that the compilation it happens for a plan basic
C2完成编译后,VB会调用LINK.EXE将所有的OBJ文件连接成EXE文件,完成编译过程。下面是一段命令行演示如何调用LINK.EXE:
LINK C:\Test\Form1.obj C:\Test\Modulo1.obj C:\Test\Progetto1.obj C:\Programmi\Microsoft Visual Studio\VB98\VBAEXE6.lib /ENTRY:__ vbaS /OUT:C:\Test\Progetto1.exe /BASE:0x400000 /SUBSYSTEM:WINDOWS, 4.0 /VERSION:1.0 /DEBUG /DEBUGTYPE:CV /INCREMENTAL:NOT /OPT:REF/MERGE:.rdata =.text /IGNORE:4078
对于我们来说这些参数没有什么意义,用默认的就行了。这段命令行中并没有包括输出函数,如果我们希望输出函数,可以定义一个.def文件,按照格式加入要输出的函数列表,然后在命令行后面加上 “/DEF: 文件名”(当然也可以直接加/ EXPORTS参数),再调用命令行编译,用的denpendency工具查看你就会发现你要输出的函数了。
Def文件格式的定义:
LIBRARY 程序名称
DESCRIPTION "MyDLL - (C) Antonio Giuliana, 2004"
EXPORTS
函数名= ?函数名@函数所在模块名@@AAGXXZ
…
例:
LIBRARY MyDLL
DESCRIPTION "MyDLL - (C) Antonio Giuliana, 2004"
EXPORTS
DllRegisterServer= ?DllRegisterServer@SymExp@@AAGXXZ
DllUnregisterServer= ?DllUnregisterServer@SymExp@@AAGXXZ
注意:函数名和模块名是区分大小写的
我先用Vb编一个截取C2、LINK命令的程序:
C2:
Private Sub Form_Load()
f = UCase$(Left$(Command$, 256))
Open "E:\C2.txt" For Output As #1
Print #1, f
Close
End
End Sub
LINK:
Private Sub Form_Load()
f = UCase$(Left$(Command$, 256))
Open "E:\C2.txt" For Output As #1
Print #1, f
Close
End
End Sub
生成EXE后把VB98下的c2与LINK剪切到别处,在用这两个程序代替。运行VB6.exe,随意打开一个工程,点文件菜单,生成EXE。
不久我编的两个程序就送给我梦寐以求的文件:
E:\C2.txt
-IL "C:\DOCUME~1\ADMINI~1\LOCALS~1\TEMP\VB381884" -F "E:\PROGRAM FILES\MICROSOFT VISUAL STUDIO\VB98\新建文件夹 (2)\FORM1.FRM" -W 3 -GY -G5 -GS4096 -DOS -ZL -FO"E:\PROGRAM FILES\MICROSOFT VISUAL STUDIO\FORM1.OBJ" -QIFDIV -ML -BASIC
E:\LINK.txt
"E:\PROGRAM FILES\MICROSOFT VISUAL STUDIO\FORM1.OBJ" "E:\PROGRAM FILES\MICROSOFT VISUAL STUDIO\LINK.OBJ" "E:\PROGRAM FILES\MICROSOFT VISUAL STUDIO\VB98\VBAEXE6.LIB" /ENTRY:__VBAS /OUT:"E:\PROGRAM FILES\MICROSOFT VISUAL STUDIO\LINK.EXE" /BASE:0X400000 /SUBS
这两个TXT就是VB送给c2以及LINK的命令。
详细解读如下:
C2.txt
-IL "C:\DOCUME~1\ADMINI~1\LOCALS~1\TEMP\VB381884" -F "E:\PROGRAM FILES\MICROSOFT VISUAL STUDIO\VB98\新建文件夹 (2)\FORM1.FRM"是c2准备处理的两个文件。 -W 3 -GY -G5 -GS4096 -DOS -ZL是c2生成OBJ的格式,后边则是OBJ文件的地址。
LINK.txt
"E:\PROGRAM FILES\MICROSOFT VISUAL STUDIO\FORM1.OBJ" "E:\PROGRAM FILES\MICROSOFT VISUAL STUDIO\LINK.OBJ"是源文件。"E:\PROGRAM FILES\MICROSOFT VISUAL STUDIO\VB98\VBAEXE6.LIB"是转换库。后面是EXE文件地址及格式 参考技术A 。。。
先运行C1.EXE
再运行LINK.EXE 参考技术B 去看雪论坛看看吧 参考技术C 没明白你的意思,说详细点。
以上是关于用VB编辑程序应该怎么写的主要内容,如果未能解决你的问题,请参考以下文章