Solved

simple edit string question

Posted on 2003-11-13
8
241 Views
Last Modified: 2010-08-05
i have a variable....

Testies = '99876'

i need to simply get rid of the ' and just have 99876

what is the easiest way to do this???
0
Comment
Question by:Thermos
8 Comments
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 9744269
If your asking how to convert a string to a number then:

Private Sub Form_Load()
    Dim Testies As String
    Testies = "99876"
   
    Dim Balls As Double
    Balls = CDbl(Testies)
   
    Dim Nads As Long
    Nads = CLng(Testies)
   
    Dim Nuts As Single
    Nuts = CSng(Testies)
   
    MsgBox Testies & " < " & (Balls * Nads * Nuts)
End Sub

Idle_Mind
0
 
LVL 11

Expert Comment

by:bingie
ID: 9744680
lol!
0
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 9745043
when you say you want to get rid of the ' and only have 99876, do you mean you have a STRING value, and you want to convert it to a NUMBER?

How do you ge the value as Testies = '99876'  ?  since the ' character acts as a Comment

What exactly are you trying to accomplish, as your explanation is VERY confused.

AW
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

Accepted Solution

by:
bad_seed earned 50 total points
ID: 9745107
if the ' character is only at the beginning and end of the string then the code below will do the trick

    Dim test As String
    Dim test2 As String

    test = "'123456'"
   
    test2 = Mid(test, 2, (Len(test) - 2))
----------------------------------------------------------------

However if the ' can be anywhere in the string then try this

    Dim test As String
    Dim test2 As String

    test = "'1'23'456'"
   
    test2 = Replace(test, "'", "")

hope this helps :o)
   
0
 

Expert Comment

by:bad_seed
ID: 9745120
oh, bear in mind the value will still be a String and NOT a number

for that, extract the ' using the code i mentioned and then use the conversion techniques by Idle_Mind
0
 
LVL 5

Expert Comment

by:burningmace
ID: 9745841
I know what he means. He wants to convert a String to an Integer

Balls = Val(Testies)

That's it.
The power of the single lined code reveals itself.

Hope it works,
Burningmace
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 9748075
> I know what he means. He wants to convert a String to an Integer
>
> Balls = Val(Testies)

> That's it.
> The power of the single lined code reveals itself.
>
> Hope it works,
> Burningmace

Except that an Integer can only hold from -32,768 to 32,767.  

So in your case burningmace, the Val() function would return a Long, not an Integer like you said.

Dim Testies As String
Testies = "99876"
Balls = Val(Testies) ' <----- Balls was not declared, so it implicitly becomes a Long

< versus >

Dim Testies As String
Testies = "99876"
Dim Balls As Integer
Balls = Val(Testies) ' <---- Overflow Error

"The power of the single lined code reveals itself."  ---> Translation: Lazy coding causes unexpected results.

Idle_Mind
0
 

Author Comment

by:Thermos
ID: 9750069
sorry for the late reply.  something came up.

and sorry i didnt explain my question better guys.  i am pulling the info with an array from a .log file.  what i pull out is '9987' (which is how it shows in the .log file) i simply needed to get rid of the 's.

bad_seed.  Mid(test, 2, (Len(test) - 2)) is exactly what i needed.  thank you.  i had been trying to use replace, len, etc but was not using them properly.

thanks again for the help guys.
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Opening Remote & Local Data Connection 2 57
DIR issue 7 53
Macro which automatically send Excel spreadsheet to Outlook problem 2 65
Hide vba in gp 7 93
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

813 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now