hg RRS feed


All replies

  • Hi, you should take a look here:

    SB Read-Write CSV Files

    Demos: Read CSV Code ZVF628  and  Write CSV Code BRP768

    • Proposed as answer by Nonki Takahashi Wednesday, March 5, 2014 9:02 AM
    • Marked as answer by litdev Sunday, March 16, 2014 7:49 PM
    Tuesday, March 4, 2014 9:26 PM
  • hgh
    • Edited by jopo786 Monday, March 10, 2014 1:58 PM
    Wednesday, March 5, 2014 7:45 PM
  • For example .....

    CRLF= Text.GetCharacter(13)+Text.GetCharacter(10)
    TextWindow.WriteLine("Input username")
    Name= TextWindow.Read()
    TextWindow.WriteLine("Input Password")
    PW= TextWindow.Read()
    CSVData= File.ReadContents(path)
    namepoint= Text.GetIndexOf(CSVData,name)
    If namepoint<>0 Then
      Start= Text.GetSubTextToEnd(CSVData,namepoint)
      Target= Text.GetSubText(start,1,CRpoint-1)+","
      If text.IsSubText(target,PW)="True" Then
        TextWindow.WriteLine("Your password is correct")
        TextWindow.WriteLine("'INCORRECT PASSWOWD ")
      TextWindow.WriteLine("'INCORRECT username ")

    Sub datalist
      TextWindow.WriteLine(" ")
      Len= Text.GetLength(Target)
      while Len>0
        NN= NN+1
        Cpoint= Text.GetIndexOf(Target,",")
        itsdata= Text.GetSubText(Target,1,Cpoint-1)
        TextWindow.WriteLine(LST[NN]+" = "+itsdata)
        Len= Text.GetLength(Target)

    Thursday, March 6, 2014 4:15 AM
  • Changed NaochanON's working code a bit :


    Target= Text.GetSubText(start,1,CRpoint-1)+","

    DelimPoint = Text.GetIndexOf(Start,",")
    DelimTarget = Text.GetSubText(Target,DelimPoint+1,Text.GetLength(PW))

    If Text.IsSubText(Target,PW) And Text.StartsWith(DelimTarget,PW) And Text.StartsWith(Target,Name) Then

    ' If text.IsSubText(target,PW)="True" Then   ' uncomment this line


    But then you MUST NOT have any character between comma and password.

    eg. Username, password, ...,          will fail  (notice the blank after the comma)

    If you can or wanna use extensions, you can also use LDFile.CSVplaceholder, LDFile.ReadCSV, LDFile.ReadCSVTransposed, LDFile.WriteCSV and LDUtilities.CSVDeliminator from LitDev Extension.

    As well as LDText.Trim to remove such leading and/or trailing White Space characters.

    Thursday, March 6, 2014 6:45 PM
  • Thanks for the code.

    I am just thinking, if the data was in a csv file (in excel 2013) such as the one below - how would you create a code for it?

    The CSV file would be saved in file in your document, for example.

    How would you check if the username matched the password from this file?

    I would appreciate any examples.

    Thanks In Advance.

    Save it as CSV file in your program directory.  EX. UserList.csv   (select ".csv" mode.)

    Change above file name from "\UserList.txt" to "\UserList.csv"

    * See "UserList.csv" using Notepad.  Data is filed like below.   

    • Edited by NaochanONEditor Thursday, March 6, 2014 11:54 PM add photo , comment
    Thursday, March 6, 2014 11:34 PM
  • I saved the csv file on my desktop- does that effect anything?

    Thanks In Advance

    You'd better  save  csv in program directory where above program is saved.

    But you saved it in "Desktop". 

     There are 3 ways.

     1)Do you know Where is your small basic program?  

        if you know it ,  Copy the csv file to the program directory(folder).

    2)If not, change path

      path=program.Directory+"\UserList.csv"  --->  path="C:\Users\????\Desktop\UserList.csv"

      ???? is your PC's name

    3)If you don't know ????(PC's name ) ,

     Copy the csv file to other drive (for example D:\) .

     and chage path

    path=program.Directory+"\UserList.csv"  --->  path="D:\UserList.csv" 

    Friday, March 7, 2014 8:10 AM
  • I tested your program with a handmade UserList.txt:

    I typed the following and saved it as UserList.txt


    When I run the program it works!!

    What do you get when you open in your SmallBasic directory the file userlist.txt (when you click "open" you do not see the file, but can type the name in the namefield) and load it.?

    You can then compare the contents of the exported Excel file, and see where it goes wrong.

    Jan [ WhTurner ] The Netherlands

    Friday, March 7, 2014 6:24 PM
  • The program reads the whole file into CSVData, checks if the text you input for Name is in the file (ATTENTION: if you input jj it finds this in jjparker)

    Then it checks in the password is after the name (ATTENTION: also finds it OK if only part of the password is found)

    If both are found the subroutine datalist is executed which lists the rest of the found line.

    Hope this helps.

    Jan [ WhTurner ] The Netherlands

    Friday, March 7, 2014 8:35 PM
  • Thanks for the help,

    Could anyone explain the code

    To see what each part does?

    Thanks In Advance.

    See photo below.

    I didn't write first line (username,password,firstname,secondname,street,city,postcode)
    This program doesn't matter first line.

    This program checks the point of username .
     namepoint= Text.GetIndexOf(CSVData,name)
    For example, "samy" exists at 210 point(59+2+7+2+57+2+7+2+60+2+7+2+1=210).
     so , namepoint=210
    * CRLF(carriage return and line feed) exists at the end of each line. It takes 2 points. 
    If you enter "samy", program searches the point "samy" exists.
    Then gets divided text (samy,sunny,.........   ,OX8 76H <-- end of text).
     Start= Text.GetSubTextToEnd(CSVData,namepoint)
    Then gets first CRLF point.(It exists after CH4 5GH)
      CRpoint = 56.(55+1=56)
    Then gets target line().
        Target= Text.GetSubText(start,1,CRpoint-1)+"," 
        Target ="samy,sunny,Sami,Yoda,43 Norton Avenue, Chester, CH4 5GH"
    Then checks if password exists in target line .
     If text.IsSubText(target,PW)="True" Then
     (If password exists , result = "True")

    and then do subroutine datalist()
    check length of Target
     Len= Text.GetLength(Target)
     Len= 55
    counts up NN


    Search first "," point.
     Cpoint= Text.GetIndexOf(Target,",")
    Gets divided text
     itsdata= Text.GetSubText(Target,1,Cpoint-1)
     itsdata= "sammy"
    show itsdata in textwindow
       TextWindow.WriteLine(LST[NN]+" = "+itsdata)
    gets remained data
       Taget="sunny,Sami,Yoda,43 Norton Avenue, Chester, CH4 5GH"
       (Note ; "sammy," is erased)
    check length of Target
     Len= Text.GetLength(Target)
     Len= 50
    repeats these procedure.
     (Finally Len becomes zero)

    **  In my PC, path="C:\Users\owner\Desktop\UserList.csv"   ????= owner

    Click PC's "Start " button. you can see PC's name .  (see below)

    • Edited by NaochanONEditor Saturday, March 8, 2014 3:34 AM add photo, comment
    Saturday, March 8, 2014 3:15 AM
  • If I was to change the username into a email, how would this change the code?

    NOT at all, but try it yourself. The code just compares user inputs and content of your file (txt, csv, xyz does'nt matter. Path must be correct under 'path=.....' in the .sb File)

    Maybe try ID: GRJ176   and test all possible variants and combinations.

    PS: NO leading or trailing empty space (chr 32) allowed in columns 1 and 2 of your Data file.

    Saturday, March 8, 2014 2:47 PM
  • Hello, Thanks for your help.

    When I use the code, I keep getting problems such as this:

    If someone types part of the email (examples, Hotmail, live, net etc.)  and the correct corresponding password,

    it is deemed as a correct username when it is not. It then displays the information which is not supposed to happen if they just type 'live'.

    Thanks in Advance.

    Saturday, March 8, 2014 5:38 PM
  • Yep, I see.

    OK, there's no InStrRev function and check comparison has to start at the beginning of each line, so import should happen line by line. Counting lines would be easier with eg. LDFile.Length. Don't know if you can use extensions ?.

    Try this ID: MVM601

    ... and check for all kinds of input contingencies and possibilities just like you did before.

    Did some proofing but one can never know..

    PS: NO spaces in a column before or after the comma. Correct is: |username,password,blabla

    Saturday, March 8, 2014 8:26 PM
  • If someone just typed any random letters or numbers as the username and password

    The code should display 'INCORRECT PASSWORD'

    If someone just typed a correct email like 'sbirling@posh.org.uk'

    But then typed the wrong password

    The code should display 'INCORRECT PASSWORD'

    And if there is an 'INCORRECT PASSWORD'

    The code should then direct users to type their email and password again.

    how about this?  KDV522-0

    more simple way.  KDV522-1

    Sunday, March 9, 2014 2:42 AM
  • Thanks for the help,

    would you mind explaining your code?

    Thanks In Advance.

    Sunday, March 9, 2014 11:41 AM
  • If you enter username as "Live" , it exists.
     But it should result in Error.

    Because "Live" is a part of email address (samy@live.co.uk)
    you must get full email address.
    How to get start point of email address is below.

    Partialnamepoint= Text.GetIndexOf(CSVData,name)
    For i= Partialnamepoint to 1 step -1
      If Text.GetSubText(CSVData,i,1)=Text.GetCharacter(10) Then ' search LF point
        namepoint=i+1  '   start point of emailaddress 

    "CRLF" exists before "samy".
    so, it searches LF point .
    " Live" point = 236. LF point=230 -->  samy starts at 231

    Sunday, March 9, 2014 12:18 PM
  • Thanks,

    Could you explain the function of 'CRLF'?

    It would help me understand the code in more detail.

    Thanks in Advance

    Sunday, March 9, 2014 2:21 PM
  • CRLF are the two characters which signal the end of a line in a textfile. They are the ASCII character 13 and 10 (Carriage Return and Line Feed).

    Jan [ WhTurner ] The Netherlands

    Sunday, March 9, 2014 5:59 PM
  • i am unable to get that code to work, as i need to be able to do the same thing
    Sunday, March 9, 2014 10:34 PM
  • i am unable to get that code to work, as i need to be able to do the same thing

    What  troubles?

    1)Did you save the program?

    2)Do you know the directory(folder) program saved?

    3)Did you make a csv file?   ("UserList.csv")

    4)Where did you save it?  You must set the Path.
      You'd better save it in the program saved folder.
       Path= Program.Directory + "\UserList.csv"
      if you saved it in Desktop,
      Path= "C:\Users\?????\Desktop\UserList.csv"
       (?????  your PC name)
       if you saved it in "D:\"  (D drive ; root directory),
      Path= "D:\UserList.csv"

    Monday, March 10, 2014 12:00 AM