数据库中的记录
姓名 分数 地址
洋子 303 中山路
孙子 200 和北路
李子 63 大华路
癞子 102 清华路
老子 42 就窄狗路要求产生如下的结果放入Excel中打印出来
分数每遇到100就要拆分洋子 100 洋子 100
中山路 中山路
洋子 100 洋子 3
中山路 中山路
孙子 100 孙子 100
和北路 和北路
李子 63 癞子 100
大华路 清华路
癞子 2 老子 42
清华路 就窄狗路
乍看似简单。可怎么做也做不出来阿。
顶者有分。请求帮忙。
姓名 分数 地址
洋子 303 中山路
孙子 200 和北路
李子 63 大华路
癞子 102 清华路
老子 42 就窄狗路要求产生如下的结果放入Excel中打印出来
分数每遇到100就要拆分洋子 100 洋子 100
中山路 中山路
洋子 100 洋子 3
中山路 中山路
孙子 100 孙子 100
和北路 和北路
李子 63 癞子 100
大华路 清华路
癞子 2 老子 42
清华路 就窄狗路
乍看似简单。可怎么做也做不出来阿。
顶者有分。请求帮忙。
n = 分数 \ 100 '有几个 100 分
For i = 1 To i
Debug.Print "100" '拆分出的 100 分数
Next i
If 分数 Mod 100 > 0 Then Debug.Print 分数 Mod 100 '非100分的余数
End If
Name As String
Code As Long
Address As String
End Type
Private Sub Form_Load()
Dim Rec(4) As tRecord
Dim Index As Long
Dim i As Long
Dim Code As Long
Rec(0).Name = “洋子”
Rec(0).Code = 303
Rec(0).Address = “中山路” Rec(1).Name = “孙子”
Rec(1).Code = 200
Rec(1).Address = “和北路” Rec(2).Name = “李子”
Rec(2).Code = 63
Rec(2).Address = “大华路” Rec(3).Name = “癞子”
Rec(3).Code = 102
Rec(3).Address = “清华路” Rec(4).Name = “老子”
Rec(4).Code = 42
Rec(4).Address = “中山路” For i = 0 To UBound(Rec)
Code = Rec(i).Code
Index = 0
Do While (Code \ 100) > 0
Debug.Print Rec(i).Name & vbTab & 100 & vbTab & Rec(i).Address
Code = Code - 100
Index = Index + 1
Loop
If Index > 0 Then
If Code <> 0 Then Debug.Print Rec(i).Name & vbTab & Code & vbTab & Rec(i).Address
Else
Debug.Print Rec(i).Name & vbTab & Code & vbTab & Rec(i).Address
End If
Next i
End Sub
Private Type cusInfo
sName As String
iCount As Integer
sAddress As String
End Type
Dim sInfo() As cusInfoPrivate Sub Command1_Click()
Dim iCount As Integer
Dim nX, nY As Integer
Dim itemp As Integer
Dim iLoop As Integer
Dim typetemp() As cusInfo
Dim yusu As Integer '余数
Dim Curset As Integer '当前记录 InitInfo
iCount = UBound(sInfo)
Curset = 0
For nX = 1 To iCount
itemp = sInfo(nX).iCount
If itemp > 100 Then
iLoop = itemp \ 100
yusu = itemp Mod (100 * iLoop)
For nY = 1 To iLoop
Curset = Curset + 1
ReDim Preserve typetemp(1 To Curset)
typetemp(Curset).sName = sInfo(nX).sName
typetemp(Curset).sAddress = sInfo(nX).sAddress
typetemp(Curset).iCount = 100
Next
If yusu > 0 Then
Curset = Curset + 1
ReDim Preserve typetemp(1 To Curset)
typetemp(Curset).sName = sInfo(nX).sName
typetemp(Curset).sAddress = sInfo(nX).sAddress
typetemp(Curset).iCount = yusu
End If
Else
Curset = Curset + 1
ReDim Preserve typetemp(1 To Curset)
typetemp(Curset).sName = sInfo(nX).sName
typetemp(Curset).sAddress = sInfo(nX).sAddress
typetemp(Curset).iCount = sInfo(nX).iCount
End If
Next
Debug.Print Curset
For nX = 1 To Curset
Debug.Print typetemp(nX).sName & ",,," & typetemp(nX).iCount & ",,," & typetemp(nX).sAddress
Next
End SubPrivate Sub InitInfo()
ReDim sInfo(1 To 5)
sInfo(1).sName = "洋子"
sInfo(1).iCount = 303
sInfo(1).sAddress = "中山路"
sInfo(2).sName = "孙子"
sInfo(2).iCount = 200
sInfo(2).sAddress = "和北路"
sInfo(3).sName = "李子"
sInfo(3).iCount = 63
sInfo(3).sAddress = "大华路"
sInfo(4).sName = "癞子"
sInfo(4).iCount = 102
sInfo(4).sAddress = "清华路"
sInfo(5).sName = "老子"
sInfo(5).iCount = 42
sInfo(5).sAddress = "就窄狗路"
End Sub
Name As String
Code As Long
Address As String
End Type
Private Sub Form_Load()
Dim Rec(4) As tRecord
Dim Index As Long
Dim ModCode As Long
Dim i As Long
Dim j As Long
Dim n As Long
Dim Code As Long
Dim Rec01() As tRecord
Rec(0).Name = "洋子"
Rec(0).Code = 303
Rec(0).Address = "中山路" Rec(1).Name = "孙子"
Rec(1).Code = 200
Rec(1).Address = "和北路" Rec(2).Name = "李子"
Rec(2).Code = 63
Rec(2).Address = "大华路" Rec(3).Name = "癞子"
Rec(3).Code = 102
Rec(3).Address = "清华路" Rec(4).Name = "老子"
Rec(4).Code = 42
Rec(4).Address = "中山路" For i = LBound(Rec) To UBound(Rec)
If Rec(i).Code <= 100 Then
ReDim Preserve Rec(n + 1) As tRecord
Rec01(n + 1) = Rec(i)
n = n + 1
Else
Index = Rec(i) \ 100
ModCode = Rec(i) Mod 100
ReDim Preserve Rec01(n + Index + 1) As tRecord
For j = n To n + Index
Rec01(j).Address = Rec(i).Address
Rec01(j).Code = 100
Rec01(j).Name = Rec(i).Name
Next
Rec01(n + Index + 1).Address = Rec(i).Address
Rec01(n + Index + 1).Code = ModCode
Rec01(n + Index + 1).Name = Rec(i).Name
n = n + Index + 1
End If
Next
End Sub
这样也可以哦!!
Option Explicit
Private Type tRecord
Name As String
Code As Long
Address As String
End Type
Dim Rec(4) As tRecordPrivate Sub Form_Load()
Dim Index As Long
Dim ModCode As Long
Dim i As Long
Dim j As Long
Dim n As Long
Dim Code As Long
Dim Rec01() As tRecord
Rec(0).Name = "洋子"
Rec(0).Code = 303
Rec(0).Address = "中山路" Rec(1).Name = "孙子"
Rec(1).Code = 200
Rec(1).Address = "和北路" Rec(2).Name = "李子"
Rec(2).Code = 63
Rec(2).Address = "大华路" Rec(3).Name = "癞子"
Rec(3).Code = 102
Rec(3).Address = "清华路" Rec(4).Name = "老子"
Rec(4).Code = 42
Rec(4).Address = "中山路" For i = LBound(Rec) To UBound(Rec)
If Rec(i).Code <= 100 Then
ReDim Preserve Rec01(n + 1) As tRecord
Rec01(n + 1) = Rec(i)
n = n + 1
Else
Index = Rec(i).Code \ 100
ModCode = Rec(i).Code Mod 100
ReDim Preserve Rec01(n + Index + 1) As tRecord
For j = n + 1 To n + Index
Rec01(j).Address = Rec(i).Address
Rec01(j).Code = 100
Rec01(j).Name = Rec(i).Name
Next
If ModCode <> 0 Then
Rec01(n + Index + 1).Address = Rec(i).Address
Rec01(n + Index + 1).Code = ModCode
Rec01(n + Index + 1).Name = Rec(i).Name
n = n + Index + 1
Else
n = n + Index
End If
End If
Next
For i = 0 To UBound(Rec01)
Debug.Print Rec01(i).Address
Debug.Print Rec01(i).Code
Debug.Print Rec01(i).Name
Next
End Sub
你看这样,不是很简单么? 分数 = 503
名字 = "老子"
折分后字符 = Replace(String(Fix(分数 / 100), "."), ".", "100," & 名字 & vbCrLf)
折分后字符 = 折分后 & 分数 Mod 100 & "," & 名字 & vbCrLf
Debug.Print 折分后字符
你看这样,不是很简单么? 分数 = 503
名字 = "老子"
折分后字符 = Replace(String(Fix(分数 / 100), "."), ".", "100," & 名字 & vbCrLf)
折分后字符 = 折分后字符 & 分数 Mod 100 & "," & 名字 & vbCrLf
Debug.Print 折分后字符