Posts Topics Forums Images
Search videos from message boards Videos Search messages from microblogs Microblogs Search messages from imdb.com Imdb Search messages from yuku.com Yuku Search messages from lefora.com (free forums) Lefora
My account: Login | Sign Up
Loading... 

Thread: a string to an integer in microsoft.public.excel.programming

Started 1 month, 1 week ago by Philosophaie
I have a string: string(3) = "543" I try to change it to an integer: int = cint(string(3)) It gives me a 'Type Mismatch' Error. Maybe there may be spaces before of after the numbers but does that matter? How do I change from a string to an integer?...
Site: Discussions in microsoft.public.excel.programming  Discussions in microsoft.public.excel.programming - site profile
Forum: microsoft.public.excel.programming  microsoft.public.excel.programming - forum profile
Total authors: 4 authors
Total thread posts: 12 posts
Thread activity: no new posts during last week
Domain info for: microsoft.com

Other posts in this thread:

Sam Wilson replied 1 month, 1 week ago
Spaces do matter. Try int = cint(trim(string(3)) "Philosophaie" wrote: > I have a string: > > string(3) = "543" > > I try to change it to an integer: > > int = cint(string(3)) > > It gives me a 'Type Mismatch' Error. > > Maybe there may be spaces before ...

Philosophaie replied 1 month, 1 week ago
There were no spaces. I checked. Why else am I getting 'Type Mismatch' Error and not letting me use cint to change from a string?

Sam Wilson replied 1 month, 1 week ago
I've just done this: Sub test() Dim s As String s = "543" Dim i As Integer i = CInt(Trim(s)) MsgBox i End Sub and it works. Have you ot an apostrophe/single quote ' preceeding the 5? "Philosophaie" wrote: > There were no spaces. I checked. Why else am ...

Philosophaie replied 1 month, 1 week ago
I am using what is already in the cell from "Left and Right" operations to a bunch of similar data strings. I have ran my own trimming operation thru if left(a,1)="-" then a=Right(a,2) but it will still not let me take the cint or cdbl of any of the data. So the quote sign is irrelevant....

Sam Wilson replied 1 month, 1 week ago
Ok... another approach - try msgbox len(str) * " """ & str & """" which should display 3 "543" to make sure there are no extra characters in there. Sam "Philosophaie" wrote: > I am using what is already in the cell from "Left and Right" operations to a > bunch of similar ...

Philosophaie replied 1 month, 1 week ago
I typed verbatum: msgbox len(str) * " """ & str & """" even that gave me a 'Type Mismatch error' "Sam Wilson" wrote: > Ok... another approach - try > > msgbox len(str) * " """ & str & """" > > which should display > > 3 "543" > > to make sure there are no extra ...

Sam Wilson replied 1 month, 1 week ago
msgbox len(str) & " """ & str & """" Sorry, my mistake. Change str for whatever string it is you're trying to convert. Sam "Philosophaie" wrote: > I typed verbatum: > > msgbox len(str) * " """ & str & """" > > even that gave me a 'Type Mismatch error' > > > "...

Charlie replied 1 month, 1 week ago
Also String is an intrinsic function in VB! Use Option Explicit at the top of your module and make sure you dim all of your variables using names that are not intrinsic functions. "Philosophaie" wrote: > I have a string: > > string(3) = "543" > > I try to change it to an integer: >...

Charlie replied 1 month, 1 week ago
Type mismatch probably comes from the fact you are using "int" int = CInt() Int is an intrinsic function in VB. You shouldn't name a variable "int" As for the other problem use Mid not Right to get the remaining portion of the string if left(a,1)="-" then a=mid(a,2) "Philosophaie" wrote: ...

Philosophaie replied 1 month, 1 week ago
they all had len=2 and nothing looked out of the ordinary. "Sam Wilson" wrote: > msgbox len(str) & " """ & str & """" > > Sorry, my mistake. Change str for whatever string it is you're trying to > convert. >

 

Top contributing authors

Name
Posts
Philosophaie
5
user's latest post:
a string to an integer in...
Published (2009-11-04 10:24:00)
  they all had len=2 and nothing looked out of the ordinary. "Sam Wilson" wrote: > msgbox len(str) & " """ & str & """" > > Sorry, my mistake. Change str for whatever string it is you're trying to > convert. >  
Sam Wilson
4
user's latest post:
a string to an integer in...
Published (2009-11-04 09:39:00)
  msgbox len(str) & " """ & str & """" Sorry, my mistake. Change str for whatever string it is you're trying to convert. Sam "Philosophaie" wrote: > I typed verbatum: > > msgbox len(str) * " """ & str & """"...
Charlie
2
user's latest post:
a string to an integer in...
Published (2009-11-04 10:24:00)
  Also String is an intrinsic function in VB! Use Option Explicit at the top of your module and make sure you dim all of your variables using names that are not intrinsic functions. "Philosophaie" wrote: > I have a string: > > string(3) = "543" > > I try to change it to an integer: > > int = cint(string(3)) > > It gives me a 'Type...
Dave Peterson
1
user's latest post:
a string to an integer in...
Published (2009-11-04 10:24:00)
  Don't use String and Int as variable names. String is a VBA function and data type. Int is a VBA function. Dim myString(1 To 3) As String Dim myInt As Long myString(3) = "543" myInt = CInt(myString(3)) Personally, I wouldn't use "as integer" or cInt(). I'd use "As long" and clng(). Philosophaie wrote: > > I have a string: > > string(3)...

Related threads on "Discussions in microsoft.public.excel.programming":

Related threads on other sites:

Thread profile page for "a string to an integer in microsoft.public.excel.programming" on http://www.microsoft.com/communities/newsgroups.... This report page is a snippet summary view from a single thread "a string to an integer in microsoft.public.excel.programming", located on the Message Board at http://www.microsoft.com/communities/newsgroups.... This thread profile page shows the thread statistics for: Total Authors, Total Thread Posts, and Thread Activity