-
Nov 5th, 2007, 07:36 PM
#1
Thread Starter
Member
How can I use a specified information saved in a text file?
I have a program that uses this code to write the info entered by the user in a text file:
Private Sub Command1_Click()
n = Text1.Text
a = Text2.Text
Open " h:\RECORDS.txt" For Append As #7
Write #7, n, a
Close #7
MsgBox "Done!"
End Sub
I am using this code to put the first field (na) of info of the text file in a combobox:
Private Sub Command2_Click()
Open " h:\RECORDS.txt" For Input As #3
Do While Not EOF(3)
Input #3, na, ag
Combo1.AddItem na
Loop
Close #3
How can I make my program so it only goes to the next form (ex. form2) when the second field of info (ag) in the text file is entered in the second textbox (a)?
Last edited by incognito_301; Nov 5th, 2007 at 07:47 PM.
-
Nov 5th, 2007, 11:23 PM
#2
Frenzied Member
Re: How can I use a specified information saved in a text file?
How can I make my program so it only goes to the next form (ex. form2) when the second field of info (ag) in the text file is entered in the second textbox (a)?
This is not clear enough/ Are you asking about the Text2 or the Combo Box ?
-
Nov 6th, 2007, 10:54 AM
#3
Thread Starter
Member
Re: How can I use a specified information saved in a text file?
Originally Posted by zeezee
This is not clear enough/ Are you asking about the Text2 or the Combo Box ?
Let's say I have a number in my text file (for example 100).
Code:
text file:
"name1", 9000
"name2", 300
"name3", 100
"name3", 5
The user chooses his/her name , which is name3 in this case,in a combo box first and then he should enter "100" in the text file or else it won't go to the next form.
Last edited by incognito_301; Nov 6th, 2007 at 11:10 AM.
-
Nov 6th, 2007, 11:23 AM
#4
Frenzied Member
Re: How can I use a specified information saved in a text file?
The user chooses his/her name , which is name3 in this case,in a combo box first and then he should enter "100" in the text file or else it won't go to the next form.
Its confusing again.
Ok tell me If I m right.
1.You got Names in the combo box.
2.User select one of the Names
3. Then User enter a number in the Text File. (or text box?)
4. If its the right number , then proceed, else dont go to next form?
-
Nov 6th, 2007, 11:39 AM
#5
Thread Starter
Member
Re: How can I use a specified information saved in a text file?
Originally Posted by zeezee
Its confusing again.
Ok tell me If I m right.
1.You got Names in the combo box.
2.User select one of the Names
3. Then User enter a number in the Text File. (or text box?)
4. If its the right number , then proceed, else dont go to next form?
Sorry. It is pretty confusing the way I explained,
Yes what I meant was eacly what you said:
1. I got Names in the combo box.
2. User select one of the names
3. Then User enter a number in the Textbox.
4. If its the right number (IF IT IS THE NUMBER IN THE TEXT FILE ) , then proceed, else dont go to next form.
-
Nov 6th, 2007, 12:08 PM
#6
Frenzied Member
Re: How can I use a specified information saved in a text file?
Ah guessed write.
here is something you can do, when you load the combo. you already read the file, so what you need to do is, keep the number in an array where the array index relates combo list index. This is like UserName Password thing right?
If your this additional data is number ,a whole number, there is another thing you can do. There is a property called ItemData in the combo box. Its an array too. you can kkep the data there, If and Only If its a Long Data. Because ItemData is a Long Array.
Here how you can do it
Code:
Private Sub Command2_Click()
Dim na As String
Dim ag As Long
Open "c:\test.txt" For Input As #3
Do While Not EOF(3)
Input #3, na, ag
Combo1.AddItem na
Combo1.ItemData(Combo1.NewIndex) = ag
Loop
Close #3
End Sub
And please declare your varibles before using and use Option Explicit in every module.
-
Nov 8th, 2007, 06:51 PM
#7
Thread Starter
Member
Re: How can I use a specified information saved in a text file?
Originally Posted by zeezee
Ah guessed write.
Here how you can do it
Code:
Private Sub Command2_Click()
Dim na As String
Dim ag As Long
Open "c:\test.txt" For Input As #3
Do While Not EOF(3)
Input #3, na, ag
Combo1.AddItem na
Combo1.ItemData(Combo1.NewIndex) = ag
Loop
Close #3
End Sub
I tried this but it gives me an error.
Code:
Input past the end of file [and highlights:]
Input #3, na, ag
This is like UserName Password thing right?
Well, It is Username and password thing!
Again, the user program enters a number as a password and using this code saves the number and the name in a text file:
Code:
Private Sub Command1_Click()
n = Text1.Text
pass = Text2.Text
Open "c:\test2.txt" For Append As #2
Write #2, n, a
Close #2
Text1.Text = ""
Text2.Text = ""
Text1.SetFocus
End Sub
So When the user chooses his/her name in the combobox, he/she has to type that randomized number in a textbox, Or else the program would not show the next form.
How do I make it work?
Last edited by incognito_301; Nov 8th, 2007 at 06:58 PM.
-
Nov 8th, 2007, 09:59 PM
#8
Frenzied Member
Re: How can I use a specified information saved in a text file?
That code I gave is the code I tested with the sample text file entries in POST#3
You have not done what I said.
And please declare your varibles before using and use Option Explicit in every module.
Your write method is wrong.
what is variable a? you take password to vriable pass and insert a to the text file. You MUST use Option Explicit in every module. Its a must. And you have to Dim all your vriables.
try this code.
Code:
Option Explicit
Private Sub Combo1_Click()
MsgBox Combo1.ItemData(Combo1.ListIndex)
End Sub
Private Sub Command1_Click()
Dim n As String
Dim pass As Long
n = Text1.Text
pass = CLng(Val(Text2.Text))
Open "c:\test2.txt" For Append As #2
Write #2, n, pass
Close #2
Text1.Text = ""
Text2.Text = ""
Text1.SetFocus
End Sub
Private Sub Command2_Click()
Dim na As String
Dim ag As Long
Combo1.Clear
Open "c:\test2.txt" For Input As #3
Do While Not EOF(3)
Input #3, na, ag
Combo1.AddItem na
Combo1.ItemData(Combo1.NewIndex) = ag
Loop
Close #3
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|