Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreVisual 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 Dev Shed Forums Sponsor:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old May 16th, 2003, 08:57 AM
Battery Powered Battery Powered is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Posts: 161 Battery Powered User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 3 m 57 sec
Reputation Power: 6
text file contents to combo box

hi

I have a text file like so:

"num","name"

where 'num' is a unique number upto 5 characters and the name is small, less than 15 characters

On my form i have a combo box and text box im trying to link together as follows:

have the combo box holding the values of 'num'
and when someone selects one from the combo box the text box holds the 'name' that matches the num

I was hoping someone could throw some light on this, just getting the 'num' parts into the combo box would be a great start

All the best
B.P

Reply With Quote
  #2  
Old May 16th, 2003, 09:55 AM
computer's Avatar
computer computer is offline
echo $usertitle['computer'];
Dev Shed God 4th Plane (6500 - 6999 posts)
 
Join Date: Jan 2003
Location: UK
Posts: 6,669 computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 4 Weeks 8 h 5 m 34 sec
Reputation Power: 219
Send a message via ICQ to computer
try this:

PHP Code:
 Dim sName(20) As String
Dim sNum
(20) As String

Private Sub Form_Load()
    
Open "textfile.txt" For Input As #1
    
Index 0
    
Do Until EOF(1)
        If 
Index 19 Then
            MsgBox 
"Sorry, Only 20 Numbers/Names at one time please."vbCritical"Users"
            
Exit Do
        
End If
        
Index Index 1

        Input 
#1, sNum(Index), sName(Index)
        
Combo1.additem sNum(Index)
    
Loop
    Close 
#1

End Sub

Private Sub Combo1_Click
    call Combo1_Change
End Sub

Private Sub Combo1_Change
    Text1
.text=sName(combo1.value)
End Sub 


This is untested

please let me know if it works

BTW. This will let you have up to 20 numbers and names. any more than that and you'll have to increase the no. 20's and the no. 19 by the same amount....
__________________

Reply With Quote
  #3  
Old May 16th, 2003, 10:24 AM
Battery Powered Battery Powered is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Posts: 161 Battery Powered User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 3 m 57 sec
Reputation Power: 6
Thanks for your post

I have a problem with this tho

Private Sub cboCentreNumber_Change()
txtCentreDescription.Text = sName(cboCentreNumber.Text)
End Sub

i get a subscript out of range error

Any ideas

Thanks again
B.P

Reply With Quote
  #4  
Old May 16th, 2003, 10:28 AM
computer's Avatar
computer computer is offline
echo $usertitle['computer'];
Dev Shed God 4th Plane (6500 - 6999 posts)
 
Join Date: Jan 2003
Location: UK
Posts: 6,669 computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 4 Weeks 8 h 5 m 34 sec
Reputation Power: 219
Send a message via ICQ to computer
ooops

try this new code:
PHP Code:
 Dim sName(20) As String
Dim sNum
(20) As String

Private Sub Form_Load()
    
Open "textfile.txt" For Input As #1
    
Index 0
    
Do Until EOF(1)
        If 
Index 19 Then
            MsgBox 
"Sorry, Only 20 Numbers/Names at one time please."vbCritical"Users"
            
Exit Do
        
End If
        
Index Index 1

        Input 
#1, sNum(Index), sName(Index)
        
Combo1.AddItem sNum(Index)
    
    
Loop
    Close 
#1

End Sub

Private Sub Combo1_Click()
    
Call Combo1_Change
End Sub

Private Sub Combo1_Change()
    
Text1.Text sName(Combo1.Text)
End Sub 


ps: you might want to lock text1

Reply With Quote
  #5  
Old May 16th, 2003, 10:33 AM
Battery Powered Battery Powered is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Posts: 161 Battery Powered User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 3 m 57 sec
Reputation Power: 6
Hi

umm i cant see what you changed there apart from '.value' to '.text' which was what i was trying to start with

B.P

Reply With Quote
  #6  
Old May 16th, 2003, 10:36 AM
computer's Avatar
computer computer is offline
echo $usertitle['computer'];
Dev Shed God 4th Plane (6500 - 6999 posts)
 
Join Date: Jan 2003
Location: UK
Posts: 6,669 computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 4 Weeks 8 h 5 m 34 sec
Reputation Power: 219
Send a message via ICQ to computer
have you got anything set differently to defaults on your text and combo boxes?

and is your file in the format:

1, "hi"
2, "hello"
3, "123 testing"

and there are no blank lines at the end?

also, what system are you running it on?

Reply With Quote
  #7  
Old May 16th, 2003, 10:41 AM
computer's Avatar
computer computer is offline
echo $usertitle['computer'];
Dev Shed God 4th Plane (6500 - 6999 posts)
 
Join Date: Jan 2003
Location: UK
Posts: 6,669 computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 4 Weeks 8 h 5 m 34 sec
Reputation Power: 219
Send a message via ICQ to computer
btw. this works on my system fine (i tested it for you)

i'm running Win 2000 with VB6

Reply With Quote
  #8  
Old May 16th, 2003, 10:44 AM
Battery Powered Battery Powered is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Posts: 161 Battery Powered User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 3 m 57 sec
Reputation Power: 6
text files are all set up as you specified so that shoulndt be a problem

System is a windows2000 box


Everything works ok, it inputs to the combo box fine, its just trying to update the text box that i get the subscript out of range error from the section:

Private Sub cboSubjectRef_Change()
text1.Text = sName(combo1.Text)
End Sub


The only thing not default on the combo box is that its sytle is set to dropdown list - but the list being inputted into the combo box is working fine so i dont see that a problem

can i dim the sName and sNum too high?

Reply With Quote
  #9  
Old May 16th, 2003, 10:46 AM
computer's Avatar
computer computer is offline
echo $usertitle['computer'];
Dev Shed God 4th Plane (6500 - 6999 posts)
 
Join Date: Jan 2003
Location: UK
Posts: 6,669 computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 4 Weeks 8 h 5 m 34 sec
Reputation Power: 219
Send a message via ICQ to computer
what you set them to?

Reply With Quote
  #10  
Old May 16th, 2003, 10:48 AM
Battery Powered Battery Powered is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Posts: 161 Battery Powered User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 3 m 57 sec
Reputation Power: 6
Both set to 100, i thought i'de put it to that to be on the safe side

Reply With Quote
  #11  
Old May 16th, 2003, 10:59 AM
computer's Avatar
computer computer is offline
echo $usertitle['computer'];
Dev Shed God 4th Plane (6500 - 6999 posts)
 
Join Date: Jan 2003
Location: UK
Posts: 6,669 computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level)computer User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 4 Weeks 8 h 5 m 34 sec
Reputation Power: 219
Send a message via ICQ to computer
they should be fine, as it is reading in ok....

i'm not sure of your problem!
is the text box properties set to default?

can you attach a screenshot of your error?
Attached Images
File Type: jpg battery's thing.jpg (7.0 KB, 352 views)

Reply With Quote
  #12  
Old May 16th, 2003, 11:17 AM
Battery Powered Battery Powered is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Posts: 161 Battery Powered User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 3 m 57 sec
Reputation Power: 6
ok i have it working a differnet way now using two combo boxes : )

still not sure why it gave the error tho

thanks for your help, was great

All the best
B.P

Reply With Quote
  #13  
Old June 26th, 2003, 10:22 AM
Battery Powered Battery Powered is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Posts: 161 Battery Powered User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 3 m 57 sec
Reputation Power: 6
Hello..

Ive had to re-open this post.. as an addition to it is needed :/

I now need to be able to delete a line from this file.. and also be able to add on to it..
I have been able to add/delete records to files before on other programs ive made.. but i let VB do it and output to the file VB's way.. not in a humun-readable way like i need now

For example, the ways i have used before would output to a file something like:
 ČA šA Monitor

Where as now i need to keep the file as:
"num", "Name"
"num", "Name"

Im trying.. and strugling to be able to add the values of two text boxs (one for the number, one for the name) to the text file,
and also sruggling to try and delete one record:

For the deleting part.. a combo box holds the number or name part.. (from the code in this post)
What im trying to do is have a user select a value from a combo box.. say the number.. and then click delete and the record be deleted

Any help would be great,

Thanks,
-BP-

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming > text file contents to combo box


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread: