Got something to write about? Check out our Article Builder.

Read Post

Advance Visual Basic

Moderators: None (Apply to moderate this forum)
Number of threads: 797
Number of posts: 1684

This Forum Only
Post New Thread

Report
Need help on list and text boxes Posted by mOski on 18 May 2008 at 3:12 AM

I'm making a program that has 2 list boxes and 4 text boxes.In the program if you click an item on one of the list box the first text box's text is equal to a text. Now what I want is that The next time I click on an item on one of the 2 list boxes, the next item will be added to the second text box, then the next click the item will be added to the third text box and so on but everytime I click on an item its always added on the first text box.

I tried everything I know and I still can't do it...

hope someone here can help.....
Reply
Report
Re: Need help on list and text boxes Posted by dokken2 on 19 May 2008 at 8:12 AM
Private Sub Command1_Click()
  'INIT LIST1
  With Me.List1
    .AddItem "a"
    .AddItem "b"
    .AddItem "c"
  End With
  'INIT LIST2
  With Me.List2
    .AddItem "1"
    .AddItem "2"
    .AddItem "3"
  End With
  'INIT TEXT1-4
  Me.Text1.Text = ""
  Me.Text2.Text = ""
  Me.Text3.Text = ""
  Me.Text4.Text = ""
End Sub

Private Sub List1_Click()
  AddText Me.List1.Text
End Sub

Private Sub List2_Click()
  AddText Me.List2.Text
End Sub

Private Sub AddText(ByVal txt As String)
  If Me.Text1.Text = "" Then Me.Text1.Text = txt: Exit Sub
  If Me.Text2.Text = "" Then Me.Text2.Text = txt: Exit Sub
  If Me.Text3.Text = "" Then Me.Text3.Text = txt: Exit Sub
  If Me.Text4.Text = "" Then Me.Text4.Text = txt: Exit Sub
End Sub



here's a 2nd way-
AddText "init" to restart adding text to textbox 1-4

Private Sub AddText(ByVal txt As String)
  Static x As Byte
  If txt = "init" Then x = 0:Exit Sub
  x = x + 1
  Select Case x
    Case 1: Me.Text1.Text = txt
    Case 2: Me.Text2.Text = txt
    Case 3: Me.Text3.Text = txt
    Case 4: Me.Text4.Text = txt
  End Select
End Sub
Reply




corner
© 1996-2008. All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Publisher: Lars Hagelin.
bootstrapLabs Logo A bootstrapLabs project.