What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Skype & Technology » Tech Talk » VB Help [Another problem]

VB Help [Another problem]
Author: Message:
CookieRevised
Elite Member
*****

Avatar

Posts: 15517
Reputation: 173
– / Male / Flag
Joined: Jul 2003
Status: Away
RE: RE: VB Help
quote:
Originally posted by raceprouk
Most of the time you need the full name to the file.
Unless you execute the program from within the same folder as where the file is, you always need the give the full path.

quote:
Originally posted by raceprouk
As for writing the username and password, use comma-separated values (or maybe the pipe | character).
It depends on how you're going to read the file. If you use the "Input" command, then you must seperate the fields with a comma. If you use the "Line Input" command (which reads a whole line instead until the next delimeter), it doesn't matter what you use to seperate it as long as you use that same seperator in your code when you extract the parts you need from it (Matty's code) or use it to build up your comparisson string (my alternative code).

quote:
Originally posted by Reaper66613
ok i got a few problems, when i type guest, qwerty in the file it doesnt login in.
Not because you entered something wrong in the file or read it out wrongly (aka the reading routine). It is because you didn't handle it correctly higher-up in your code. See my notes below about your code...

quote:
Originally posted by Reaper66613
when i put just guest in the file, i get the error: Run-time error "62"
Input past end of file.
when i click debug, the line Input #1, strUsername, strPassword is highlighted. when i put my mouse over strUsername, it ses strUsername = "guest" but when i do it over strPassword it says strPassword""
Because there was 1 field missing in the file.

quote:
Originally posted by Reaper66613
also the pipe character doesnt work
That doesn't work when you use "Input #1, Variable1, Variable2". If you use that then you need 2 fields in the file. A pipe symbol doesn't qualify as a delimeter, only a comma does (when reading field by field).

If you wanna use a pipe symbol you need to read the whole line at once with "Line Input #1, Variable". In fact instead of a pipe symbol you can use whatever character you like (or none at all for that matter) as the line is interpreted as a whole, not as seperate fields...

quote:
Originally posted by brian
How do you mean doesn't work, what you are supposed to do is:
It didn't work because he is using "Input", and not "Line Input".

quote:
Originally posted by brian
make a file with "guest|qwerty" in it
open the file, loop through it, split each LINE with |.
each line will have a user/pass, so you choose the line/user you need and get its pass, then check.
Much to complicated (not to mention slow string and/or array manipulations). You don't need to split anything and then check each fields individually. See my alternative code.

quote:
Originally posted by Matty
Heres an example for you.
It contains a big bad wolvebug :P You forgot to close your file when a match is found ;)


-----------------------------------------


Reaper66613, about your posted Form code:

1) Since you used "Input #1, strUsername, strPassword", login.txt needs to contain:
code:
guest,qwerty
2) You need to adapt many other parts of the example code to let it work eventually. What people have provided for you in this thread here is the base for checking a file with some login info: the basic open file and checking for some matches. You need to adapt the example source from VB to incooperate that. Aka adapt the cmdOK_Click() routine because at the moment the file login.txt is simply read out when you load the form and checked against empty strings as you don't have anything entered yet in the textboxes (because the form isn't shown yet).

The code provided in this thread does not go into the Form_Load procedure but must be incooperated into cmdOK_Click()...

Also:
code:
Dim strUsername, strPassword As String
is the same as
code:
Dim strUsername As Variant
Dim strPassword As String
and not, as intended, as
code:
Dim strUsername As String
Dim strPassword As String
Never declare variables on one line, unless you state for each individual one the proper data type. strUsername is declared "As Variant" because there is no explicit data type given.


-----------------------------------------


Alternative on Matty's code (use/copy this Command1_Click() procedure over Matty's example code. It is not meant to be put in your Form, Reaper66613)
Note that this doesn't use any heavy string manipulations, nor splits or whatever (and it does close the file when a match is found :p)
Also note that the login.txt file is expected to be in the following format:
code:
guest|qwerty
login2|password2
login3|password3
login4|password4
code:
Private Sub Command1_Click()

    Dim strPath        As String
    Dim strText        As String
    Dim strMatchSearch As String
    Dim blnMatchFound  As Boolean

    strMatchSearch = txtUsername.Text & "|" & txtPassword.Text
    blnMatchFound = False

    strPath = App.Path
    If Right(strPath, 1) <> "\" Then strPath = strPath & "\"

    Open strPath & "text.txt" For Input As #1
        Do Until EOF(1) Or blnMatchFound
            Line Input #1, strText
            If strMatchSearch = strText Then blnMatchFound = True
        Loop
    Close #1

    If blnMatchFound Then
        MsgBox "Username/Pass match"
    Else
        MsgBox "Username/Pass not found"
    End If

End Sub


Help on MSDN Library (=official help files, which explain in full detail each command of VB) about:
Input #1
Line Input #1



For the 2 examples (one based on Matty's approach (project2), as listed above. The other the full working source of the VB example (project3)) see attached zip -------vv

.zip File Attachment: Example2-3.zip (4.04 KB)
This file has been downloaded 70 time(s).

This post was edited on 09-14-2005 at 07:51 AM by CookieRevised.
.-= A 'frrrrrrrituurrr' for Wacky =-.
09-14-2005 06:33 AM
Profile PM Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
VB Help [Another problem] - by Reaper on 09-13-2005 at 06:01 PM
RE: VB Help - by matty on 09-13-2005 at 06:48 PM
RE: RE: VB Help - by CookieRevised on 09-14-2005 at 06:33 AM
RE: VB Help - by Reaper on 09-13-2005 at 06:52 PM
RE: VB Help - by RaceProUK on 09-13-2005 at 09:14 PM
RE: VB Help - by Reaper on 09-13-2005 at 10:00 PM
RE: VB Help - by brian on 09-13-2005 at 10:25 PM
RE: VB Help - by Reaper on 09-13-2005 at 10:29 PM
RE: VB Help - by matty on 09-13-2005 at 11:08 PM
RE: VB Help - by Reaper on 09-14-2005 at 02:58 PM
RE: VB Help [Another problem] - by Reaper on 09-15-2005 at 05:17 PM
RE: VB Help [Another problem] - by RaceProUK on 09-15-2005 at 08:25 PM
RE: VB Help [Another problem] - by Reaper on 09-15-2005 at 09:17 PM
RE: RE: VB Help [Another problem] - by CookieRevised on 09-16-2005 at 06:55 AM
RE: VB Help [Another problem] - by Reaper on 09-16-2005 at 01:50 PM


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On