首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > VB Dotnet >

VB.NET 一段程序老是溢出!解决办法

2012-01-26 
VB.NET 一段程序老是溢出!急!上次问过一次。。。可是试了一下。。。还是不行。。。所以再来问一次。。。Public Class F

VB.NET 一段程序老是溢出!急!
上次问过一次。。。可是试了一下。。。还是不行。。。所以再来问一次。。。
Public Class Form2
  Inherits System.Windows.Forms.Form


  Public intCustomNum As Integer '顾客总人数
  Public intComeCata As Integer '到达时间分布类型
  Public intBuyCata As Integer '购物时间分布类型
  Public intPayCata As Integer '付款时间分布类型

  Public intSeverNum As Integer '服务台数 'Public intSeverNum As Integer 服务台数
  Public maxLength As Integer '最大队列长度
  Public sinTotalTime As String '仿真最长时间
  Public nowTime As Single '当前系统时针
  Public nowCustom As Long '当前顾客
  Private sinCustomCome() As Long '顾客到达时间
  Private sinCustomBuy() As Long '顾客购物完毕时间
  Private sinCustomBuyTime() As Long '顾客选购时间
  Private sinCustomBuyTemp() As Single '临时变量
  Private intQueueSquare(,) As Long '顾客排队队列矩阵 'Dim intQueueSquare(,) As long
  Private sinStartPay() As Long '开始付款时间
  Private sinStartPayTemp() As Single
  Private sinLeaveTime() As Long '离去时间
  Private sinLeaveTimeTemp() As Single
  Private sinCustomPayTime() As Single '付款时间
  Private intQueueLength() As Long '顾客队列长度
  Private intCustomRow() As Long '顾客所在队列序号
  Private intQueuePosit() As Long '顾客所在队列位置
  Private sinLesTime() As Single '顾客空闲时间
  Private sinCustomWait As Single '等待时间
  Private intCustomWaitNum As Integer '排
  Private sinQueueLeis() As Single
  Private sinQueueTime() As Single
  Const MAX = 100000000.0#


  Public g As Single
  Public h As Single
  Public j As Single
  Public k As Single
  Public l As Single

  Public nNow As Long

  '=============================================初始化函数 把所有清空=============================================
  Private Sub Initial()
  Randomize()
  Dim i As Integer
  intCustomNum = 0
  maxLength = 0
  nowTime = 0
  'intComeCata = intddcata '取得各个分布类型及其参数
  intBuyCata = intgwcata
  intPayCata = intfkcata
  intSeverNum = TextBox1.Text
  ReDim sinCustomCome(0) '重新定义各个动态数组
  ReDim sinCustomBuy(0)
  ReDim sinCustomBuyTime(0)
  ReDim sinLeaveTime(0)
  ReDim sinCustomPayTime(0)
  ReDim sinLeaveTimeTemp(0)

  ReDim intQueueSquare(intSeverNum - 1, 0)
  ReDim intQueueLength(intSeverNum - 1)
  ReDim intCustomRow(0)
  ReDim sinCustomBuyTemp(0)
  ReDim intQueuePosit(0)
  ReDim sinStartPay(0)
  ReDim sinStartPayTemp(0)
  ReDim sinQueueLeis(0)
  ReDim sinQueueTime(0)
  ReDim sinLesTime(intSeverNum - 1)
  ReDim sinQueueTime(intSeverNum - 1)
  For i = 0 To intSeverNum - 1
  sinLesTime(i) = 0
  Next
  sinCustomWait = 0
  intCustomWaitNum = 0
  sinCustomCome(0) = 0
  sinCustomBuy(0) = 0
  sinCustomBuyTemp(0) = 0
  intCustomRow(0) = 0
  For i = 0 To intSeverNum - 1
  intQueueSquare(i, 0) = 0
  intQueueLength(i) = 0
  Next
  DataGridView1.RowCount = 1 ' DataGridView1.RowCount = 1 不知道对不对
  End Sub





  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  If IsNumeric(TextBox1.Text) = False Or IsNumeric(TextBox2.Text) = False Or IsNumeric(TextBox3.Text) = False Then
  MsgBox("请输入数字", , "注意")
  TextBox1.Text = ""
  TextBox2.Text = ""
  TextBox3.Text = ""
  TextBox1.Focus()
  Exit Sub
  End If

  Initial()
  GetTime()
  CustomArrive()

  Do '事件选择流程
  Select Case ChooseEvent()
  Case 0
  CustomArrive() '到达事件
  Case 1
  ChooseQueue(nowCustom) '购毕事件
  Case 2
  CustomLeave(nowCustom) '离去事件,排队结束事件
  End Select
  Loop Until nowTime > sinTotalTime '仿真结束标志
  OutPut()

  End Sub

  Public Function GetTolSeconds(ByVal dtDateTime As DateTime) As Integer
  GetTolSeconds = dtDateTime.Hour * 3600 + dtDateTime.Minute * 60 + dtDateTime.Second
  End Function


  Public Function SecondToHour(ByVal nSecondTime As Integer) As String
  Dim nHour As Integer
  Dim nMinute As Integer
  Dim nSecond As Integer
  nHour = Int(nSecondTime / 3600)
  nMinute = Int((nSecondTime - nHour * 3600) / 60)
  nSecond = nSecondTime - nHour * 3600 - nMinute * 60
  Dim sMinute As String
  Dim sSecond As String
  If nMinute.ToString.Length = 1 Then
  sMinute = "0" & nMinute.ToString
  Else
  sMinute = nMinute.ToString
  End If

  If nSecond.ToString.Length = 1 Then
  sSecond = "0" & nSecond.ToString
  Else
  sSecond = nSecond.ToString
  End If
  SecondToHour = nHour & ":" & sMinute & ":" & sSecond
  End Function

  '========================================================顾客到达(指定为指数分布)以及购物事件=============================================================
  Private Sub CustomArrive()
  Dim sngArrivalNmd As Single '取到达的λ
  Dim a As Single
  Dim b As Single
  Dim f As Single
  Dim c As Single
  Dim d As Single

  SystemPara.sngArrivalNmd = Me.Label4.Text

  Dim sinComeTime As Single
  Dim sinBuyTime As Single

  intCustomNum = intCustomNum + 1 '顾客数+1,因为初始值赋给的是0,所以要加1

  ReDim Preserve sinCustomCome(intCustomNum) 'redim是重新定义数组的大小,preserve可以保留数组的内容()
  ReDim Preserve sinCustomBuy(intCustomNum)
  ReDim Preserve sinCustomBuyTemp(intCustomNum)
  ReDim Preserve sinCustomBuyTime(intCustomNum)
  ReDim Preserve sinLeaveTime(intCustomNum)
  ReDim Preserve sinLeaveTimeTemp(intCustomNum)
  ReDim Preserve sinCustomPayTime(intCustomNum)
  ReDim Preserve intCustomRow(intCustomNum)
  ReDim Preserve intQueuePosit(intCustomNum)
  ReDim Preserve sinStartPay(intCustomNum)
  ReDim Preserve sinStartPayTemp(intCustomNum)

  sinComeTime = indexrandom(sngArrivalNmd) '到达分布类型




  Select Case intBuyCata
  Case 1
  a = Me.Label9.Text
  b = Me.Label7.Text
  sinBuyTime = avgrandom(a, b)
  Case 2
  f = Me.Label9.Text
  sinBuyTime = indexrandom(f)
  Case 3
  c = Me.Label9.Text
  d = Me.Label7.Text
  sinBuyTime = ztRandom(c, d)
  End Select

  sinCustomBuyTime(intCustomNum) = sinBuyTime '顾客购货时间
  sinCustomCome(intCustomNum) = sinComeTime + sinCustomCome(intCustomNum - 1) '生成下位顾客到达时间
  sinCustomBuy(intCustomNum) = sinBuyTime + sinCustomCome(intCustomNum - 1) '顾客购物完毕时间
  sinStartPay(intCustomNum) = MAX
  sinLeaveTime(intCustomNum) = MAX
  sinLeaveTimeTemp(intCustomNum) = MAX
End Sub

sinCustomCome(intCustomNum) = sinComeTime + sinCustomCome(intCustomNum - 1) '生成下位顾客到达时间
执行到这步就溢出。。。

代码很多。。。
各位大大帮个忙吧。。。谢谢。。。

[解决办法]
Private sinLeaveTimeTemp() As Single 
Private sinCustomPayTime() As Single '付款时间
这两个用Double试试。

Loop Until nowTime > sinTotalTime '仿真结束标志 
还有这一句,nowTime是Single类型,而sinTotalTime是String类型,并且,我没有看到你在哪里给sinTotalTime赋值。
[解决办法]
把出错提示信息贴上来大家能更好地分析

热点排行