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

Pages: (2): « First « 1 [ 2 ] Last »
VB Help [Another problem]
Author: Message:
Reaper
Veteran Member
*****

Avatar

Posts: 1393
Reputation: 23
35 / Male / Flag
Joined: Jun 2004
O.P. RE: VB Help [Another problem]
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?
would i have to write the information to a file? if so how :P?

i have written a code i think i got the basics, but i want to know how to put the information in the file in the format userame|password
the code doesnt work, as in i type in the info and click ok but it just disappears and nothing appears in the txt file. also how do i mask the password characters?

code:
Dim Filename As String

Private Sub cmdCancel_Click()
Unload Me
End Sub

Private Sub cmdOK_Click()
    Dim Username As String
    Dim Password As String
    Username = txtUsername.Text
    Password = txtPassword.Text
    Open Filename For Append As #1
    Write #1, Username, Password
    Close #1
    txtUsername.Text = " "
    txtPassword.Text = " "
    txtUsername.SetFocus
End Sub

Private Sub Form_Load()
    Filename = App.Path & "\login.txt"
End Sub


This post was edited on 09-15-2005 at 09:19 PM by Reaper.
09-15-2005 05:17 PM
Profile E-Mail PM Find Quote Report
RaceProUK
Elite Member
*****

Avatar

Posts: 6073
Reputation: 57
39 / Male / Flag
Joined: Oct 2003
RE: VB Help [Another problem]
Surely it should be 'Open Filename For Append As #1'?
[Image: spartaafk.png]
09-15-2005 08:25 PM
Profile PM Web Find Quote Report
Reaper
Veteran Member
*****

Avatar

Posts: 1393
Reputation: 23
35 / Male / Flag
Joined: Jun 2004
O.P. RE: VB Help [Another problem]
lol yup that works but i get a " at the beginning of the username and end of password for example:

"123456|blah"

how do i remove it, and how do i mask the password?

[Edit] changed the code in prevous post

This post was edited on 09-15-2005 at 09:20 PM by Reaper.
09-15-2005 09:17 PM
Profile E-Mail PM Find Quote Report
CookieRevised
Elite Member
*****

Avatar

Posts: 15519
Reputation: 173
– / Male / Flag
Joined: Jul 2003
Status: Away
RE: RE: VB Help [Another problem]
quote:
Originally posted by Reaper66613
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?
would i have to write the information to a file? if so how :P?

i have written a code i think i got the basics, but i want to know how to put the information in the file in the format userame|password
the code doesnt work, as in i type in the info and click ok but it just disappears and nothing appears in the txt file. also how do i mask the password characters?

code:
Dim Filename As String

Private Sub cmdCancel_Click()
Unload Me
End Sub

Private Sub cmdOK_Click()
    Dim Username As String
    Dim Password As String
    Username = txtUsername.Text
    Password = txtPassword.Text
    Open Filename For Append As #1
    Write #1, Username, Password
    Close #1
    txtUsername.Text = " "
    txtPassword.Text = " "
    txtUsername.SetFocus
End Sub

Private Sub Form_Load()
    Filename = App.Path & "\login.txt"
End Sub


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:
Dim Username As String
Dim Password As String
Username = txtUsername.Text
Password = txtPassword.Text
......
Write #1, Username, Password


===>

Dim Username As String
Dim Password As String
Username = txtUsername.Text
Password = txtPassword.Text

......
Write #1, txtUsername.Text, txtPassword.Text





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:
Originally posted by Reaper66613
how do mask the password?
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...  :S


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


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 :p*), 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. ;)

This post was edited on 09-16-2005 at 07:14 AM by CookieRevised.
.-= A 'frrrrrrrituurrr' for Wacky =-.
09-16-2005 06:55 AM
Profile PM Find Quote Report
Reaper
Veteran Member
*****

Avatar

Posts: 1393
Reputation: 23
35 / Male / Flag
Joined: Jun 2004
O.P. RE: VB Help [Another problem]
thanks again cookie :D
lol i think ive had enough of your spoon feeding for now :P
i guess i better use the MSDN from now on

thanks :D
09-16-2005 01:50 PM
Profile E-Mail PM Find Quote Report
Pages: (2): « First « 1 [ 2 ] Last »
« Next Oldest Return to Top Next Newest »


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