您的位置:程序门 -> vb -> 基础类



还是文件写入,还有个问题想问问


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


还是文件写入,还有个问题想问问
发表于:2008-01-17 14:41:47 楼主
下面一段是写入一个数另起一行,如果我想每10个数一行呢
例如:1,2,3,4,5,6,7,8,9,10
          11,...........
这样


private   sub   command1_click()
        dim   str   as   string
        command1.visible   =   false
        randomize   timer
        str   =   ""
        open   "c:\vb.txt"   for   output   as   #1
        while   j   <   10
                q   =   int(rnd(1)   *   369   +   1)
                label1.caption   =   q:   doevents
                if   n(q)   =   0   and   bstop   =   true   then
                        str   =   str   &   q   &   chr(13)   &   chr(10)
                        n(q)   =   1
                        j   =   j   +   1
                        bstop   =   false
                end   if
        wend
        if   str   <>   ""   then
                print   #1,   str
        end   if
        close   #1
end   sub
发表于:2008-01-17 17:01:501楼 得分:0
将这句红色部分去掉
str   =   str   &   q   &       chr(13)       &       chr(10)  
改为
str   =   str   &   q   &   ","

将这句改了
if   str   <>   ""   then  
        print       #1,       str  
end       if  
改为
if   len(str)   =   0   then  
        print   #1,   left(str,   len(str)   -   1)   &   vbcrlf
end       if  
发表于:2008-01-17 17:03:212楼 得分:0
写错了,应该是   "> ",   不是   "="
if   len(str)   >   0   then      
发表于:2008-01-17 20:52:423楼 得分:0
  楼上的我调试乐,貌似不行啊,全部写成一排乐
发表于:2008-01-17 21:57:404楼 得分:0
呵呵,你又问这个..
还没搞好啊?
发表于:2008-01-17 22:22:225楼 得分:0
呵呵,你那个是每个数字一行,这次我想10个一行打印,搞不定
发表于:2008-01-18 08:11:286楼 得分:0
从你代码中我看不大懂,你有多少个数据,还是无限制,总的有个结束条件吧。
发表于:2008-01-18 08:40:107楼 得分:0
private       sub       command1_click()  
                dim       str       as       string  
                command1.enabled       =       false  
                randomize       timer  
                str       =       ""  
                open       "c:\vb.txt"       for       output       as       #1  
                while   j   <   10    
                                q       =       int(rnd(1)       *       369       +       1)  
                                label1.caption       =       q:       doevents  
                                if       n(q)       =       0       and       bstop       =       true       then  
                                                str       =       str       &       q       &       iif((j   mod   10)   =   9,   vbnewline,   ",")
                                                n(q)       =       1  
                                                j       =       j       +       1
                                                bstop       =       false  
                                end       if  
                wend  
                if       str       <>       ""       then  
                                print       #1,       str  
                end       if  
                close       #1  
end       sub
发表于:2008-01-18 10:10:068楼 得分:0
        dim   ofilesysobject     as   filesystemobject
        dim   otextstream           as   textstream
        dim   lindex                     as   long
        dim   sline                       as   string
       
        on   error   goto   errhnd
       
        set   ofilesysobject   =   new   filesystemobject
       
        set   otextstream   =   ofilesysobject.opentextfile("c:\test.txt",   forwriting,   true)
       
        for   lindex   =   1   to   100
                if   sline   =   ""   then
                        sline   =   cstr(lindex)
                else
                        sline   =   sline   &   ","   &   cstr(lindex)
                end   if
               
                if   lindex   mod   10   =   0   then
               
                        otextstream.writeline   (sline)
                       
                        sline   =   ""
                end   if
        next
       
        otextstream.close
       
        set   ofilesysobject   =   nothing
       
        exit   sub
errhnd:
        msgbox   (err.description)
发表于:2008-01-18 10:13:499楼 得分:0
接上

要在参照设定里选中microsoft   scripting   runtime
发表于:2008-01-18 10:36:3010楼 得分:0
按of123的方法,然后你把while   j <10改为j <100,你应该看到10行了


快速检索

最新资讯
热门点击