Mysterious hidden characters in combo box

smiler44

Registered User.
Local time
Today, 16:09
Joined
Jul 15, 2008
Messages
678
Below is the code I am using to retrive the name of a file, 1st.bmp and load the file name into a combo box. 1st.bmp is 7 characters long but the code in command1 tells me it is 9 charectors long.

spent hors on this but I can not see the problem, can you?
smiler44


Private Sub Form_Load()
Combo3.AddItem "Good"
End Sub
Private Sub Combo3_Click()
Dim pathname As String ' full path to find the files
Dim dir As String 'main directory
Dim subdir As String ' sub directory
dir = "C:\temp2\"
subdir = Combo3.Text ' subdir = Good
Dim strStartPath As String
pathname = dir & subdir
strStartPath = pathname
ListFolder strStartPath
End Sub

Private Sub ListFolder(sFolderPath As String)
Dim FS As New FileSystemObject
Dim FSfolder As Folder
Dim File As File
Dim i As Integer

Set FSfolder = FS.GetFolder(sFolderPath)
Text1.Text = ""
For Each File In FSfolder.Files
DoEvents
Text1.Text = File & vbCrLf ' this method gets just the file
Call forme
Next File
Set FSfolder = Nothing
End Sub

Private Sub forme()
' checks whats in text2 and if an exchange name adds it to a combo box
Dim scan As String
Dim name As String 'name is the name of exch displayed in text2
scan = Text1.Text
Text2 = Mid$(scan, 15, 16) ' scans text2 starting at 15th charector ans captures the next 16, only 7 of the 16 are charactors the rest are blank
name = Text2.Text
If Text2 <> "" Then
Combo1.AddItem name
Else
Exit Sub
End If
End Sub

Private Sub Command1_Click()
Dim text_length As Integer
text_length = Len(Combo1.Text)
Text3 = text_length
End Sub
 
Code:
Private Sub forme()
' checks whats in text2 and if an exchange name adds it to a combo box
Dim scan As String
[COLOR="Red"]Dim name As String [/COLOR]'name is the name of exch displayed in text2
[COLOR="Red"][B]'May not have anything to do with your problem, but Name is a reserved word [/B][/COLOR]
scan = Text1.Text
Text2 = Mid$(scan, 15, 16) ' scans text2 starting at 15th charector ans captures the next 16, only 7 of the 16 are charactors the rest are blank
name = Text2.Text
If Text2 <> "" Then
Combo1.AddItem name
Else
Exit Sub
End If
End Sub
 
Thanks Catfish, I did not know that.

I have found a work around but would like to find out the problem.
I will redo the code and change name.
thanks again
 
Smiler,

This line has a few problems:

Text1.Text = File & vbCrLf

1st, the .Text property is only valid during the OnChange event. It lets you inspect
the text as people type it in. It isn't valid in this context, you probably need .Value
which is the default.

2nd, the vbCrLf appends two unprintable characters to the end of your filename:

CarriageReturn - Ascii(13)
LineFeed - Ascii(10)

Wayne
 
2nd, the vbCrLf appends two unprintable characters to the end of your filename...........so that is where the problem is! I would never have found it, thank you.

I have to ask, do you know what I can use instead? I'm sure I tried coding without using vbCrlf and it did not work but I will double check
I've searched the internet to find out the definition of vbcrlf , Visual Basic Carriage Return Line Feed, which is what you have said.

Thank you again

smiler44
 
Some clarification ...

>> 1st, the .Text property is only valid during the OnChange event <<

I hate to say it but that is not true. You can use the .Text property to find out the text within a textbox or combobox. The difference between .Value and .Text is that the .Value property returns the value that is committed in the Text/Combo box. The .Text returns what you see ... so if you are typing in a box and read the .Text value with the OnChange event of the control, the .Text will reflect what you type, the .Value will be what is was before you started typing. Once the control looses the focus, the .Text and .Value are the same, with the exception of a Null .Value, with will equate to a ZLS with .Text ... But ... the caveat is that you can not read the .Text property UNLESS the control has the FOCUS.

...

Also ... I see no need for a vbCrLf ... what are you trying to emulate? ...a "return" or "enter"? It seems you are best suited to use the .Value property of the control (which is the default, and thus does not need to be specified if you do not wish to specify it) ...

Me.Text1.Value = File
..Or ..
Me.Text1 = File

...

But do take note that "File" is also a reserved word, so I would suggest you change that variable identifier. Many times folks will name variables with a prefix, like "strFile", thus indicating the variable is a STRing datatype ...
 
Brent,

I'm sorry but ... I really believe that the .Text property is only valid when
a Control has the focus.

Must investigate further.

Wayne
 
Brent,

That's not bad for 90 seconds of research ... upon further review:

My lawyer and I read your last post and I'm in complete agreement with you.
Now, why couldn't I read that properly the 1st time?

Wayne
 
Re: Mysterious hidden characters in combo box, datAdrenaline

I hvae done some playing around and now know why I used vbcrlf.
I was practising with the code and needed vbcrlf to get the names of the files to go one below the other in a text box.
When I wrote my project once a single path and file name was entered I went to another routine to just get the file name. I can see now with the help of people here that it was my own stupidity still adding vbcrlf when it was not needed. Also with help here I learnt what vbcrlf stood for and does.

Thank you

smiler44
 

Users who are viewing this thread

Back
Top Bottom