Results 1 to 5 of 5

Thread: My listbox highlight moves fast!

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    Arrow My listbox highlight moves fast!

    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

    VB Code:
    1. Private Sub Command2_Click()
    2.  
    3. Dim i As Long
    4. For i = 0 To List1.ListCount - 1
    5.    Text2 = List1.List(i)
    6.    List1.Selected(i) = True
    7.  
    8. Next
    9.  
    10. End Sub
    11.  
    12.  
    13. Private Sub Form_Load()
    14.  
    15.   List1.AddItem "item1"
    16.     List1.AddItem "item2"
    17.     List1.AddItem "item3"
    18.     List1.AddItem "item4"
    19.     List1.AddItem "item5"
    20.      List1.AddItem "item6"
    21.   List1.AddItem "item7"
    22.   List1.AddItem "item8"
    23.   List1.AddItem "item9"
    24.  
    25. End Sub

  2. #2
    Frenzied Member Andrew G's Avatar
    Join Date
    Nov 2005
    Location
    Sydney
    Posts
    1,587

    Re: My listbox highlight moves fast!

    VB Code:
    1. For i = 0 To List1.ListCount - 1
    2.    Text2 = List1.List(i)
    3.    List1.Selected(i) = True
    4.    DoEvents
    5. Next

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    Re: My listbox highlight moves fast!

    Quote Originally Posted by Andrew G
    VB Code:
    1. For i = 0 To List1.ListCount - 1
    2.    Text2 = List1.List(i)
    3.    List1.Selected(i) = True
    4.    DoEvents
    5. Next
    Thank u for u reply. I tried this now i see the value keep chang in my textbox like in my listbox i got 2000 items!! and i scans them in like 4 seconds.And my program only executes 2 of them !!! I tried the following code where cmdSend_Click is a function that needs to make a post request to php script and output the result in another textbox. I need to do this a large amount of items from listbox and it failes each time . I tried sleep function and nothing got transfred to textbox2. I be happy if i get helping in achiving this task.Thanks


    VB Code:
    1. Private Sub Command1_Click()
    2.  
    3. Dim i As Long
    4. For i = 0 To List2.ListCount - 1
    5.  
    6. List2.Selected(i) = True
    7. txtVariableValue(0) = List2.List(i)
    8.  
    9. DoEvents
    10. [B]cmdSend_Click[/B]
    11. Next
    12.  
    13. End Sub

  4. #4
    Frenzied Member Andrew G's Avatar
    Join Date
    Nov 2005
    Location
    Sydney
    Posts
    1,587

    Re: My listbox highlight moves fast!

    Wats in your CmdSend_Click Sub?

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    Re: My listbox highlight moves fast!

    Quote Originally Posted by Andrew G
    Wats in your CmdSend_Click Sub?
    Complete code and importent part shown in bold:
    VB Code:
    1. Option Explicit
    2. '' this 3 lines to add scroll bar to listbox
    3. Private Declare Function ShowScrollBar Lib "user32" (ByVal hwnd As Long, ByVal wBar As Long, _
    4. ByVal bShow As Long) As Long
    5. 'Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
    6.  
    7. Private Const SB_HORIZONTAL = 0
    8. ' we set this to true whil a connection is established
    9. Private blnConnected As Boolean
    10.  
    11.  
    12.  
    13. ' this function sends the HTTP request
    14. [B]Private Sub cmdSend_Click()[/B]
    15.  
    16.     Dim eUrl As URL
    17.    
    18.     Dim strMethod As String
    19.     Dim strData As String
    20.     Dim strPostData As String
    21.     Dim strHeaders As String
    22.    
    23.     Dim strHTTP As String
    24.     Dim X As Integer
    25.    
    26.     strPostData = ""
    27.     strHeaders = ""
    28.     strMethod = cboRequestMethod.List(cboRequestMethod.ListIndex)
    29.    
    30.     If blnConnected Then Exit Sub
    31.    
    32.     ' get the url
    33.     eUrl = ExtractUrl(txtUrl.Text)
    34.    
    35.     If eUrl.Host = vbNullString Then
    36.         MsgBox "Invalid Host", vbCritical, "ERROR"
    37.    
    38.         Exit Sub
    39.     End If
    40.    
    41.     ' configure winsock
    42.     winsock.Protocol = sckTCPProtocol
    43.     winsock.RemoteHost = eUrl.Host
    44.    
    45.     If eUrl.Scheme = "http" Then
    46.         If eUrl.Port > 0 Then
    47.             winsock.RemotePort = eUrl.Port
    48.         Else
    49.             winsock.RemotePort = 80
    50.         End If
    51.     ElseIf eUrl.Scheme = vbNullString Then
    52.         winsock.RemotePort = 80
    53.     Else
    54.         MsgBox "Invalid protocol schema"
    55.     End If
    56.    
    57.     ' build encoded data the data is url encoded in the form
    58.     ' var1=value&var2=value
    59.     strData = ""
    60.     For X = 0 To txtVariableName.Count - 1
    61.         If txtVariableName(X).Text <> vbNullString Then
    62.        
    63.             strData = strData & URLEncode(txtVariableName(X).Text) & "=" & _
    64.                             URLEncode(txtVariableValue(X).Text) & "&"
    65.         End If
    66.     Next X
    67.    
    68.     If eUrl.Query <> vbNullString Then
    69.         eUrl.URI = eUrl.URI & "?" & eUrl.Query
    70.     End If
    71.    
    72.     ' check if any variables were supplied
    73.     If strData <> vbNullString Then
    74.         strData = Left(strData, Len(strData) - 1)
    75.        
    76.        
    77.         If strMethod = "GET" Then
    78.             ' if this is a GET request then the URL encoded data
    79.             ' is appended to the URI with a ?
    80.             If eUrl.Query <> vbNullString Then
    81.                 eUrl.URI = eUrl.URI & "&" & strData
    82.             Else
    83.                 eUrl.URI = eUrl.URI & "?" & strData
    84.             End If
    85.         Else
    86.             ' if it is a post request, the data is appended to the
    87.             ' body of the HTTP request and the headers Content-Type
    88.             ' and Content-Length added
    89.             strPostData = strData
    90.             strHeaders = "Content-Type: application/x-www-form-urlencoded" & vbCrLf & _
    91.                          "Content-Length: " & Len(strPostData) & vbCrLf
    92.                          
    93.         End If
    94.     End If
    95.            
    96.     ' get any aditional headers and add them
    97.     For X = 0 To txtHeaderName.Count - 1
    98.         If txtHeaderName(X).Text <> vbNullString Then
    99.        
    100.             strHeaders = strHeaders & txtHeaderName(X).Text & ": " & _
    101.                             txtHeaderValue(X).Text & vbCrLf
    102.         End If
    103.     Next X
    104.    
    105.     ' clear the old HTTP response
    106.     'txtResponse.Text = ""
    107.    
    108.     ' build the HTTP request in the form
    109.     '
    110.     ' {REQ METHOD} URI HTTP/1.0
    111.     ' Host: {host}
    112.     ' {headers}
    113.     '
    114.     ' {post data}
    115.     strHTTP = strMethod & " " & eUrl.URI & " HTTP/1.0" & vbCrLf
    116.     strHTTP = strHTTP & "Host: " & eUrl.Host & vbCrLf
    117.     strHTTP = strHTTP & strHeaders
    118.     strHTTP = strHTTP & vbCrLf
    119.     strHTTP = strHTTP & strPostData
    120.  
    121.     txtRequest.Text = strHTTP
    122.    
    123.     winsock.Connect
    124.    
    125.     ' wait for a connection
    126.     While Not blnConnected
    127.         DoEvents
    128.     Wend
    129.    
    130.     ' send the HTTP request
    131.     winsock.SendData strHTTP
    132.  
    133.     Command3_Click
    134. End Sub
    135.  
    136.  
    137. ' transfer all urls i loop
    138. [B]Private Sub Command1_Click()
    139.  
    140. Dim i As Long
    141. For i = 0 To List2.ListCount - 1
    142.  
    143. List2.Selected(i) = True
    144. txtVariableValue(0) = List2.List(i)
    145. 'MsgBox List2.List(i)
    146. DoEvents
    147. cmdSend_Click
    148. Next
    149.  
    150. End Sub[/B]
    151.  
    152.  
    153. Private Sub txtVariableValue_Change(Index As Integer)
    154. cmdSend_Click
    155.  
    156. End Sub
    157.  
    158.  
    159.  
    160. 'transfer url one by one function
    161. Private Sub Command2_Click()
    162.  
    163. txtVariableValue(0) = List2.Text
    164. End Sub
    165.  
    166. 'writes the content of text box to a file
    167. ' this funcion needs to write to a text file
    168. Private Sub Command3_Click()
    169. 'Dim Parser As New clsXMLParser
    170.  ' Dim Node As clsXMLNode
    171.   'Dim Child As clsXMLNode
    172.   Dim fn As Long
    173.   'Dim i As Long
    174.  
    175.  'Dim path As String
    176.   'Dim title As String
    177.  
    178.   fn = FreeFile
    179.   Open "C:\file.txt" For Append As #fn
    180.   'Yes. Use Print #fn instead of Write #fn
    181.     'Write #fn, Text4.Text
    182.     Print #fn, txtResponse.Text
    183.   Close #fn
    184.  
    185.  
    186.  
    187.  
    188. End Sub
    189.  
    190.  
    191.  
    192.  
    193.  
    194. Private Sub winsock_Connect()
    195.     blnConnected = True
    196. End Sub
    197.  
    198. ' this event occurs when data is arriving via winsock
    199. Private Sub winsock_DataArrival(ByVal bytesTotal As Long)
    200.     Dim strResponse As String
    201.  
    202.     winsock.GetData strResponse, vbString, bytesTotal
    203.    
    204.     strResponse = FormatLineEndings(strResponse)
    205.    
    206.     ' we append this to the response box becuase data arrives
    207.     ' in multiple packets
    208.     txtResponse.Text = txtResponse.Text & strResponse
    209.    
    210. End Sub
    211.  
    212. Private Sub winsock_Error(ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
    213.     MsgBox Description, vbExclamation, "ERROR"
    214.    
    215.     winsock.Close
    216. End Sub
    217.  
    218. Private Sub winsock_Close()
    219.     blnConnected = False
    220.    
    221.     winsock.Close
    222. End Sub
    223.  
    224. ' this function converts all line endings to Windows CrLf line endings
    225. Private Function FormatLineEndings(ByVal str As String) As String
    226.     Dim prevChar As String
    227.     Dim nextChar As String
    228.     Dim curChar As String
    229.    
    230.     Dim strRet As String
    231.    
    232.     Dim X As Long
    233.    
    234.     prevChar = ""
    235.     nextChar = ""
    236.     curChar = ""
    237.     strRet = ""
    238.    
    239.     For X = 1 To Len(str)
    240.         prevChar = curChar
    241.         curChar = Mid$(str, X, 1)
    242.                
    243.         If nextChar <> vbNullString And curChar <> nextChar Then
    244.             curChar = curChar & nextChar
    245.             nextChar = ""
    246.         ElseIf curChar = vbLf Then
    247.             If prevChar <> vbCr Then
    248.                 curChar = vbCrLf
    249.             End If
    250.            
    251.             nextChar = ""
    252.         ElseIf curChar = vbCr Then
    253.             nextChar = vbLf
    254.         End If
    255.        
    256.         strRet = strRet & curChar
    257.     Next X
    258.    
    259.     FormatLineEndings = strRet
    260. End Function
    261.  
    262. Private Sub Form_Load()
    263.     cboRequestMethod.ListIndex = 0
    264.     blnConnected = False
    265.    
    266.    
    267.    [B]List2.AddItem "item1"
    268.     List2.AddItem "item2"
    269.     List2.AddItem "item3"
    270.     List2.AddItem "item4"
    271.     List2.AddItem "item5"
    272.      List2.AddItem "item6"
    273.   List2.AddItem "item7"
    274.   List2.AddItem "item8"
    275.   List2.AddItem "item9"[/B]
    276.  
    277. End Sub
    278.  
    279. ' the code below has nothing to do with winsock or HTTP and deals only with the
    280. ' display and manipulation of controls
    281. Private Sub cmdMoreHeaders_Click()
    282.     Dim intNext As Integer
    283.     Dim lngTop As Long
    284.    
    285.     ' find the next control
    286.     intNext = txtHeaderName.Count
    287.    
    288.     ' find the next top
    289.     lngTop = txtHeaderName(intNext - 1).Top + txtHeaderName(intNext - 1).Height + 80
    290.    
    291.     ' add new controls
    292.     Load lblHeaderName(intNext)
    293.     Load txtHeaderName(intNext)
    294.     Load lblHeaderValue(intNext)
    295.     Load txtHeaderValue(intNext)
    296.    
    297.                                  
    298.     With lblHeaderName(intNext)
    299.         .Top = lngTop
    300.         .Left = lblHeaderName(intNext - 1).Left
    301.         .Visible = True
    302.     End With
    303.    
    304.     With txtHeaderName(intNext)
    305.         .Top = lngTop
    306.         .Left = txtHeaderName(intNext - 1).Left
    307.         .Visible = True
    308.         .Text = ""
    309.     End With
    310.        
    311.     With lblHeaderValue(intNext)
    312.         .Top = lngTop
    313.         .Left = lblHeaderValue(intNext - 1).Left
    314.         .Visible = True
    315.     End With
    316.    
    317.     With txtHeaderValue(intNext)
    318.         .Top = lngTop
    319.         .Left = txtHeaderValue(intNext - 1).Left
    320.         .Visible = True
    321.         .Text = ""
    322.     End With
    323.    
    324.     ' set the new height of the controls container
    325.     pbxHeaders.Height = txtHeaderName(intNext).Top + txtHeaderName(intNext).Height + 80
    326.    
    327.     ' check if we should activate the scroll bar, ie: the outerbox
    328.     ' is higher than the inner box
    329.     If pbxHeaders.Height > pbxOHeaders.Height Then
    330.         With vsbHeaders
    331.             .Enabled = True
    332.             .SmallChange = txtHeaderName(intNext).Height
    333.             .LargeChange = pbxOHeaders.Height
    334.             .Min = 0
    335.             .Max = pbxHeaders.Height - pbxOHeaders.Height
    336.             .Value = .Max
    337.         End With
    338.     End If
    339. End Sub
    340.  
    341.  
    342.  
    343. Private Sub vsbHeaders_Change()
    344.     pbxHeaders.Top = 0 - vsbHeaders.Value
    345. End Sub
    346.  
    347. Private Sub vsbHeaders_Scroll()
    348.     pbxHeaders.Top = 0 - vsbHeaders.Value
    349. End Sub
    350.  
    351. Private Sub vsbVariables_Change()
    352.     pbxVariables.Top = 0 - vsbVariables.Value
    353. End Sub
    354.  
    355. Private Sub vsbVariables_Scroll()
    356.     pbxVariables.Top = 0 - vsbVariables.Value
    357. End Sub
    Last edited by tony007; May 7th, 2006 at 03:01 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width