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

2008-04-09 04:42:06来源:互联网 阅读 ()

新老客户大回馈,云服务器低至5折


     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
   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
    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环境下编译通过

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:深入研究VB.Net远程调用对象的机制

下一篇:用注册表给应用程序加口令