Can't remove comma, reading from CSV
mjones2620
Posts: 86
Anyone know why my comma won't go away between columns? Remove string doesn't do the trick:
DEFINE_FUNCTION fnReadFile(CHAR cFILENAME[]) { LOCAL_VAR SLONG slFILE_VAL slFILE_VAL = FILE_OPEN(cFILENAME,FILE_READ_ONLY) IF(slFILE_VAL < 0) { SELECT { ACTIVE(slFILE_VAL == -2):SEND_COMMAND dvTP_VTC,"'^TXT-604,0,Invalid Path'" ACTIVE(slFILE_VAL == -3):SEND_COMMAND dvTP_VTC,"'^TXT-604,0,Invalid Value'" ACTIVE(slFILE_VAL == -5):SEND_COMMAND dvTP_VTC,"'^TXT-604,0,I/O Error'" ACTIVE(slFILE_VAL == -14):SEND_COMMAND dvTP_VTC,"'^TXT-604,0,Max Files Open'" ACTIVE(slFILE_VAL == -15):SEND_COMMAND dvTP_VTC,"'^TXT-604,0,Invalid File Format'" } } IF(slFILE_VAL > 0) { LOCAL_VAR SLONG slVAL LOCAL_VAR INTEGER i LOCAL_VAR CHAR cBUFF[2048] slVAL = FILE_READ_LINE(slFILE_VAL,cBUFF,MAX_LENGTH_ARRAY(cBUFF)) FOR(i=1;i<=MAX_LENGTH_ARRAY(uPRESETS);i++) { uPRESETS[i].cNAMES = REMOVE_STRING(cBUFF,',',1) SET_LENGTH_STRING(uPRESETS[i].nNUMBERS,LENGTH_STRING(uPRESETS[i].nNUMBERS)-1) uPRESETS[i].nNUMBERS = cBUFF SEND_COMMAND dvTP_VTC,"'^TXT-',ITOA(499+i),',0,',uPRESETS[i].cNAMES" SEND_COMMAND dvTP_VTC,"'^TXT-',ITOA(603+i),',0,',uPRESETS[i].nNUMBERS" slVAL = FILE_READ_LINE(slFILE_VAL,cBUFF,MAX_LENGTH_ARRAY(cBUFF)) } FILE_CLOSE(slFILE_VAL) } }
0
Comments
Looks like this:
Should be this:
AHHHH, overlooked the obvious mistake. Thank you sir!
be this:
DEFINE_FUNCTION CHAR[DUET_MAX_PARAM_LEN] DuetParseCmdParam(CHAR cCmd[])
// Name : ==== DuetParseCmdParam ====
// Purpose: To parse out parameters from module send_command or send_string
// Params : (1) IN/OUT - sndcmd/str data
// Returns: Parse parameter from the front of the string not including the separator
// Notes : Parses the strings sent to or from modules extracting the parameters.
// A single param is picked of the cmd string and removed, through the separator.
// The separator is NOT returned from the function.
// If the first character of the param is a double quote, the function will
// remove up to (and including) the next double-quote and the separator without spaces.
// The double quotes will then be stripped from the parameter before it is returned.
// If the double-quote/separator sequence is not found, the function will remove up to (and including)
// the separator character and the leading double quote will NOT be removed.
// If the separator is not found, the entire remained of the command is removed.
// Command separating character assumed to be ',', Duet standard
//
DuetParseCmdHeader() and DuetParseCmdParam() are some of the handiest, least utilized SNAPI functions available. I was so happy when I stumbled upon them so I could do away with my other SNAPI parsing routines..
Could you provide an example of how I'd use this for the code I posted earlier in this thread?
DuetParseCmdParam takes the input string (in your case cBUFF) and, if it finds a comma, returns the string portion to the left of the comma. The input string has the parameter including the comma removed. If no comma is found, the function returns the entire string and the input string will be empty.
Andy