VB Help [Another problem] - Printable Version -Shoutbox (https://shoutbox.menthix.net) +-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58) +--- Forum: Skype & Technology (/forumdisplay.php?fid=9) +---- Forum: Tech Talk (/forumdisplay.php?fid=17) +----- Thread: VB Help [Another problem] (/showthread.php?tid=50449) VB Help [Another problem] by Reaper on 09-13-2005 at 06:01 PM
im working on my A2 computing project, and i want to put a login dialog on my system. code: this is the code given by the VB app RE: VB Help by matty on 09-13-2005 at 06:48 PM
code: RE: VB Help by Reaper on 09-13-2005 at 06:52 PM
text1.text is the name of the file. do i put the whole path name or just the name of the file? RE: VB Help by RaceProUK on 09-13-2005 at 09:14 PM Most of the time you need the full name to the file. As for writing the username and password, use comma-separated values (or maybe the pipe | character). I also recommend hashing the password before storing it - you won't need MD5, a simple hash like the one MSN uses to encode e-mail addresses will suffice. RE: VB Help by Reaper on 09-13-2005 at 10:00 PM
ok i got a few problems, when i type guest, qwerty in the file it doesnt login in. RE: VB Help by brian on 09-13-2005 at 10:25 PM
How do you mean doesn't work, what you are supposed to do is: RE: VB Help by Reaper on 09-13-2005 at 10:29 PM
i just wanna test it with the one login info, so i dont need to do the loop and split do i? code: RE: VB Help by matty on 09-13-2005 at 11:08 PM Heres an example for you. RE: RE: VB Help by CookieRevised on 09-14-2005 at 06:33 AM
quote:Unless you execute the program from within the same folder as where the file is, you always need the give the full path. quote: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: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:Because there was 1 field missing in the file. quote: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:It didn't work because he is using "Input", and not "Line Input". quote: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:It contains a big bad ----------------------------------------- Reaper66613, about your posted Form code: 1) Since you used "Input #1, strUsername, strPassword", login.txt needs to contain: code: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:is the same as code:and not, as intended, as code: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 ) Also note that the login.txt file is expected to be in the following format: code: code: 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 RE: VB Help by Reaper on 09-14-2005 at 02:58 PM
omg cookie RE: VB Help [Another problem] by Reaper on 09-15-2005 at 05:17 PM
i was just sorting out my systme, and i thought about adding an option to create a user. so how would i go about doing this? code: RE: VB Help [Another problem] by RaceProUK on 09-15-2005 at 08:25 PM Surely it should be 'Open Filename For Append As #1'? RE: VB Help [Another problem] by Reaper on 09-15-2005 at 09:17 PM
lol yup that works but i get a " at the beginning of the username and end of password for example: RE: RE: VB Help [Another problem] by CookieRevised on 09-16-2005 at 06:55 AM
quote: Issue 1 Why do you assign txtUsername.Text and txtPassword.Text to variables and then immediatly write those variables? That's rather useless... Just write out txtUsername.Text and txtPassword.Text directly... code: Issue 2 (main issue of your question) As I said several times before (if not in all my replies): LOOK UP WHAT EACH FUNCTION DOES BEFORE USING IT!!! I provided links to the online MSDN Library in my previous replies, USE THEM! If you would have read the online help of "Input #1" and read the pages like you should have and thus also clicked on "See Also" and the various "Examples" you would have seen that there are two possible commands to write to files: "Write" and "Print"... The difference is explained in great detail on the helppages (or in the help files of VB6). Also the difference can be seen quite easly if you just try it out and see the result by opening login.txt in notepad. Issue 3 Study the complete source I gave to you. Ask yourself questions like why did he do that? Why did he used that command and not that one? And above all: what does that line exactly do? I say this (again) because you missed the big point about delimiting (or in this case not delimiting) the data you write. Line Input, which you used to read out the file, doesn't care about delimiters; Line Input reads a complete line. This includes any characters you used for delimiting the two fields as that delimiter is nothing more then a character itself: Reading data: login.txt: username, password Reading out: => Line Input #1, MyString1 MyString1 will contain: username, password (there is no MyString2 because 1) the login.txt only contains one line and 2) because Line Input reads whole lines literally, not fields) => Input #1, MyString1, MyString2 MyString1 will contain: username MyString2 will contain: password (this is because the comma is a delimiter used in VB6 to split up seperate fields when _reading_ data out of a file) login.txt: username@password Reading out: => Line Input #1, MyString1 MyString1 will contain: username@password => Input #1, MyString1, MyString2 MyString1 will contain: username@password MyString2 will contain nothing, in fact this input statement will produce an error since there is no second MyString2 field (the @ character is not interpreted as a delimiter of fields). login.txt: "username", "password" Reading out: => Line Input #1, MyString1 MyString1 will contain: "username", "password" (Thus, as you can see, the Line Input statement reads an entire line literally. It doesn't care about delimiters, quotes or whatever) => Input #1, MyString1, MyString2 MyString1 will contain: username MyString2 will contain: password (the comma is interpreted as delimiter AND note that the quotes around the fields aren't returned; they are also interpreted) login.txt: "username, password", "beep" => Input #1, MyString1, MyString2 MyString1 will contain: username, password MyString2 will contain: beep (Because the first comma in the file is part of the string here and thus not a delimiter. The second comma is a delimiter as it is no part of any field.) Writing data: Write #1, "Hello" the file will contain: "Hello" (note the quotes) Write #1, "Hello,world" the file will contain: "Hello,world" (note the quotes encapsuling the whole string you just wrote and note that the comma is part of what you wrote) Write #1, "Hello@world" the file will contain: "Hello@world" (note the quotes) Write #1, "Hello", "World" the file will contain: "Hello","World" (note the quotes AND the use of two seperate fields and thus also the comma which isn't part of any of the two fields you've written; it is the seperator of the two variables. As seperator you can also use the ";" character when using the Write statement. But a comma will always be used as delimiter of the fields inside the file you've written to) Write #1, "Hello", "World"; "Beep" the file will contain: "Hello","World","Beep" (note the mixed use of "," and ";" to seperate the fields in the code AND the comma inside the file which is always used when using the Write statement) ----- Print #1, "Hello" the file will contain: Hello (note that there are no quotes) Print #1, "Hello,world" the file will contain: Hello,world (note again the lack of quotes and note again that the comma was part of what you told 'Print' to write) Print #1, "Hello@world" the file will contain: Hello@world (note that there are no quotes) Print #1, "Hello", "World" the file will contain: Hello World (note the 8 spaces! This is the 'delimeter' used when you use a comma to seperate fields because a comma means: put a tab between the two fields (and a tab=8 spaces) when using it with the Print statement.) Print #1, "Hello"; "World" the file will contain: HelloWorld (note the lack of spaces or delimeter. ";" means concatenate the fields; "World" is just written right after "Hello". the use of ";" in this case is the same as using & (well almost but I'm not going into that atm)) Print #1, "Hello", "World"; "Beep" the file will contain: Hello WorldBeep (note the difference between the output from this Print statement and the previous Write statement) ----- So if your file contains: guest|qwerty You read it out with: Line Input #1, MyStringVariable or Input #1, MyStringVariable (and you need to either split the string up yourself by code and comparing the two parts seperatly (like in Matty's code) or compare the whole string directly and at once to a madeup/concatenated variable (like in my code)) You write such lines to the file with: Print #1, "guest|qwerty" Thus to spoon-feed you: Print #1, txtUsername.Text & "|" & txtPassword.Text or by splitting everything up: Print #1, txtUsername.Text; Print #1, "|"; Print #1, txtPassword.Text mind the use of ";" here. It means: do not add a carriage return after the thing you wrote to the file (again stuff you can find in the help files) or by using a premade variable: MyStringVariable = txtUsername.Text & "|" & txtPassword.Text Print #1, MyStringVariable ------------------------ quote:pretty pleeeeeeeaaaaaase learn to find out things by yourself *snif*. This question clearly shows that you don't take the time to find out things. Did you even had a look at the 'Project3' which I gave to you in my previous post???? The password textbox is masked there. Now, instead of plainly asking about how you do that, why don't you look at the properties of that textbox yourself (right click and choose 'properties') . And pleeeeeaaaase go fetch a book in your local library about VB... ------------------------ I'm glad to be able to help out, but I can't keep spoon-feeding you like this though (and putting a hell of a lot of time in making these kind of posts *Segosa once asked *), you need to learn to find this stuff out by your own. And also important: learn the basics first (eg: that masked password question). Do not be afraid to put some time in reading helpfiles and understanding them and trying some stuff out. In fact all that is mandatory if you want to learn something and it is even much quicker and more rewarding in the end than asking such stuff on forums. To more you learn looking things up yourself, to more and quicker you'll learn about that stuff and the more you will be able to look at the right place the next time or to solve a problem by deduction. RE: VB Help [Another problem] by Reaper on 09-16-2005 at 01:50 PM
thanks again cookie |