Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

finging the length of a string

Posted on 2000-03-05
7
Medium Priority
?
265 Views
Last Modified: 2010-05-02
Is there a function in VB that returns the length of a given string in characters.

Thanks
0
Comment
Question by:kh5395
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 9

Expert Comment

by:Ruchi
ID: 2585192
Use function len.
0
 

Accepted Solution

by:
aaronspitzer earned 100 total points
ID: 2585502
Yes there is: Len()

Usage is straightforward-

Dim x as Integer
Dim strText as String

strText = "Hello there"

x = Len(strText)

debug.Print x

This little routine will return 11 in the immediate window.
0
 
LVL 32

Expert Comment

by:Erick37
ID: 2585684
Len() returns a Long, not Integer.

This will cause a runtime error:

Dim x As Integer
Dim strText As String

strText = Space(&H10000)

x = Len(strText)

Debug.Print x
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 10

Expert Comment

by:caraf_g
ID: 2585714
kh,

I'm not sure how to say this without sounding like a bit of an a****le, so please don't take this the wrong way. The "len" function is a fairly basic VB function, which leads me to believe you are fairly new at the language. In that case I would strongly advise you to buy a programmer's guide. If you go to a decent book shop which has a "computing" section you should be able to find a good book that will help you get over the learning curve. VB is a very nice language, and there's plenty of good work in it, so it would be money well spent.
0
 
LVL 15

Expert Comment

by:ameba
ID: 2585872
' you can also return width of a given string in characters
Private Sub Form_Click()
    Me.ScaleMode = vbCharacters
    MsgBox TextWidth("HHHHH")       ' returns 5
    MsgBox TextWidth("wwwww")       ' returns 5
    MsgBox TextWidth("Hello there") ' returns 6.375
End Sub
0
 

Expert Comment

by:aaronspitzer
ID: 2589218
Good point that Len returns a Long data type, not an integer - though this only becomes an issue when the length of the string exceeds 32,768 characters or so. I don't often hit that limit when using Len()
0
 
LVL 32

Expert Comment

by:Erick37
ID: 2589385
25 years ago, programmers never thought their code would still be running in the year 2000.

:-o
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question