Dim i As Long
Dim ParaAll As String
For i = 0 To 800000
ParaAll = ParaAll & i & ","
Next 这段垃圾代码有运行完的时候吗?为什么状态和死机一样,怎么搞才能得到1,2,3,4....n
的字符串
Dim ParaAll As String
For i = 0 To 800000
ParaAll = ParaAll & i & ","
Next 这段垃圾代码有运行完的时候吗?为什么状态和死机一样,怎么搞才能得到1,2,3,4....n
的字符串
解决方案 »
- combo 的 style 设置为2 也增加(additem )了空行"" ,要怎么才能把 combo.text 的值设置成空行?
- 用VB代码怎样实现版本更新?
- 高手帮帮忙,怎样实现gb2312 ,utf8 编码的相互转换。。
- 请各位帮忙测试
- [求助]如何在vb中用midi函数(api函数midiOutShortMsg)实现多种乐器同时演奏
- 想给女友一个惊喜!
- recordcount为什么是-1
- 是不是form窗体的背景是什么颜色,me.printform打印出来的就是什么颜色呢?
- 请教高手!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- 在VB中用ADO通过ODBC连接ORACEL,数据库中字段的类型,为浮点型时,怎么表示
- 求vb com电子教程
- *****看来VB6.0也能有安全的多线程*****
For i = 0 To 800000
ParaAll = ParaAll & i & ","
DoEvents
Next
Private Sub Command1_Click()
Dim i As Integer
Dim ParaAll As String
For i = 0 To 3
ParaAll = ParaAll & i & ","
Next
Text1.Text = ParaAll ‘将结果在一个文本框里面显示出来
End Sub
正确的书写应该是下面这样:Private Sub Command1_Click()
Dim i As Long
Dim ParaAll As String
For i = 0 To 800
ParaAll = ParaAll & i & ","
Next
Text1.Text = ParaAll
End Sub
改成以下代码速度可以大幅提升:Dim i As Long
Dim ParaStr() As String
dim ParaAll As Stringredim ParaStr(800000)
For i = 0 To 800000
ParaStr(i) = cstr(i)
Next ParaAll=join(ParaStr,",")这样 paraAll 就是你要的字符串了。速度可能提升上千倍。但是别把 i 搞得太大,不然可能会耗光内存造成溢出。
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "StringW"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Attribute VB_Ext_KEY = "SavedWithClassBuilder6" ,"Yes"
Attribute VB_Ext_KEY = "Top_Level" ,"Yes"
Option Explicit
Private cTxtLen As Long, cBuffLen As Long
Public ValueB As String
Public buffSize As LongPublic Property Get Value() As String
Attribute Value.VB_UserMemId = 0
Value = Mid$(ValueB, 1, cTxtLen)
End PropertyPublic Property Let Value(vNewValue As String)
ValueB = vNewValue
cTxtLen = Len(vNewValue)
cBuffLen = cTxtLen
End PropertyPublic Property Get Length() As Long
Length = txtLen
End PropertyPublic Function Add(s As String) As String
Dim oldLen As Long, addTxtlen As Long
addTxtlen = Len(s)
oldLen = cTxtLen
cTxtLen = cTxtLen + addTxtlen
If addTxtlen > buffSize Then
ValueB = Value + s
End If
If cBuffLen < cTxtLen Then
ValueB = ValueB + String$(buffSize, Chr$(0))
cBuffLen = cBuffLen + buffSize
End If
Mid$(ValueB, oldLen + 1, addTxtlen) = s
End FunctionPrivate Sub Class_Initialize()
buffSize = 10240
End Sub这样写代码:
Dim i As Long
Dim ParaAll As New StringW
ParaAll.buffSize = 409600
For i = 0 To 800000
ParaAll.Add i & ","
Next
Text1.Text = ParaAll
Public Function Add(s As String) As String
Dim oldLen As Long, addTxtlen As Long
addTxtlen = Len(s)
oldLen = cTxtLen
cTxtLen = cTxtLen + addTxtlen
If addTxtlen > buffSize Then
ValueB = Value + s
Exit Function
End If
If cBuffLen < cTxtLen Then
ValueB = ValueB + String$(buffSize, Chr$(0))
cBuffLen = cBuffLen + buffSize
End If
Mid$(ValueB, oldLen + 1, addTxtlen) = s
End Function
如果你还需要使用ParaAll ,那么ParaAll = ""基本上释放了内存了
Dim ParaStr() As String
dim ParaAll As Stringredim ParaStr(800000)
For i = 0 To 800000
ParaStr(i) = cstr(i)
DoEvents '加入DoEvents,可以表现的不像死机,但是执行时间变长了,分配时间片嘛
Next ParaAll=join(ParaStr,",")