vb6,0问题 Private Sub Command1_Click() x = 5 For i = 1 To 20 Step 2 x = x + i \ 5 Next i Print x En
2个回答
展开全部
的值是奇数,并返回相应的数字串
Private Function IsOddNumber(ByVal pString As String, ByRef pStrNum) As Boolean
Dim x As Long
Dim Num As Long
If Len(Trim(pString)) = 0 Then Exit Function
x = InStr(pString, "(")
If x = 0 Then '没有括号,视出现1次
pStrNum = pString
Num = 1
Else
pStrNum = Mid(pString, 1, x - 1)
Num = Val(Mid(pString, x + 1))
End If
IsOddNumber = (Num And 1)
End Function
'数字串计数函数
Private Sub GetNumCount(pStrNum As String, NumCount() As Long, pMaxNum)
Dim n As Long
Do
n = Mid(pStrNum, 1, 1)
NumCount(n) = NumCount(n) + 1
If NumCount(n) > pMaxNum Then pMaxNum = NumCount(n)
Mid(pStrNum, 1, 1) = Chr(32)
pStrNum = Trim(pStrNum)
Loop While Len(pStrNum)
End Sub
Private Sub Command1_Click()
Dim NumCount(9) As Long
Dim arr() As String
Dim i As Long
Dim strTmp As String
Dim lngTmp As Long
Dim maxNum As Long
Dim x As Long
Dim tmp() As String
arr = Split(Text1, vbCrLf)
For i = 0 To UBound(arr)
If Len(arr(i)) > 0 Then
tmp = Split(arr(i), ",")
For x = 0 To UBound(tmp)
If IsOddNumber(tmp(x), strTmp) Then
Call GetNumCount(strTmp, NumCount, maxNum)
End If
Next
End If
Next
'归类排序相同次数值
ReDim tmp(maxNum)
For i = 0 To 9
tmp(NumCount(i)) = tmp(NumCount(i)) & i
Next
'组合排序结果
ReDim arr(9)
x = 0
For i = maxNum To 0 Step -1
If Len(tmp(i)) > 0 Then
arr(x) = tmp(i) & "(" & i & ")"
x = x + 1
End If
Next
ReDim Preserve arr(x - 1)
'MsgBox Join(arr, ",")
'写入txt文本
Dim hFile As Long
Dim pFile As String
pFile = App.Path & "\myTxt.txt"
hFile = FreeFile
Open pFile For Output As hFile
Print #hFile, Join(arr, ",")
Close
'打开文本
Shell "NOTEPAD.EXE " & pFile, vbNormalNoFocus
End Sub
Private Sub Form_Load()
Dim s As String
s = "2(13),6(12),1(11),8(6),0479(5),3(4),5(3)" & vbCrLf
s = s & "3(15),5(10),278(1),0149(0)" & vbCrLf
s = s & "13(4),057" & vbCrLf
s = s & "13456(2),027(1)" & vbCrLf
Text1 = s
End Sub
Private Function IsOddNumber(ByVal pString As String, ByRef pStrNum) As Boolean
Dim x As Long
Dim Num As Long
If Len(Trim(pString)) = 0 Then Exit Function
x = InStr(pString, "(")
If x = 0 Then '没有括号,视出现1次
pStrNum = pString
Num = 1
Else
pStrNum = Mid(pString, 1, x - 1)
Num = Val(Mid(pString, x + 1))
End If
IsOddNumber = (Num And 1)
End Function
'数字串计数函数
Private Sub GetNumCount(pStrNum As String, NumCount() As Long, pMaxNum)
Dim n As Long
Do
n = Mid(pStrNum, 1, 1)
NumCount(n) = NumCount(n) + 1
If NumCount(n) > pMaxNum Then pMaxNum = NumCount(n)
Mid(pStrNum, 1, 1) = Chr(32)
pStrNum = Trim(pStrNum)
Loop While Len(pStrNum)
End Sub
Private Sub Command1_Click()
Dim NumCount(9) As Long
Dim arr() As String
Dim i As Long
Dim strTmp As String
Dim lngTmp As Long
Dim maxNum As Long
Dim x As Long
Dim tmp() As String
arr = Split(Text1, vbCrLf)
For i = 0 To UBound(arr)
If Len(arr(i)) > 0 Then
tmp = Split(arr(i), ",")
For x = 0 To UBound(tmp)
If IsOddNumber(tmp(x), strTmp) Then
Call GetNumCount(strTmp, NumCount, maxNum)
End If
Next
End If
Next
'归类排序相同次数值
ReDim tmp(maxNum)
For i = 0 To 9
tmp(NumCount(i)) = tmp(NumCount(i)) & i
Next
'组合排序结果
ReDim arr(9)
x = 0
For i = maxNum To 0 Step -1
If Len(tmp(i)) > 0 Then
arr(x) = tmp(i) & "(" & i & ")"
x = x + 1
End If
Next
ReDim Preserve arr(x - 1)
'MsgBox Join(arr, ",")
'写入txt文本
Dim hFile As Long
Dim pFile As String
pFile = App.Path & "\myTxt.txt"
hFile = FreeFile
Open pFile For Output As hFile
Print #hFile, Join(arr, ",")
Close
'打开文本
Shell "NOTEPAD.EXE " & pFile, vbNormalNoFocus
End Sub
Private Sub Form_Load()
Dim s As String
s = "2(13),6(12),1(11),8(6),0479(5),3(4),5(3)" & vbCrLf
s = s & "3(15),5(10),278(1),0149(0)" & vbCrLf
s = s & "13(4),057" & vbCrLf
s = s & "13456(2),027(1)" & vbCrLf
Text1 = s
End Sub
展开全部
Private Sub Command1_Click()
dim x = 5
For i = 1 To 20 Step 2
x = x + i \ 5
Print x
Next i
End Sub
是实现这个功能还是实现下面这个功能
Private Sub Command1_Click()
dim x = 5
For i = 1 To 20 Step 2
x = (x + i) \ 5
Print x
Next i
End Sub
问题没说清楚
dim x = 5
For i = 1 To 20 Step 2
x = x + i \ 5
Print x
Next i
End Sub
是实现这个功能还是实现下面这个功能
Private Sub Command1_Click()
dim x = 5
For i = 1 To 20 Step 2
x = (x + i) \ 5
Print x
Next i
End Sub
问题没说清楚
追问
Print x
答案是21,我不懂、、、
追答
把整个题目发出来才能弄清楚
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询