If Trim(Aclass.Text) <> "" Then
        smallclass1 = Trim(Aclass.Text)
        End If
        If Trim(AnClass.Text) <> "" Then
        smallclass2 = Trim(AnClass.Text)
        End If
        If Trim(Aclass1.Text) <> "" Then
        smallclass3 = Trim(Aclass1.Text)
        End If
        If Trim(Anclass1.Text) <> "" Then
        smallclass4 = Trim(Anclass1.Text)
        End If
        smallclass = smallclass1 & " , " & smallclass2 & ", " & smallclass3 & ", " & smallclass4
如果我现在4个都选那么smallclass 的值刚好是我想要的
但是如果有的是空那么就多了我不想要的,
我不知道这个应该怎么处理,大家帮忙告诉

解决方案 »

  1.   

    Private Sub Form_Load()
        Dim SmallClass As String
        SmallClass = ""
        If Trim(Aclass.Text) <> "" Then
            SmallClass = Trim(Aclass.Text)
        End If
        If Trim(AnClass.Text) <> "" Then
            If Trim(SmallClass) = "" Then
                SmallClass = Trim(AnClass.Text)
            Else
                SmallClass = SmallClass & "," & Trim(AnClass.Text)
            End If
        End If
        If Trim(Aclass1.Text) <> "" Then
            If Trim(SmallClass) = "" Then
                SmallClass = Trim(Aclass1.Text)
            Else
                SmallClass = SmallClass & "," & Trim(Aclass1.Text)
            End If
        End If
        If Trim(Anclass1.Text) <> "" Then
            If Trim(SmallClass) = "" Then
                SmallClass = Trim(Anclass1.Text)
            Else
                SmallClass = SmallClass & "," & Trim(Anclass1.Text)
            End If
        End If
        MsgBox SmallClass
    End Sub
      

  2.   

    smallclass = ""
        If Trim(Aclass.Text) <> "" Then
            smallclass = smallclass & Trim(Aclass.Text) & ","
        End If
        If Trim(AnClass.Text) <> "" Then
            smallclass = smallclass & Trim(AnClass.Text) & ","
        End If
        If Trim(Aclass1.Text) <> "" Then
            smallclass = smallclass & Trim(Aclass1.Text) & ","
        End If
        If Trim(Anclass1.Text) <> "" Then
            smallclass = smallclass & Trim(Anclass1.Text) & ","
        End If
        If Len(smallclass) > 1 Then
            '截掉最后的逗号
            smallclass = Left(smallclass, Len(smallclass) - 1)
        End If
      

  3.   

    If Trim(Aclass.Text) <> "" Then
            smallclass1 = Trim(Aclass.Text)
    smallclass=smallclass & smallclass1 & ","
            End If
            If Trim(AnClass.Text) <> "" Then
            smallclass2 = Trim(AnClass.Text)
            smallclass=smallclass & smallclass2 & ","
            End If
            If Trim(Aclass1.Text) <> "" Then
            smallclass3 = Trim(Aclass1.Text)
            smallclass=smallclass & smallclass3 & ","
            End If
            If Trim(Anclass1.Text) <> "" Then
            smallclass4 = Trim(Anclass1.Text)
            smallclass=smallclass & smallclass4 & ","
            End If
            if smallclass<>"" then
            smallclass = left(smallclass,len(smallclass)-1)
            end if
      

  4.   

    dim smallclass as string
    smallclass=""
    If Trim(Aclass.Text) <> "" Then
            smallclass = smallclass & Trim(Aclass.Text)
            End If
            If Trim(AnClass.Text) <> "" Then
            smallclass = smallclass & Trim(AnClass.Text)
            End If
            If Trim(Aclass1.Text) <> "" Then
            smallclass = smallclass & Trim(Aclass1.Text)
            End If
            If Trim(Anclass1.Text) <> "" Then
            smallclass = smallclass & Trim(Anclass1.Text)
            End If