|
-
Sep 22nd, 2005, 11:30 AM
#1
Thread Starter
Frenzied Member
text file question
Im using something like this to write to the text file:
VB Code:
Open "C:\test.txt" For Append As #1
Print #1, Text1.Text & "=" & Text2.Text
Close #1
which writes into the text file like this:
John=3565 (where John is the text1 name and 3565 is the text2 ID)
But now, if I make 2 more text boxes..
Text3.Text and Text4.Text, and i enter John in Text3.Text and 3565 in Text4.Text, and then i clikc Command1 button, how can i make it msgbox that the username=id is a correct combination?
otherwise i need it to msgbox that its a wrong username/ID etc..
hope you guys know what i mean, thanks in advance!!
-
Sep 22nd, 2005, 11:53 AM
#2
Fanatic Member
Re: text file question
You would need to open your C:\test.txt file for Output, read in a line with something like this:
Dim read_data As String
Line Input#1, read_data
Then, split what's read on the '=' to get what's on both sides of the equal sign with:
Dim a As String
Dim b As String
a = Split(read_data, "=") (0)
b = Split(read_data, "=") (1)
Then compare these values to what is in Text3 and Text4:
If Text3.Text = a And Text4.Text = b Then
' enter code here for what to do if they match
Else
' enter code here for what to do if they don't match
End If
Do canibals not eat clowns because they taste funny? 
-
Sep 22nd, 2005, 12:03 PM
#3
Thread Starter
Frenzied Member
Re: text file question
ok thanks i got this:
VB Code:
Private Sub Command8_Click()
Dim read_data As String
Open "C:\test.txt" For Append As #1
Line Input #1, read_data
Dim a As String, b As String
a = Split(read_data, "=")(0)
b = Split(read_data, "=")(1)
Text3.Text = a
Text4.Text = b
Close #1
End Sub
but i get bad file code on this line:
Line Input #1, read_data
(at any time the text file will only have 1 line, so i just want it to read the first line in the file)
test.txt contains this:
John=3575
-
Sep 22nd, 2005, 12:03 PM
#4
Re: text file question
 Originally Posted by doofusboy
You would need to open your C:\test.txt file for Output, read in a line with something like this:
Dim read_data As String
Line Input#1, read_data
Then, split what's read on the '=' to get what's on both sides of the equal sign with:
Dim a As String
Dim b As String
a = Split(read_data, "=") (0)
b = Split(read_data, "=") (1)
Then compare these values to what is in Text3 and Text4:
If Text3.Text = a And Text4.Text = b Then
' enter code here for what to do if they match
Else
' enter code here for what to do if they don't match
End If
One minor change I would make
VB Code:
Dim a As String
a = Split(read_data, "=")
If Text3.Text = a(0) And Text4.Text = a(1) Then
' enter code here for what to do if they match
Else
' enter code here for what to do if they don't match
End If
You really don't need the extra variable.
-
Sep 22nd, 2005, 12:13 PM
#5
Thread Starter
Frenzied Member
Re: text file question
well i get compile erorr, expected array..
VB Code:
Private Sub Command8_Click()
Dim read_data As String
Open "C:\test.txt" For Append As #1
Line Input #1, read_data
Dim a As String
a = Split(read_data, "=")
Text3.Text = a(0)
Text4.Text = a(1)
Close #1
End Sub
im just trying to get 'John' into text3.text and the ID into text4.text
anyone see where im going wrong
-
Sep 22nd, 2005, 12:23 PM
#6
Re: text file question
Dim a as string
should be
Dim a() as string
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Sep 22nd, 2005, 12:24 PM
#7
Thread Starter
Frenzied Member
Re: text file question
ok thanks i changed it but now i get: bad file mode on this line;
Line Input #1, read_data
-
Sep 22nd, 2005, 12:28 PM
#8
Re: text file question
change Append to Input
Open "C:\test.txt" For Append As #1
is for writing to the file not reading from
Open "C:\test.txt" For Input As #1
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Sep 22nd, 2005, 12:31 PM
#9
Thread Starter
Frenzied Member
Re: text file question
ooooops forgot about that, yeah works thanks alot guys!
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
|