|
Post by pandawdy on Aug 1, 2020 12:41:54 GMT -5
A little hard to describe. I made a very simple chat program. When you visit the site, you enter your name, then the program reads all entries a text file, line by line. You enter your chat message, press enter, and your chat is appended to that file. Sometimes what you type in is cut short, and I'm not sure why. You can open the text file and look, and it's also cut short in the text file. It doesn't always happen. print "Input your name below and click Accept" input name$
[beginning]
cls open "chat.txt" for input as #readchat while eof(#readchat) = 0 line input #readchat, newinput$ print newinput$ wend close #readchat
input chat$ open "chat.txt" for append as #writechat print #writechat, date$() + " " + time$() + " " + name$ + ":" + " " + chat$ close #writechat goto [beginning]
end
|
|
|
Post by StefanPendl on Aug 2, 2020 1:26:29 GMT -5
Do you lock access to the text file while one is reading or writing from/to it? I don't think that a text file is best suited for a chat resource without control handling of reading and writing.
|
|
|
Post by pandawdy on Aug 2, 2020 12:38:04 GMT -5
Do you lock access to the text file while one is reading or writing from/to it? I don't think that a text file is best suited for a chat resource without control handling of reading and writing. No. I know if several people were chatting at once, eventually it's going to be a problem. But the problem I'm having is happening when just one person is using it. Wish I could recreate the problem, but it seems to come and go. I was able to briefly recreate it. One time I had sentence that would always cause it to happen. But later when I came back and tried to do it again, the problem never came back.
|
|
|
Post by pandawdy on Aug 4, 2020 20:48:20 GMT -5
Until I can recreate the problem easily, I don't think I'll be able to fix it. But that's cool. This is just a goof around project for me.
|
|
|
Post by meerkat on Aug 5, 2020 10:55:12 GMT -5
I made a small change to your code to use SQLite. See if this works for you? I'm curious - if this works, then maybe there is something wrong with the file buffer. You need to change the "chat_project" to wherever your chat project is located in Run Basic.
wordWrap$ = "style='white-space: pre-wrap;";_ "white-space: -moz-pre-wrap;";_ "white-space: -pre-wrap;";_ "white-space: -o-pre-wrap;";_ "word-wrap: break-word'"
projectDir$ = "chat_project" '<<<<<<<<<<<<<<<<< change this to where your chat project is located <<<<<<<<<<< chatDb$ = DefaultDir$ + "\projects\" + projectDir$ + "\chat.db" files #f,chatDb$ if #f HASANSWER() = 0 then ' file does not exist sqliteconnect #sql, chatDb$ sql$ = " CREATE TABLE chat ( userName VARCHAR(22), msgDate DATE, msgTime TIME, msg TEXT)" #sql execute(sql$) #sql disconnect() Print "New SQLlite3 database created" end if
input "Input your name ";name$
[beginning] html "<TABLE BORDER=1 CELLPADDING=0 CELLSPACING=0> <TR><TD BGCOLOR=silver ALIGN=RIGHT><B>Name</B></TD><TD ALIGN=CENTER>";name$;"</TD></TR> <TR><TD BGCOLOR=silver ALIGN=RIGHT><B>Message</B></TD> <TD valign=top><TEXTAREA NAME=msg ROWS=8 COLS=60></TEXTAREA> </TD></TR><TR><TD BGCOLOR=silver></TD><TD BGCOLOR=silver align=center>"
button #add, "Add", [add] button #lst, "List", [list] button #ext, "Exit", [exit]
html "</TD></TR></TABLE>" wait
[add] cls msg$ = #request get$("msg") if trim$(msg$) <> "" then sqliteconnect #sql, chatDb$ sql$ = "INSERT INTO chat VALUES('";name$;"','";date$();"','";time$();"','";msg$;"')" #sql execute(sql$) #sql disconnect() end if goto [beginning]
[exit] cls Print "Thanks for stopping by" end
[list] sqliteconnect #sql, chatDb$ sql$ = "SELECT * FROM chat order by msgDate desc,msgTime desc" #sql execute(sql$) rows = #sql ROWCOUNT() 'Get the number of rows html "<TABLE BORDER=1 CELLPADDING=0 CELLSPACING=0>" html "<TR align=center bgcolor=silver><TD>User</TD><TD>Date</TD><TD>Time</TD><TD>Message</TD></TR>" WHILE #sql hasanswer() #row = #sql #nextrow() userName$ = #row userName$() msgDate$ = #row msgDate$() msgTime$ = #row msgTime$() msg$ = #row msg$() html "<TR>" html "<TD>";userName$;"</TD>" html "<TD>";msgDate$;"</TD>" html "<TD>";msgTime$;"</TD>" html "<TD ";wordWrap$;" >";msg$;"</TD>" html "</TR>" WEND html "</TABLE>" #sql disconnect() wait
Good luck with your project.. Hope this helps Dan
|
|
|
Post by pandawdy on Aug 6, 2020 19:21:34 GMT -5
I made a small change to your code to use SQLite. See if this works for you? I'm curious - if this works, then maybe there is something wrong with the file buffer. You need to change the "chat_project" to wherever your chat project is located in Run Basic. wordWrap$ = "style='white-space: pre-wrap;";_ "white-space: -moz-pre-wrap;";_ "white-space: -pre-wrap;";_ "white-space: -o-pre-wrap;";_ "word-wrap: break-word'"
projectDir$ = "chat_project" '<<<<<<<<<<<<<<<<< change this to where your chat project is located <<<<<<<<<<< chatDb$ = DefaultDir$ + "\projects\" + projectDir$ + "\chat.db" files #f,chatDb$ if #f HASANSWER() = 0 then ' file does not exist sqliteconnect #sql, chatDb$ sql$ = " CREATE TABLE chat ( userName VARCHAR(22), msgDate DATE, msgTime TIME, msg TEXT)" #sql execute(sql$) #sql disconnect() Print "New SQLlite3 database created" end if
input "Input your name ";name$
[beginning] html "<TABLE BORDER=1 CELLPADDING=0 CELLSPACING=0> <TR><TD BGCOLOR=silver ALIGN=RIGHT><B>Name</B></TD><TD ALIGN=CENTER>";name$;"</TD></TR> <TR><TD BGCOLOR=silver ALIGN=RIGHT><B>Message</B></TD> <TD valign=top><TEXTAREA NAME=msg ROWS=8 COLS=60></TEXTAREA> </TD></TR><TR><TD BGCOLOR=silver></TD><TD BGCOLOR=silver align=center>"
button #add, "Add", [add] button #lst, "List", [list] button #ext, "Exit", [exit]
html "</TD></TR></TABLE>" wait
[add] cls msg$ = #request get$("msg") if trim$(msg$) <> "" then sqliteconnect #sql, chatDb$ sql$ = "INSERT INTO chat VALUES('";name$;"','";date$();"','";time$();"','";msg$;"')" #sql execute(sql$) #sql disconnect() end if goto [beginning]
[exit] cls Print "Thanks for stopping by" end
[list] sqliteconnect #sql, chatDb$ sql$ = "SELECT * FROM chat order by msgDate desc,msgTime desc" #sql execute(sql$) rows = #sql ROWCOUNT() 'Get the number of rows html "<TABLE BORDER=1 CELLPADDING=0 CELLSPACING=0>" html "<TR align=center bgcolor=silver><TD>User</TD><TD>Date</TD><TD>Time</TD><TD>Message</TD></TR>" WHILE #sql hasanswer() #row = #sql #nextrow() userName$ = #row userName$() msgDate$ = #row msgDate$() msgTime$ = #row msgTime$() msg$ = #row msg$() html "<TR>" html "<TD>";userName$;"</TD>" html "<TD>";msgDate$;"</TD>" html "<TD>";msgTime$;"</TD>" html "<TD ";wordWrap$;" >";msg$;"</TD>" html "</TR>" WEND html "</TABLE>" #sql disconnect() wait Good luck with your project.. Hope this helps Dan Yours is quite a bit better than mine. Pretty cool.
|
|
|
Post by pandawdy on Aug 8, 2020 17:04:49 GMT -5
I think I found the problem. Run BASIC doesn't accept commas with input. But Liberty Basic does.
|
|
|
Post by StefanPendl on Aug 9, 2020 0:24:12 GMT -5
LINE INPUT should ignore commas, only regular INPUT from files will treat commas as field separators. You could replace the commas by a different character that is not used in a chat, like CHR$(255). Replace CHR$(255) by a comma for display.
|
|