Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old February 3rd, 2005, 08:52 AM
FOxKid FOxKid is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 2 FOxKid User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 24 m 50 sec
Reputation Power: 0
Angry Trying to copy contents of list box into textbox

Ok im basically trying to get it same that i can copy information from a list box to text box same that i can save the informaton in a .txt file. and since i cant work out how the hell to get the information to save from a list box iv come up with this only problem is i cant get all of the list to copy across i only get the 1st one selected.

Code:
 
Private Sub Command1_Click()
Dim i As Integer
If List1.ListIndex = -1 Then Exit Sub
For i = List1.ListCount - 1 To 0 Step -1
If List1.Selected(i) = True Then
Text1.Text = List1.list(i)
List1.RemoveItem i
End If
Next i
 
End Sub
Private Sub Form_Load()
With List1
.AddItem "1"
.AddItem "2"
.AddItem "3"
.AddItem "4"
End With
End Sub


im unsure what is wrong as im only a beginner at this so if anyone can help me with this code or tell me how to save information from list boxes to .txt file would be gratful

Reply With Quote
  #2  
Old February 3rd, 2005, 12:39 PM
ssk ssk is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 14 ssk User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 54 m
Reputation Power: 0
Private Sub Command1_Click()
Dim i As Integer
If List1.ListIndex = -1 Then Exit Sub
For i = List1.ListCount - 1 To 0 Step -1
If List1.Selected(i) = True Then
Text1.Text = List1.list(i) <----- THIS IS THE ERROR !!!
List1.RemoveItem i
End If
Next i

The error line replaces the text of the textbox in every attempt of the loop..... replace the line with Text1.Text = Text1 & " " & List1.Text and ur job is done

Reply With Quote
  #3  
Old February 4th, 2005, 04:38 AM
FOxKid FOxKid is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 2 FOxKid User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 24 m 50 sec
Reputation Power: 0
not exactly what i wanted but it closer i want the text to be transered so it is displayed in the text box as it was in the list box not all on same line but thanx anyway

Reply With Quote
  #4  
Old February 6th, 2005, 08:15 PM
Journeyman Journeyman is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 20 Journeyman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 19 m 18 sec
Reputation Power: 0
Set txtfile = fso.CreateTextFile(Path of your file here, True)
txtfile.WriteLine (Your variable here)
txtfile.Write (Your variable here)
txtfile.Close

What I would do is create a string variable to capture the list box, your loop should populate the string variable then place the variable in the code above,

Note: WritLine creates the line then returns a new line, where write just writes the line with no return.

Also note you will need this in the general declaration section of you project.
Dim fso As New FileSystemObject

Hope this helps

Journeyman

Reply With Quote
  #5  
Old February 6th, 2005, 11:32 PM
ssk ssk is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 14 ssk User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 54 m
Reputation Power: 0
Quote:
Originally Posted by FOxKid
not exactly what i wanted but it closer i want the text to be transered so it is displayed in the text box as it was in the list box not all on same line but thanx anyway


well for that set multiline for the textbox = True in properties and replace the line (Text1.Text = Text1 & " " & List1.Text) with Text1.Text = Text1 & " " & vbCrlf & List1.Text

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingVisual Basic Programming > Trying to copy contents of list box into textbox


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT