Home > Software engineering >  The tooltip text read commas between super end such as files, content should be assigned to a variab
The tooltip text read commas between super end such as files, content should be assigned to a variab

Time:09-26

The program is that

 Private Sub Command1_Click () 
Dim id $, name $, price $, store $' declare variables attribute
Open "fetch. TXT" For Input As # 1
The Do While Not EOF (1)
Input # 1, id, name, price, and store the data into the 'four variables in
Print id, name, price, output data store '
Loop
Close # 1
MsgBox "complete"
End Sub



Text content is
AUH, 010000 t15805, T155, 20141019
AUH, 010000 t15805, T155, 20141020
AUH, 010000 t15805, T155, 20141021
AUH, 2400000 z510a, Z51, 20141019
AUH, 2400000 z510a, Z51, 20141020
AUH, 2400000 z510a, Z51, 20141021

CodePudding user response:

Such as online urgent need

CodePudding user response:

CodePudding user response:

This code, you want to read the file content but not normal "error", has a limitation:
The text file you fetch. TXT last line can't end with "of", the newline character.

"Simple" sensory judgment, is after you open this file with notepad program,
Its "at the end of the line" is not a blank line;
You press the keyboard "Ctrl + End", behind the cursor "1", in 141021, flashing, rather than at the start of a blank line,

CodePudding user response:

Just run your code, and found that the result is:
The last line can use "+ newline character at the end, that is the end of the file can have a" blank lines ";
But if you press the return key, more add a blank line at the end of the file, would be a "super end as file" error,

CodePudding user response:

Private Sub Command1_Click ()
On the Error Resume Next
Dim id $, name $, price $, store $' declare variables attribute
Open "fetch. TXT" For Input As # 1
The Do While Not EOF (1)
Input # 1, id, name, price, and store the data into the 'four variables in
Print id, name, price, output data store '
Loop
Close # 1
MsgBox "complete"
End Sub

CodePudding user response:

reference 5 floor zhao4zhong1 reply:
Private Sub Command1_Click ()
On the Error Resume Next
.
End Sub

Hate the most is the idea of "the ostrich"!

CodePudding user response:

refer to 6th floor Chen8013 response:
Quote: refer to the fifth floor zhao4zhong1 reply:

Private Sub Command1_Click ()
On the Error Resume Next
.
End Sub

Hate the most is the idea of "the ostrich"!

Some short-scale, inch a director,

CodePudding user response:

refer to 7th floor zhao4zhong1 response:
Quote: refer to the sixth floor Chen8013 response:

Quote: refer to the fifth floor zhao4zhong1 reply:

Private Sub Command1_Click ()
On the Error Resume Next
.
End Sub

Hate the most is the idea of "the ostrich"!

Some short-scale, inch a director,

You this kind of treatment, long a dog P!!!!!!
Reading file, members of the "value" not read, appear even "deliberately mispresents" all don't know!

Your file content, can be regarded as "data form," with "field" attributes,
I feel really want "rigorous processing," shouldn't use Input statements directly read,
Because the file is a plain text content, format "optional" may occur:
If there is a blank line, or a line is much more (or less), two commas,
The result is a direct result of reading to members of the value "misplaced"!
However, these phenomena, the process of reading data show it is "normal", wrong all don't know!
Read the data are wrong, "processing" correctly???

Should use the Line Input statement read, with the Split Split member (field), give each variable assignment respectively,
Although this process trival, but there are some benefits:
1. The blank line of the file, you can skip directly, so no matter in the middle or at the end of the blank line, does not affect the operation,
At the same time, directly solves the original poster encountered this kind of "beyond the file at the end of" exception,
2. How many in a row "fields", you can check, can prompt error does not conform to the requirements,
If read to accumulation of "line", can also prompt error is how many of the lines in the file,
3. Can be format for each row "specific fields" check, if do not conform to the requirements, can also prompt error,
The host's file, one of the most obvious is the fourth field, should be "date format";
The third field, should be specific letters + digital format;
The first field, should be a specific one of a set of code,
The three fields are easy to check, if necessary can be added to the reading process, not by check can prompt content error,

CodePudding user response:

The original poster don't silent, look back upstairs and reply,,

Words I have never used inpu basic statements, are the line input or input function,
Both Dim id $
"C: \ 1. TXT" Open For Input As # 1 
Id=Input (LOF (1), # 1)
Close # 1
The Print id

All suggest that the original poster is read into the string, then use string segmentation method for processing, do not know what is the context of the original poster posted code, why do you say "content must be assigned to a variable that can't change", if the original poster is don't know anything about vb dare not move freely move the predecessors left so suggest your company to find the vb code professional person to do a good job in the for small white words on the above several every word estimates are hard to digest, so silent, directly,

CodePudding user response:

refer to the eighth floor Chen8013 response:
Quote: refer to 7th floor zhao4zhong1 response:

Quote: refer to the sixth floor Chen8013 response:

Quote: refer to the fifth floor zhao4zhong1 reply:

Private Sub Command1_Click ()
On the Error Resume Next
.
End Sub

Hate the most is the idea of "the ostrich"!

Some short-scale, inch a director,

You this kind of treatment, long a dog P!!!!!!
Reading file, members of the "value" not read, appear even "deliberately mispresents" all don't know!

Your file content, can be regarded as "data form," with "field" attributes,
I feel really want "rigorous processing," shouldn't use Input statements directly read,
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  •  Tags:  
  • VBA
  • Related