LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How to read strings from .txt file to TEXT BOX Line by Line using ArrayToFile?

I wanna read strings from a .txt file to Text Box line by line ,but failed.
The format of strings in the .txt file is as belows:
 
1.1 LDO 5V Test;
1.2 LDO 3.3V TEST;
1.3 RS232 TEST;
.......
 
 
   read_file = OpenFile ("\\Txt\\config.txt", VAL_READ_WRITE, VAL_OPEN_AS_IS, VAL_ASCII);
   FileToArray ("Txt\\config.txt", File, VAL_CHAR, 16, 1, VAL_GROUPS_TOGETHER, VAL_GROUPS_AS_ROWS, VAL_ASCII);
   
   strcpy(Temp,File[0]);
   InsertTextBoxLine (panelHandle, PANEL_READ_TXT, -1, Temp);
 
Can anynoe give any hit?
Thanks
Yuki
0 Kudos
Message 1 of 5
(4,522 Views)

This way might be easier:

FILE *fp;
char line [256];

fp = fopen ("TextFile.txt", "rt");
while (fgets (line, 256, fp))
    SetCtrlVal (panel, PANEL_TEXTBOX, line);
fclose (fp);

JR

0 Kudos
Message 2 of 5
(4,514 Views)
Dear JR:
  
    Thanks a lot for your reply.
    It does work,but  how can I read one line one time.For example when I click the button 1st time line 1 is read and line 2 is read when the button is clicked the second time.......
    Best Regards
   Yuki
0 Kudos
Message 3 of 5
(4,483 Views)
every time you call fgets (line, 256, fp) you read one line from the file(the second time the second line etc.)..
if you want to read specific lines every time consider using inifile.fp and the Ini functions..

paulos
0 Kudos
Message 4 of 5
(4,469 Views)

IT is much simpler if you use the ini-file management and read values using tags

(the content of the ini file)

[SECTION]

TAG1 = value1

TAG2 = value 2

-----------------------

IniText Settings;

int linepos;

char line[MAX_LINELEN+1]

Seetings=Ini_New(0);

Ini_FeadFile(Setting);

GetRawString(line,"Section],"Tag1",line);

InsertTextBoxLine(panel,control,linepos,line);

 

regards: layosh

 

0 Kudos
Message 5 of 5
(4,420 Views)