我想可能是你的记录集的内容没有去空格!
你把内容取出再去除两头的空格试试!
trim(TheString)

解决方案 »

  1.   

    从你的实验可以看出actualsize就是字段的实际长度呀,怎么是字段定义的大小了?
    自动是不可能的,你只能手工循环寻找最大的值,再调整宽度.
      

  2.   

    字段的值当然是会变的啦,可是colwidth(i)的宽度都是1000的啊,我跟求出来的ActualSize这怎么个比法啊?且看下面的循环,
    while not rst.eof 
        for i = 0 to rst.field.count-1
            if mshdata.colwidth(i)<rst .Fields(i).ActualSize then        mshdata.colwidth(i)= rst.Fields(i).ActualSize
              
        next
    wend
    我一运行就死机
      

  3.   

    actualsize是字节宽度,colwidth是的单位是twips
    Dim i As Long, j As Long
        adcView.Refresh
        mshdata.Cols = adcView.Recordset.Fields.Count
        
        With adcView.Recordset
            If Not (.EOF And .BOF) Then
                While Not .EOF
                    For i = 0 To .Fields.Count - 1
                        If mshdata.ColWidth(i) < .Fields(i).ActualSize * Me.TextWidth("a") Then
                            mshdata.ColWidth(i) = .Fields(i).ActualSize * Me.TextWidth("a")
                        End If
                    Next
                    .MoveNext
                Wend
            End If
        End With
      

  4.   

    以下摘之csdn:Public Sub AutoColWidth(Mygrid As MSHFlexGrid)
    With Mygrid
        Dim I As Long
        Dim J As Long
        Dim MaxWidth As Integer
        Dim NowWidth As Integer
        Dim CharWidth As Single
        CharWidth = Mygrid.Parent.TextWidth("A")
        For J = 0 To .Cols - 1
            MaxWidth = 0
            For I = 0 To .Rows - 1
                NowWidth = LenC(.TextMatrix(I, J))
                If NowWidth > MaxWidth Then
                    MaxWidth = NowWidth
                End If
            Next I
            .ColWidth(J) = (MaxWidth + 1) * CharWidth
        Next J
    End With
    End SubPublic Function LenC(Zfc As String) As Long
        '求得中英文混合字符串的长度
        Dim a As String
        a = StrConv(Zfc, vbFromUnicode)
        LenC = LenB(a)
    End Function