沟通空间吧 关注:9贴子:202
  • 3回复贴,共1

用VB6.0编写电脑抽奖程序

只看楼主收藏回复


源程序及注释如下:
'窗体源程序
Option Explicit
     Dim m_strNameArray() As MyName
     Dim m_bIsStart As Boolean
     Dim m_nNameIndex As Integer
     Dim MAX_INDEX As Integer
     Dim m_nSelectNum As Integer
      '被选定数
     Dim nScrollStep As Integer
     Dim nScrollWidth As Integer
     Dim bScrollState As Boolean
     Dim nEnableSecond As Integer
     Dim m_strTitle As String
     Dim m_strAppTitle As String
     Dim m_strScrollTitleLeft As String
     Dim m_strScrollTitleRight As String
Private Sub Command_Start_Stop_Click()
     If m_bIsStart = True Then
       '按停止钮
       m_bIsStart = False
       Command_Start_Stop.Caption =
       “开始"
       Label_FlashName.Visible = True
       Timer_FlashName.Enabled = True
       Timer_ScrollName.Enabled = False
       Label_FlashName =
         m_strNameArray(m_nNameIndex).strName + “中奖了!"
       m_strNameArray(m_nNameIndex).bIsSelect = True
       m_nSelectNum = m_nSelectNum + 1
       Dim Temp As MyName
       Temp =m_strNameArray(MAX_INDEX)
       m_str Name Array(MAX-INDEX) = m_strNameArray(m_nNameIndex)
       m_strNameArray(m_nNameIndex) =Temp
       MAX_INDEX = MAX_INDEX - 1
       If MAX_INDEX = 0 Then
         MsgBox “非常感谢您使用本软件"
       End If
     Else '按开始钮
       m_bIsStart = True
       Command_Start_Stop.Caption = “停止"
       Command_Start_Stop.Enabled = False
       Timer_ScrollName.Enabled = True
       Timer_FlashName.Enabled = False
       Label_FlashName.Caption = “"
     End If
End Sub
Private Sub Form_Load()
     Form_Bouns.ScaleMode = 3
     m_nNameIndex = 0
     m_bIsStart = False
     Timer_ScrollName.Enabled = True
     Timer_ScrollTitle.Enabled = True



1楼2010-01-07 16:25回复
         Label_FlashName.Visible = False
         Label_ScrollName.Caption = “"
         nEnableSecond = 0
         '定义起始秒数
         ReDimNameArray
         '获得文本中的名字和打乱名字顺序
         nScrollStep = 5 '设定滚动字的步长
         nScrollWidth = Label_Congruation.Left
         '设定title的移动宽度
         bScrollState = False
         '设定缺省的开始滚动方向为向左
         m_nSelectNum = 0
         '初始化被选定数为0
         Init
         '初始化本程序的界面
    End Sub
    Private Sub Timer_FlashName_Timer() '闪动中奖者姓名
         If Label_FlashName.Visible = True Then
           Label_FlashName.Visible = False
         Else
           Label_FlashName.Visible = True
         End If
    End Sub
    Private Sub Timer_ScrollName_Timer() '滚动出现名字
         If m_bIsStart = True Then
           If m_nNameIndex >= MAX_INDEX Then
             m_nNameIndex = 0
           End If
           m_nNameIndex =m_nNameIndex + 1
           If m_strNameArray(m_nNameIndex).bIsSelect = True Then
             If m_nNameIndex < MAX-INDEX Then
               m_nNameIndex =
               m_nNameIndex + 1
             Else
               m_nNameIndex = 0
             End If
           End If
           Label_ScrollName.Caption = m_str
           NameArray(m_nNameIndex).strName
           'End If
         End If
    End Sub
        
    Private Sub Timer_ScrollTitle_Timer() '滚动“恭喜发财"字样
         If bScrollState = False Then '向左滚
           nScrollStep = 10
           Label_Congruation.Caption = m_strScrollTitleLeft
           If nScrollWidth > 0 Then
             nScrollWidth =
             nScrollWidth - nScrollStep
           Else
             bScrollState = True
           End If
         Else '向右滚
           nScrollStep = -10
    


    2楼2010-01-07 16:25
    回复
      广告
      立即查看
             Label_Congruation.Caption =
             m_strScrollTitleRight
             If nScrollWidth < Form_Bouns.ScaleWidth -
                     Label_Congruation.Width Then
               nScrollWidth =
               nScrollWidth - nScrollStep
             Else
               bScrollState = False
             End If
           End If
           Label_Congruation.Left = nScrollWidth
           '以下为8秒钟内使“停止"按钮有效
           If nEnableSecond <= 49 Then
             If m_bIsStart = True Then
               nEnableSecond =nEnableSecond + 1
             End If
           Else
             If m_bIsStart = True Then
               Command_Start_Stop.Enabled = True
               nEnableSecond = 0
             End If
           End If
      End Sub
           '动态定义数组
      Private Sub ReDimNameArray()
           Dim nMaxIndex As Integer
           Dim strMaxIndex As String
           Dim nIndex As Integer
           Dim bIsBegin As Boolean
           bIsBegin = False
           nIndex = 0
           Open App.Path + “\name.txt" For Input As #1 '读文件
           Do Until EOF(1)
             If bIsBegin = False Then
               Line Input #1, strMaxIndex
               nMaxIndex = Val(strMaxIndex)
               MAX_INDEX = nMaxIndex - 1
               ReDim m_strNameArray(0 To nMaxIndex - 1)
               bIsBegin = True
             Else
               Line Input #1, m_strNameArray(nIndex).strName
               m_strNameArray(nIndex).bIsSelect = False
               nIndex = nIndex + 1
             End If
           Loop
           '以下为打乱人员顺序10次
           Dim i As Integer
           Dim j As Integer
           Dim Temp As String
           Dim nRandomNum As Integer
           For j = 0 To 10
             For i = 0 To nMaxIndex - 1
      


      3楼2010-01-07 16:25
      回复
                 nRandomNum = ((nMaxIndex - 1) × Rnd) '利用Rnd函数
                 Temp = m_strNameArray(i).strName
               m_strNameArray(i).strName = m_strNameArray(nRandomNum).strName
                 m_strNameArray(nRandomNum).strName = Temp
               Next i
             Next j
             End Sub
            
        Private Sub Init() '读取INI文件
             Dim X As Long
             Dim lpFileName
             Dim Temp As String × 50
             lpFileName = App.Path + “\Sortition.ini"
             X = GetPrivateProfileString(“SYSTEM",“AppTitle",“抽奖程序", Temp, Len(Temp), lpFileName)
             m_strAppTitle = Trim(Temp)
             Temp =“"
             X = GetPrivateProfileString(“SYSTEM", "Title", "欢迎使用抽奖程序", Temp, Len(Temp), lpFileName)
             m_strTitle = Trim(Temp)
             Temp = “"
             X = GetPrivateProfileString(“SYSTEM",“ScrollTitleRight", “恭喜发财!!!", Temp, Len(Temp), lpFileName)
             m_strScrollTitleRight = Trim(Temp)
             X = GetPrivateProfileString(“SYSTEM",“ScrollTitleLeft", “龙年大发!!!", Temp, Len(Temp), lpFileName)
             m_strScrollTitleLeft = Trim(Temp)
             Form_Bouns.Caption = m_strAppTitle
             Label_CompanyTitle.Caption = m_strTitle
             End Sub
             模块源程序:
             '用于读取ini文件的API函数
             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 Long, ByVal lpFileName As String) As Long
             Public Type MyName
               strName As String
               bIsSelect As Boolean
             End Type
             由于程序利用的windows ini文件保存一些标题信息,因而可以方便的修改使用环境,及标题内容。
             见ini文件内容:
           [SYSTEM]
               ;应用程序的form名称
               AppTitle=“风云电脑抽奖Test"
               ;窗口的内的标题(限9个字)
               Title=“大抽奖"
               ;右滚动的文字(仅能为如下格式:XXXX!!!)
                  ScrollTitleRight=“恭喜发财!!!"
               ;左滚动的文字(仅能为如下格式:XXXX!!!)
               ScrollTitleLeft=“祝您好运!!!"
        如此一个小小的电脑抽奖程序便完成了。
        以上程序在VB6.0 Windows98环境下编译通过
        


        4楼2010-01-07 16:25
        回复