Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

My listbox highlight moves fast!

Status
Not open for further replies.
Apr 28, 2006
69
NL
Hi all i got a form that i need to process listbox items on by one automatically by sending it to a textbox but when i click command2 i see the highlight moves so fast and reaches last item in my listbox without allowing my textbox to process all listbox items. Could any one tell me how to solve this problem .Thanks

Code:
Private Sub Command1_Click()

Dim i As Long
For i = 0 To List1.ListCount - 1

List1.Selected(i) = True
txtVariableValue(0) = List1.List(i)
'MsgBox List1.List(i)
DoEvents
cmdSend_Click ' this calls another function to textbox data
Next

End Sub


'Private Sub txtVariableValue_Change(Index As Integer)
'cmdSend_Click

'End Sub

Private Sub Form_Load()

  List1.AddItem "item1"
    List1.AddItem "item2"
    List1.AddItem "item3"
    List1.AddItem "item4"
    List1.AddItem "item5"
     List1.AddItem "item6"
  List1.AddItem "item7"
  List1.AddItem "item8"
  List1.AddItem "item9"

End Sub
 
DavidTigerch,

I wouldn't even bother myself to sending an item to a textbox and with calling the click event of a button. If you need an item to be processed somehow, then just pass its value into the procedure that sits INSIDE the click event, but not the event itself. And what the point in highlighting an item?

vladk
 
i do not how to pass the listbox item to this funciton directly. If that is what u mean .This function needs to process what is in textbox in the form.So i be happy if u show me how i can send it directly to this funciton.txtVariableValue it the variable that holds the item sent from listbox to textbox which has txtVariableValue .I want to process be automatic process all listbox items ony by now:

Code:
' this function sends the HTTP request
Private Sub cmdSend_Click()

    Dim eUrl As URL
    
    Dim strMethod As String
    Dim strData As String
    Dim strPostData As String
    Dim strHeaders As String
    
    Dim strHTTP As String
    Dim X As Integer
    
    strPostData = ""
    strHeaders = ""
    strMethod = cboRequestMethod.List(cboRequestMethod.ListIndex)
    
    If blnConnected Then Exit Sub
    
    ' get the url
    eUrl = ExtractUrl(txtUrl.Text)
    
    If eUrl.Host = vbNullString Then
        MsgBox "Invalid Host", vbCritical, "ERROR"
    
        Exit Sub
    End If
    
    ' configure winsock
    winsock.Protocol = sckTCPProtocol
    winsock.RemoteHost = eUrl.Host
    
    If eUrl.Scheme = "http" Then
        If eUrl.Port > 0 Then
            winsock.RemotePort = eUrl.Port
        Else
            winsock.RemotePort = 80
        End If
    ElseIf eUrl.Scheme = vbNullString Then
        winsock.RemotePort = 80
    Else
        MsgBox "Invalid protocol schema"
    End If
    
    ' build encoded data the data is url encoded in the form
    ' var1=value&var2=value
    strData = ""
[b]
    For X = 0 To txtVariableName.Count - 1
        If txtVariableName(X).Text <> vbNullString Then
        
            strData = strData & URLEncode(txtVariableName(X).Text) & "=" & _
                            URLEncode(txtVariableValue(X).Text) & "&"
        End If
    Next X
    [/b]
    If eUrl.Query <> vbNullString Then
        eUrl.URI = eUrl.URI & "?" & eUrl.Query
    End If
    
    ' check if any variables were supplied
    If strData <> vbNullString Then
        strData = Left(strData, Len(strData) - 1)
        
        
        If strMethod = "GET" Then
            ' if this is a GET request then the URL encoded data
            ' is appended to the URI with a ?
            If eUrl.Query <> vbNullString Then
                eUrl.URI = eUrl.URI & "&" & strData
            Else
                eUrl.URI = eUrl.URI & "?" & strData
            End If
        Else
            ' if it is a post request, the data is appended to the
            ' body of the HTTP request and the headers Content-Type
            ' and Content-Length added
            strPostData = strData
            strHeaders = "Content-Type: application/x-[URL unfurl="true"]www-form-urlencoded"[/URL] & vbCrLf & _
                         "Content-Length: " & Len(strPostData) & vbCrLf
                         
        End If
    End If
            
    ' get any aditional headers and add them
    For X = 0 To txtHeaderName.Count - 1
        If txtHeaderName(X).Text <> vbNullString Then
        
            strHeaders = strHeaders & txtHeaderName(X).Text & ": " & _
                            txtHeaderValue(X).Text & vbCrLf
        End If
    Next X
    
    ' clear the old HTTP response
    'txtResponse.Text = ""
    
    ' build the HTTP request in the form
    '
    ' {REQ METHOD} URI HTTP/1.0
    ' Host: {host}
    ' {headers}
    '
    ' {post data}
    strHTTP = strMethod & " " & eUrl.URI & " HTTP/1.0" & vbCrLf
    strHTTP = strHTTP & "Host: " & eUrl.Host & vbCrLf
    strHTTP = strHTTP & strHeaders
    strHTTP = strHTTP & vbCrLf
    strHTTP = strHTTP & strPostData

    txtRequest.Text = strHTTP
    
    winsock.Connect
    
    ' wait for a connection
    While Not blnConnected
        DoEvents
    Wend
    
    ' send the HTTP request
    winsock.SendData strHTTP

    Command3_Click
End Sub
 
Rather than looping through the textbox (and in fact populating the textbox) in your Click event (as you bolded in your code), why not just loop through the listbox there?

I think that's along the lines of what vlad's talking about.

Hope this helps

HarleyQuinn
---------------------------------
Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
Or in fact, how about just putting the code you have in the cmdSend_Click event into it's own sub and call that passing the listbox item as a variable to it in the call?

Hope this helps

HarleyQuinn
---------------------------------
Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top