Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

loading files

[b][red]This message was edited by thegreenstar at 2003-6-4 18:31:40[/red][/b][hr]
Thanks, Zantos, the save code you wrote works great. I modified it to append instead of output. Here it is:
Dim n As Integer
Dim strUser As String, strPass As String, strOutPut As String
Dim TempLen As Integer
For n = 1 To Len(CMD)
If Mid(CMD, n, 2) = ", " Then
strUser = Mid$(CMD, 11, n - 11)
strPass = Mid$(CMD, n + 7)
Exit For
End If
Next n
strOutPut = strUser & vbCrLf & strPass
Open "C:Program FilesGameuserlog.txt" For Append As #1
Write #1, strOutPut
Close #1


CMD = ""
TempLen = 0
strUser = ""
strPass = ""
n = 0
End Sub

It would be great if someone could write me a sub that scans userlog.txt for strUSER and strPASS (defined by the user) amongst multiple sets of these strings and if it can find a matching set will load strUSER and strPASS from the text document and put them in 2 strings: svdUSER and svdPASS. Thanks

Comments

  • ZantosZantos Posts: 139Member
    Why even bother with all that code?? If you want to save a user name and password, then retrieve it, just do something like this:
    [code]
    [blue]Private Sub[/blue] SaveFile()
    [blue]Dim[/blue] strOutput [blue]As String[/blue]
    [blue]Dim[/blue] OutFile [blue]As Integer[/blue]

    strOutput = "thegreenstar" & vbCrLf & "password"
    OutFile = FreeFile
    [blue]Open[/blue] "C:Program FilesGameuserlog.txt" [blue]For Output As[/blue] #OutFile
    [blue]Print[/blue] OutFile, strOutput
    [blue]Close[/blue] #OutFile
    [blue]End Sub[/blue]
    [/code]
    Then when you want to load this file into variables:
    [code]
    [blue]Private Sub[/blue] LoadFile()
    [blue]Dim[/blue] InFile [blue]As Integer[/blue]
    [blue]Dim[/blue] strTemp [blue]As String[/blue]
    [blue]Dim[/blue] strUser [blue]As String[/blue]
    [blue]Dim[/blue] strPass [blue]As String[/blue]
    InFile = FreeFile
    [blue]Open[/blue] "C:Program FilesGameuserlog.txt" [blue]For Input As[/blue] #InFile
    [blue]For[/blue] n = 1 [blue]To[/blue] 2
    [blue]Line Input[/blue] #InFile, strTemp
    [blue]If[/blue] n = 1 [blue]Then[/blue]
    strUser = strTemp
    [blue]Else[/blue]
    strPass = strTemp
    [blue]End If[/blue]
    [blue]Close[/blue] #InFile
    [blue]End Sub[/blue]
    [/code]
    Do something easy like that...I hope it helps!

    ..:: Zantos ::..


    : Here is my save sub, which works, and saves one line in a text document, userlog.txt, that would look like this if strUSER = thegreenstar and strPASS = password:
    :
    : "thegreenstar","password"
    :
    : Private Sub subnew()
    : Dim n As Integer
    : Dim strUser As String, strPass As String
    : Dim TempLen As Integer
    : For n = 1 To Len(CMD)
    : If Mid(CMD, n, 2) = ", " Then
    : strUser = Mid$(CMD, 11, n - 11)
    : strPass = Mid$(CMD, n + 7)
    : Exit For
    : End If
    : Next n
    : Open "C:Program FilesGameuserlog.txt" For Append As #1
    : Write #1, strUser, strPass
    : Close #1
    : CMD = ""
    : TempLen = 0
    : strUser = ""
    : strPass = ""
    : n = 0
    : End Sub
    :
    : Could someone write a sub for me that will
    : a)load userlog.txt from C:Program FilesGameuserlog.txt and scan through the whole thing and
    : b)see if svdUSER and svdPASS, inputted by the user to start this sub, compare with any two matched values (inputted in the above sub), and if so, use them as the captions of lblUSER and lblPASS respectively
    :
    : Thanks for your time & help,
    : thegreenstar
    :

Sign In or Register to comment.