Hi,
I got an answer to a big part of my question the following
vb code which
reads a file, line by line and outputs line into a message box.
How can I access single characters in this array line. in c++ I would do
line[0] and access the first char and so on.
Could anybody help?
Private Sub Command1_Click()
Dim lngIndex As Long
Dim intFile As Integer
'file identification number
Dim strFile As String
'filename
Dim strData As String
'string to contain complete file
Dim strLine() As String
'array to contain each line
Dim intChoice As Integer
'user selection in msgbox
intFile = FreeFile
'unique file identification number
strFile = "c:\temp\myfile.txt"
'filename to read
Open strFile For Input As #intFile
'open file to read
strData = Input(Lof(intFile), #intFile)
'read in complete file
Close #intFile
'close file
strLine = Split(strData, vbCrLf)
'split total data into array of line
For lngIndex = 0 To UBound(strLine)
'loop through all lines (array)
intChoice = MsgBox(strLine(lngIndex), vbOKCancel, "Line: " &
CStr(lngIndex)) 'show each line
If intChoice = vbCancel Then Exit For
'select 'cancel' to jump out of loop
Next lngIndex
End sub
"David" wrote:
Hello everbody,
I know C++, so below is a code I wrote that opens/reads a file and looks for
certain character and writes into another file all X and Y coordinates of a
pecific character.
I would like to build a matrix using VB:
I need help on how to open and read a text file(read every character in
file), then create a matrix and insert everyone of those characters into a
table (matrix) in VB.
Could anybody help with this.
int main()
{
FILE *infile, *InkLocsFile;
char line[MAXLINE]={0}; //wmapBitLoc[rows][cols]
int n=0,i=0,j=0, flag=0, cl=0,Ink=0, rw = -1;
infile = fopen("wmap.txt", "r"); //open fail file for reading and writing
if (infile == NULL)
{
printf("\nError (Error opening wmap file): %s file failed to
open.\n",infile);
exit(0);
}//end if
InkLocsFile = fopen("InkLocsFile.txt", "w");
fprintf (InkLocsFile, "RowLoc ColLoc \n");
fprintf (InkLocsFile, "----- ------ \n");
while ( (fgets (line,sizeof(line),infile) != NULL))
{
rw +=1;
// if (strstr(line))
// {
for (n=0; n<MAXLINE; n++)
{
if (line[n] == 48)
{
cl =n;
fprintf (InkLocsFile, "%2d %10d \n",rw, cl);
}//end if (line[n] == 0)
}// end for
// }//end if strstr()
}//end While
fclose (infile);
fclose (InkLocsFile);
return 0;
}//end main()
C++ code: