hi Hans hope all is well and not too cold yet in The Netherlands....
have attached png - - - - hopefully that is ok... [ am in a remote system and not allowed to copy ]
lci_gstrCurrentUser is a global variable string dimmed at app start up....
let's say UserText.txt consists of one word: TEST
the WHILE clause is making no sense to me ....
and then the final lci_gstrCurrentUse value also makes no sense to me....
will set it up to test on it's own but in the meantime am wondering what I'm missing...
strange code
-
- 3StarLounger
- Posts: 308
- Joined: 24 Dec 2015, 16:41
strange code
You do not have the required permissions to view the files attached to this post.
-
- Administrator
- Posts: 78594
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: strange code
This is a needlessly convoluted way of extracting the first word of the first line in the text file USERTEXT.TXT.
For example, if lci_gstrCurrentUser is blank, and if the first line of the text file is "John Doe", then lci_gstrCurrentUser will be set to "John".
Since spl is a String variable, it can never be Null or Empty.
Possible equivalent code:
For example, if lci_gstrCurrentUser is blank, and if the first line of the text file is "John Doe", then lci_gstrCurrentUser will be set to "John".
Since spl is a String variable, it can never be Null or Empty.
Possible equivalent code:
Code: Select all
Dim textline As String
Dim cntr As Long
If lci_gstrCurrentUser = "" Then
' If the variable is blank, then open the text file
Open "C:\COSG\SIGNONLOG\USERTEXT.TXT" For Input As #1
' Read its first line
Input #1, textline
' And close it
Close #1
' Get the first word of the line
lci_gstrCurrentUser = Split(textline)(0)
End If
Best wishes,
Hans
Hans
-
- 3StarLounger
- Posts: 308
- Joined: 24 Dec 2015, 16:41
Re: strange code
thanks for the sanity check....
....though I must admit I thought the result was the first letter not the first word....
=Mid(Textline,1,0)
....though I must admit I thought the result was the first letter not the first word....
=Mid(Textline,1,0)
-
- Administrator
- Posts: 78594
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: strange code
The code loops through the characters of the line until it finds a space or the line ends. That is the purpose of the While ... Wend loop. It then takes the substring starting at position 1 and ending just before the space.
Best wishes,
Hans
Hans
-
- 3StarLounger
- Posts: 308
- Joined: 24 Dec 2015, 16:41
Re: strange code
ah yes .... cntr has incremented up ... got it.