Ahhh... creating a text file...
<newbieness mode>
Hey everyone...
How do I create a text file for a username and password to be stored in (its for a Maths program... doesn't need to be secure)
Thanks,
-Fubar
</newbieness mode>
I wanted to be a procrastinator, but never got round to it.
<i> Remove NOSPAM_ to email me </i>
Re: Ahhh... creating a text file...
refer http://vblib.virtualave.net, there is a function that write text string array into text file called WriteFileText in vbFileIO as the activeX DLL.
so, in order to store username and password, do this
dim data(0) as string
dim vbFileIO as new vbFileIO
data(0) = "username" & " " & "password
vbFileIO.WriteFileText(filename,data)...
HTH
Re: Ahhh... creating a text file...
You can use this quick solution for storing your names and passwords in a textfile.
Open App.Path & "pass.txt" for append as #1
print #1, txtUser.Text
print #1, txtPass.text
Close #1
Re: Ahhh... creating a text file...
ok, that kinda works but what i need is a seperate text file for each student... and it creates an "MathsTutitionbob" (when Username = bob)
plus, it stores it in a directory below the one i want... grrr... :)
But thanks alot!
I wanted to be a procrastinator, but never got round to it.
<i> Remove NOSPAM_ to email me </i>
Re: Ahhh... creating a text file...
dim sFileName as string
dim sFilePath as string
sFileName = "MathsTuition" & txtUser.Text
sFilePath = App.Path & "\yourDir\"
Open sFilePath & sFileName for Output as #1
print #1, txtUser.Text
print #1, txtPass.text
Close #1
Re: Ahhh... creating a text file...
I think this is closer to what you wanted. Missed the \ earlier.
Open App.Path & "\" & txtUser.Text & ".txt" for Output as #1
print #1, txtUser.Text
print #1, txtPass.text
Close #1
Re: Ahhh... creating a text file...
'you can hard code the path
dim yourPath as string
yourpath = "c:\yourdir\yoursubdir\"
'you should chek for its existance:
if dir(yourpath,vbdirectory) <> "" then
Open yourpath.Path & "pass.txt" for append as #1
print #1, txtUser.Text
print #1, txtPass.text
Close #1
end if
'and if you want a different txt file for each student
'(you sure you want?)
you can do as follow:
Option Explicit
Dim yourpath As String
Private Sub Command1_Click()
'use username to write a file
yourpath = "c:"
Open yourpath.Path & "\" & Text1.Text For Output As #1
'if it does not exist= created.
'if it exists= replaced
'store only password
Print #1, txtPass.Text
Close #1
End Sub
Private Sub Command2_Click()
Dim vntInput As String
'to retrieve:
yourpath = "c:"
If Dir(yourpath & "\" & Text1.Text) <> "" Then
Open yourpath.Path & "pass.txt" For Input As #1
Line Input #1, vntInput
Close #1
'in vbinput you have passowrd
If Text2.Text <> vbinput Then
MsgBox "Wrong Password"
End If
Else
MsgBox "user not registered. Create the file, before."
End If
End Sub
Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, Bruno Paris and all the other wonderful people who made and make Codeguru a great place. Come back soon, you Gurus.