|
-
Apr 4th, 2008, 02:28 PM
#1
Thread Starter
Lively Member
[RESOLVED] how to stop it from writing the same details
The most basic registration form , if for example I run this and enter
username1 and password1
then do that again it will display in txt file as
"username1","password1"
"username1","password1"
Is there an If statement I could use?, so if the username exists then exit sub :?
Code:
Dim savefile As Long
savefile = FreeFile()
Open "D:\a.txt" For Append As #savefile
Write #savefile, (Text1.Text); (Text2.Text)
Close #savefile
-
Apr 4th, 2008, 02:39 PM
#2
Re: how to stop it from writing the same details
It gets written twice because you are Appending, use Output instead.
Open "D:\a.txt" For Output As #savefile
-
Apr 4th, 2008, 02:47 PM
#3
Thread Starter
Lively Member
Re: how to stop it from writing the same details
 Originally Posted by Edgemeal
It gets written twice because you are Appending, use Output instead.
Open "D:\a.txt" For Output As #savefile
when i use output it only writes 1 line, so cant have multiple logins
-
Apr 4th, 2008, 02:48 PM
#4
Re: how to stop it from writing the same details
Then you really have no choice but to search the file to see if it already exists or not.
-
Apr 5th, 2008, 06:08 AM
#5
Re: how to stop it from writing the same details
And you would probably want to check to see if the username and password you are about to write already exists in the file, or it would get duplicated.
-
Apr 5th, 2008, 04:11 PM
#6
Thread Starter
Lively Member
Re: how to stop it from writing the same details
 Originally Posted by Hack
And you would probably want to check to see if the username and password you are about to write already exists in the file, or it would get duplicated.
manualy or using vbcode?
-
Apr 5th, 2008, 04:40 PM
#7
Re: how to stop it from writing the same details
You are writing a program. There is no point in doing anything manually.
-
Apr 6th, 2008, 02:13 AM
#8
Re: how to stop it from writing the same details
-
Apr 6th, 2008, 07:47 AM
#9
Thread Starter
Lively Member
Re: how to stop it from writing the same details
-
Apr 6th, 2008, 09:33 AM
#10
Hyperactive Member
Re: how to stop it from writing the same details
I have a login for my application, and they way I do it is I store all the usernames and passwords in a txt file, and at the start of my program, I load all the usernames into a string array, and all the passwords in another string array. That way anytime I need to do something with the usernames and passwords they're all right there to search through.
Code:
strBats = App.Path & "\bats\"
intFileNum = FreeFile
intIndex = 0
Open strBats & "users.sun" For Input As intFileNum
Do While EOF(intFileNum) = False
ReDim Preserve strUser(intIndex), strPassword(intIndex)
Input #intFileNum, strUser(intIndex), strPassword(intIndex)
intIndex = intIndex + 1
Loop
Close #intFileNum
Then when making changes (ie adding) to the users, you need only to make the change to the string arrays, then open the file for OUTPUT and write the arrays back in:
Code:
Open strBats & "users.sun" For Output As intFileNum
For intIndex2 = LBound(strUser()) To UBound(strUser())
Write #intFileNum, strUser(intIndex2), strPassword(intIndex2)
Next intIndex2
Close #intFileNum
The only issue with doing it this way is to work with the username and passwords together, the indexes of the two arrays must stay the same. The username stored in the 4th index corresponds to the password stored in the 4th index. Gotta be careful not to change them in your code.
Hope I could help!
-
Apr 6th, 2008, 02:32 PM
#11
Thread Starter
Lively Member
Re: how to stop it from writing the same details
I wonder why this does not work?, it was code that I used for login form,
Code:
Dim uname As String
Dim is_matched As Boolean
If (Trim(uname) = (Text1.Text)) Then
MsgBox "username exists"
Else
MsgBox "username does not exist"
is_matched = False
Open "G:\College Work ------- Updated 2008 March\new-work\savedfile.txt" For Input As #1
Do While Not EOF(1)
Input #1, uname
If Trim(uname) = Trim(Text1.Text) Then
is_matched = True
Close #1
Exit Do
End If
Loop
Close #1
Ofcourse i modified it, setup a new form for tests, not working how I wanted,
When I type username in text1 (lets say one that exists in txt file), it still says username does not exist :S, hmm, I still remain testing this, until someone can put me right
-
Apr 7th, 2008, 07:03 AM
#12
Hyperactive Member
Re: [RESOLVED] how to stop it from writing the same details
I would just load the usernames into an array, then when the user types their username do something like:
Code:
'Load users
Dim intFileNum as Integer, intIndex as Integer
Dim strUsers() as string
intfileNum = FreeFile
open [file] for input as intfilenum
do while eof(intfilenum) = false
redim preserve strUsers(intIndex)
Input #intfilenum, strUsers(intindex)
intIndex = intIndex + 1 Loop
'Check Username
for intIndex = lbound(strUsers()) to ubound(strUsers())
if strUsers(intIndex) = txtUser.text then
msgbox "User found!"
'Your Code Else
msgbox "User Not Found!" end if Next intIndex
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
|