最近脑子乱,一问题想办天想不出来,请教.
cboLogin 里面有数据
张三
李四
王五
如果变量strLogin等于其中的值,则默认选中,如果没有其中的值就为空?

解决方案 »

  1.   

    if instr(strLogin,"张三")=0 and instr(strLogin,"李四")=0 and instr(strLogin,"王五")=0 then strLogin=""
      
      

  2.   

    数据不确定.我的意思是有一combobox,里面或许有那些数据.数据不确定,应该是用FOR或者什么吧.
      

  3.   

    for i=0 to combo.listcount-1
       if 没有其中的值 then combo.listindex=-1
       else combo.listindex=i:exit for
    next
      

  4.   

    for   i=0   to   cboLogin.listcount-1 
          if  strLogin<>cboLogin.list(i)   then   
               cboLogin.listindex=-1 
          else  
               cboLogin.listindex=i
               exit   for 
          end if 
    next
      

  5.   

    Dim strLogin As String * 255  '最后登录人姓名
    Dim n As Integer
    INIFileName$ = App.Path & "\" & strCFG_FileNamen = GetPrivateProfileString("INFO", "LastLogin", "", strLogin, Len(strLogin), INIFileName)
    strLogin = Left(strLogin, n) '读取INI里面最后登陆者的名字
    Call objConnDim rsLoad As New ADODB.Recordset
    sqlLoad$ = "SELECT RealName,UserName FROM ADMIN ORDER BY UserName ASC"
    rsLoad.Open sqlLoad, conn, 1, 1
    If cboUserName.ListCount <> rsLoad.RecordCount Then
        cboUserName.Clear
        While rsLoad.EOF = False
            cboUserName.AddItem rsLoad.Fields("RealName")
            rsLoad.MoveNext
        Wend
    End If
    For i = 0 To cboUserName.ListCount - 1
        If cboUserName.List(i) = strLogin Then
            cboUserName.ListIndex = i
            Exit For
        Else
            cboUserName.ListIndex = -1
        End If
    Next怎么不行啊.
      

  6.   

    我发现问题所在了,主要是在返回值上,len(strLogin)返回255而cboUserName.List(i) 则返回2{如果combobox值为"二字"的话},说明数据类型不对.查了资料,看来还是对GetPrivateProfileString不了解的原因,那么n为什么返回值为LastLogin的值的长度X2呢.