Help with some code.

jctjepkmea

Member
Joined
Apr 15, 2009
Messages
5
Programming Experience
Beginner
hello is here any one who can help me.
I have this code but it stops on the rule withe the*..* and vb makes that rule Yellow. could you help me??

Thanks
VB.NET:
    Dim namefile As String
        namefile = TextBox1.Text
        If TextBox1.Text = "" Then
            MsgBox("fil in a username!")
        Else
            If TextBox2.Text = "" Then
                MsgBox("fil in a password")
            Else
               *Write(CurDir() & "\Accounts\" & namefile & ".txt")*
                Print(namefile, TextBox1.Text)
                Print(namefile, TextBox2.Text)
            End If
        End If
 
Assuming I'm even interpreting your vb yellow rule explanation (Ok, I have no clue what you're even talking about)

From your code it looks like you want to write the string to a file, which you're not using a StreamWriter to do so, unless Write() is a sub that has that code.

Could you explain a little better what you're trying to do.
 
I am trying to write a username and password to a txt file witch have the same name as the username. here is a print screen from the error

jwosfileerror.png
 
Try
VB.NET:
MsgBox(CurDir() & "\Accounts\" & namefile & ".txt")*

The Write Sub is not for displaying data on the screen. If you are unsure what a sub does use Intellisense. The summary for the Write sub is the following:

Writes data to a sequential file. Data written with Write is usually read from a file by using Input.
 
Wow, disregard that post, I totally didnt see you wrote anything.

You are trying to write to a file so you are about there. But if you look at Intellisense when you are on the Write sub you will see that it accepts an integer as a parameter. This should be an indicator that you are using the wrong sub.

Try this
VB.NET:
        Try
            Dim strFile As New IO.StreamWriter(CurDir() & "\Accounts\" & namefile & ".txt")*)

            strFile.WriteLine(TextBox1.Text)
            strFile.WriteLine(TextBox2.Text)

            strFile.Close()
        Catch e As Exception
            MsgBox("An Error Occured, Please Try Again.")
        End Try
 
<user id="CtrlAltPhreak">
<password>passwordhash1234</password>
</user>
<user id="jctjepkmea">
<password>passwordhash4567</password>
</user>


This would be a more flexible solution as to add in extra information afterwards (e.g. to store a users age or date of birth) you could just add in an element (node?).

e.g.

<user id="CtrlAltPhreak">
<password>passwordhash1234</password>
<age>21</age>
</user>
 
Back
Top