473,324 Members | 1,856 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Read and Write from a listbox (VB6)

I got a textbox, from where people can add textstrings to a listbox.
From there, I want, once a person clicks "Start", the program types the first string from the list. After the interval the second, and so on. After it's had all of them, I want it to start at the top of the list again and repeat the action.
I already got a start button, but when I click it, it doesnt seem to read from the listbox and type them on the screen.

Could anyone help me getting this straight ?
Thanks,
Evolution445
Jul 17 '07 #1
10 7645
danp129
323 Expert 256MB
I got a textbox, from where people can add textstrings to a listbox.
From there, I want, once a person clicks "Start", the program types the first string from the list. After the interval the second, and so on. After it's had all of them, I want it to start at the top of the list again and repeat the action.
I already got a start button, but when I click it, it doesnt seem to read from the listbox and type them on the screen.

Could anyone help me getting this straight ?
Thanks,
Evolution445
You forgot to post the code that's not working
Jul 17 '07 #2
Oh, sorry, here it is:

Expand|Select|Wrap|Line Numbers
  1. Private Sub msglist_Click()
  2. Dim message As String
  3. Dim currentmsg As Integer
  4. currentmsg = currentmsg + 1
  5. message = msglist.list(currentmsg)
  6. End Sub
  7.  
Edit:

This is the code I got in the Listbox. In the timer, thats activated with the startbutton, I only have the bit that it presses Enter, which also doesnt seem to work:

Expand|Select|Wrap|Line Numbers
  1. Private Sub msgtimer_Timer()
  2. SendKeys (vbKeyReturn)
  3. End Sub
  4.  
Anyone got any idea on solving this problem and get the list and pressing enter to work ?
Jul 17 '07 #3
danp129
323 Expert 256MB
This should work
Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2. Dim lngPrevItem As Long
  3. Dim blnRunning As Boolean
  4.  
  5. Private Sub Command1_Click()
  6.     'Command button to add text to listbox
  7.     List1.AddItem Text1.Text
  8.     Text1.Text = ""
  9. End Sub
  10.  
  11. Private Sub Command2_Click()
  12.     'command button to start timer
  13.     If blnRunning Then Command2.Caption = "Start" Else Command2.Caption = "Stop"
  14.     blnRunning = blnRunning = False
  15.     msgtimer.Enabled = blnRunning
  16. End Sub
  17.  
  18. Private Sub msgtimer_Timer()
  19.     'Timer to send keystrokes
  20.     If lngPrevItem = List1.ListCount - 1 Then lngPrevItem = -1
  21.     lngPrevItem = lngPrevItem + 1
  22.     SendKeys List1.List(lngPrevItem), 10
  23. End Sub
  24.  
  25. Private Sub Form_Load()
  26.     Text1.Text = ""
  27.     Command1.Caption = "Add"
  28.     Command2.Caption = "Start"
  29.     msgtimer.Enabled = False
  30.     msgtimer.Interval = 1000
  31. End Sub
Jul 17 '07 #4
Somehow it just doesnt seem to be working. It also refuses to press enter.
Would this be right to make it press enter after the message has been typed ?

SendKeys (vbKeyReturn)

Could it maybe be that it types the text, and presses Enter at the same time ?
Would there be an easy code to make it wait about 100 milliseconds ?
Jul 17 '07 #5
danp129
323 Expert 256MB
use vbCr:
SendKeys List1.List(lngPrevItem) & vbCr, 10
Jul 17 '07 #6
Thanks a lot, as it worked. But now I upgraded to VB2005. (The one currently on Microsoft's website)
I managed to change the code a bit so it would work in my eyes, but now it just writes: False, instead of the message from the listbox.

Here's the code from my current timer.
Expand|Select|Wrap|Line Numbers
  1.     Private Sub msgtimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles msgtimer.Tick
  2.         Dim lngPrevItem As Long
  3.         If lngPrevItem = msglist.Items.Count - 1 Then lngPrevItem = -1
  4.         lngPrevItem = lngPrevItem + 1
  5.         SendKeys.Send(msglist.Items.Count = (lngPrevItem))
  6.         SendKeys.Send("{ENTER}")
  7.     End Sub
  8.  
Anyone got any idea on fixing this ?

Then another question,
How do I let - (just this timer/application, as it's for a multiplayer game) - wait 100 milliseconds after the first Sendkeys ?

Regards,
Evolution445
Jul 20 '07 #7
Killer42
8,435 Expert 8TB
This... "msglist.Items.Count = (lngPrevItem)" is a comparison, which will return True or False. So that's what I would expect to be sent by the SendKeys in line 5.
Jul 21 '07 #8
Oh, i see, stupid me !

It's now working as it should, thanks all :)
Jul 22 '07 #9
Killer42
8,435 Expert 8TB
Oh, i see, stupid me !

It's now working as it should, thanks all :)
:) I wish I had a dollar for every "stupid" bug I've created.

Glad we could help.
Jul 22 '07 #10
Killer42
8,435 Expert 8TB
Jolie, I've split off your message to this new discussion thread, so it is more likely to attract a response.
Aug 23 '07 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Mad | last post by:
Hello to all, I am new to vb6 and I have been trying to make a listbox with a horizontal and vertical scrollbar. For example, like the one on the program Address book that is found on all Windows...
1
by: madhu | last post by:
Hello I am new to vb.net 1) I have 2 listboxs Named as list1 and list2 and 3 Buttons add and the next one is remove buttons, read button on click of add button the selected item from the...
2
by: Bill Dudek | last post by:
Does vb.net have a listbox with a checkbox style like in vb6? I didn't even see a style option under properties. I'm just starting in .net and am trying to port an existing application over. ...
3
by: BVH | last post by:
Hi, I'm currently having a problem with a vb6 project I once wrote that needs to be converted to vb.NET. The problem is as follows : On a form I have a listbox and two commandbuttons. The 2...
21
by: Bilal Abbasi | last post by:
I realize that you can add items to a list box as objects so you can have access to more than just one property like the itemindex in vb6. Question I have is how do I cause the listbox to show a...
4
by: CR | last post by:
In VB6 if I wanted to display a group of records, and possibly allow the user to select one or more records, I would use the ListBox. For example suppose I wanted to display something like this: ...
5
by: Steven Blair | last post by:
I need to write an ASP.NET application which can do the following: 1. Create a socket which will stay alive and continously read data. 2. The data read needs to be displayed on the webpage. 3....
5
by: newsaboutgod | last post by:
I think VB.NET drives some people crazy because some simple VB6 things seem so hard. Here is some VB6 code: 'Write CSV File open "c:\test.csv" for output as #1 write#1, "1","2","3","4","5"...
1
by: Sunray | last post by:
I have a form called the sales form and i have 2 sets of listboxes So what happens is. i add items form the bottom set of list boxes which are bound to a data base to the top set of list boxes which...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.