+ Reply to Thread
Results 1 to 23 of 23

dim as string, but end as double

  1. #1
    Forum Contributor
    Join Date
    03-28-2017
    Location
    Thailand
    MS-Off Ver
    2013
    Posts
    241

    dim as string, but end as double

    Hi,

    I need to give some data as string to a Json request

    I put variable dim price as string
    when i look in the locals window I see
    Item 2 : "price" : Variant/String
    but
    : price : 230.096 : Variant/Double

    I tried with format the cell withe the value as text
    for some other figures it become string for price it stay double

    how to solve this please

    Thanks

  2. #2
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: dim as string, but end as double


    Hi,

    when you need a particular data type just declare the variable accordingly rather than Variant …

  3. #3
    Forum Contributor
    Join Date
    03-28-2017
    Location
    Thailand
    MS-Off Ver
    2013
    Posts
    241

    Re: dim as string, but end as double

    Hi Marc,

    I am sorry, but I not really understand well
    could you tell me how to do ?

  4. #4
    Forum Contributor
    Join Date
    03-28-2017
    Location
    Thailand
    MS-Off Ver
    2013
    Posts
    241

    Re: dim as string, but end as double

    the figure in the cell that has the price to send change all the time

    it's like ... when the price (online data) is good, he take the vaiue en put it in the price cell
    json send a buy or sell request with that specific last price
    Last edited by incobart; 05-23-2020 at 10:18 AM.

  5. #5
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: dim as string, but end as double


    If you use the appropriate data type for any variable you can't obviously see 'Variant/Double' but just the data type declared …

  6. #6
    Forum Contributor
    Join Date
    03-28-2017
    Location
    Thailand
    MS-Off Ver
    2013
    Posts
    241

    Re: dim as string, but end as double


    you mean if you dim as string, it can not come out as double ?

    but it does

  7. #7
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Lightbulb Re: dim as string, but end as double


    Quote Originally Posted by incobart View Post
    I need to give some data as string to a Json request
    Another way is to directly send the cell Text property rather than one of its value properties …

  8. #8
    Forum Contributor
    Join Date
    03-28-2017
    Location
    Thailand
    MS-Off Ver
    2013
    Posts
    241

    Re: dim as string, but end as double

    Marc, with all respect...
    but not everyone is as deep in excel as you, I don't understand anything you say

    could you please explain how to do in simple language ? thank you so much

  9. #9
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: dim as string, but end as double


    Quote Originally Posted by incobart View Post
    you mean if you dim as string, it can not come out as double ?

    but it does
    No as a declared variable other than Variant can't obviously change its data type
    so it can't be in the VBE 'Locals' window like you can easily check just declaring a variable as String,
    allocating a value to the same variable then taking a glance to 'Locals' window for the same variable …

  10. #10
    Forum Contributor
    Join Date
    03-28-2017
    Location
    Thailand
    MS-Off Ver
    2013
    Posts
    241

    Re: dim as string, but end as double

    someone can translate please ?

  11. #11
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,070

    Re: dim as string, but end as double

    Depends on how you have declared your variables, if you use
    Please Login or Register  to view this content.
    then it will be a string, however if you have declared it like
    Please Login or Register  to view this content.
    then Price is variant & Test is a string

  12. #12
    Forum Contributor
    Join Date
    03-28-2017
    Location
    Thailand
    MS-Off Ver
    2013
    Posts
    241

    Re: dim as string, but end as double

    Ow Fluff what a relief finally something understandable
    Thanks
    I used the first Dim price as string

    but in locals I see variant/double and not variant/string. Marc says it can not change but .. it is like that

  13. #13
    Forum Contributor
    Join Date
    03-28-2017
    Location
    Thailand
    MS-Off Ver
    2013
    Posts
    241

    Re: dim as string, but end as double

    Json send back an error because it must be a string

    when I change the cell format from general to text, then some change from double to string, but price still stay variant/double
    Last edited by incobart; 05-23-2020 at 10:58 AM.

  14. #14
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,070

    Re: dim as string, but end as double

    Can you post your code?

  15. #15
    Forum Contributor
    Join Date
    03-28-2017
    Location
    Thailand
    MS-Off Ver
    2013
    Posts
    241

    Re: dim as string, but end as double

    The code is long and complex but i get out the main thing... (not my code)
    Please Login or Register  to view this content.

  16. #16
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: dim as string, but end as double


    As strRate is Variant instead of String, Lol ! Just follow post #11 …

    And as I wrote just using Text property rather than Value ! So without any useless bad data type variable …
    Last edited by Marc L; 05-23-2020 at 11:18 AM.

  17. #17
    Forum Contributor
    Join Date
    03-28-2017
    Location
    Thailand
    MS-Off Ver
    2013
    Posts
    241

    Re: dim as string, but end as double

    local windows shows
    params3
    : Item 1 : "instrument_id" : Variant/String
    : Item 2 : "price" : Variant/String
    : Item 3 : "size" : Variant/String

    : strCurP : "IOSTBNC" : Variant/String
    : strRate : 230.096 : Variant/Double
    : strQty : "17.4" : Variant/String

    before strQty was also double but became string when i formatted the cells to text
    strRate stay double :-(

  18. #18
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: dim as string, but end as double


    As yet explained here in several posts like #11 if you want some useless variables then declare each one as String for example …

  19. #19
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,070

    Re: dim as string, but end as double

    With
    Please Login or Register  to view this content.
    Only JsonResponse & strCurP are strings, the rest are variant. You need to specify the type for each one individually like
    Please Login or Register  to view this content.

  20. #20
    Forum Contributor
    Join Date
    03-28-2017
    Location
    Thailand
    MS-Off Ver
    2013
    Posts
    241

    Re: dim as string, but end as double

    Marc,
    you mean dim strRate as variant ?

    and strRate = wsTR.Range("C1").text ?

    or Fluff HEEEELP

  21. #21
    Forum Contributor
    Join Date
    03-28-2017
    Location
    Thailand
    MS-Off Ver
    2013
    Posts
    241

    Re: dim as string, but end as double

    Fluff13 YOU DID IT !

    THAAAAAAAAAAAAAAAAANKSS

    can be so simple


    Mark #11 you mean apollo 11 ?

  22. #22
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Re: dim as string, but end as double


    LoL, you are singing 'I believe I can fly' !

    But just well reading answer you may understand your bad …

  23. #23
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,070

    Re: dim as string, but end as double

    You're welcome & thanks for the feedback.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Convert string to double/number, not working
    By travelkid in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-11-2019, 06:44 AM
  2. Convet string to double after replace function
    By travelkid in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 02-04-2019, 10:07 AM
  3. Double quotes when string contains a comma
    By sumdumgai in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-16-2016, 02:56 PM
  4. [SOLVED] Function that takes in a string and returns a double
    By chipp300 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 12-16-2014, 06:56 PM
  5. bad data when i change string to double
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-04-2006, 01:10 PM
  6. how to use (double) quotation mark as string in codes?
    By ViestaWu in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-31-2006, 03:50 AM
  7. [SOLVED] dot / comma and string to double conversion
    By snaggy^^ in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-30-2006, 04:00 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1