Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

excel and vb

Posted on 2006-06-14
5
Medium Priority
?
217 Views
Last Modified: 2010-04-30
I have a program that populates an excel spreadsheet.

When I have numbers like below stored into my db (as a string), I can populate without a problem.
+3.205539E-05

When I use a number stored as a string like .000032 and format it like
Format(tmpRS("calculatedValue"), "#.0000E+00") it works well.

When I try to add a "+" sign before it, it will not show up in excel.

so

"+" & Format(tmpRS("calculatedValue"), "#.0000E+00") strips the "+"

since everything is a string, why does it work when it comes out of the db in that format, but it won't work when I build it on the fly?



0
Comment
Question by:jackjohnson44
[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
  • 2
  • 2
5 Comments
 
LVL 13

Expert Comment

by:Mark_FreeSoftware
ID: 16907746

that is because it is stored as a string, and it comes out as a string

when you build on the fly, it gets stored as string, but without the + sign, because excel formats it before storing it
0
 
LVL 26

Accepted Solution

by:
EDDYKT earned 1000 total points
ID: 16910528
how about

"'+" & Format(tmpRS("calculatedValue"), "#.0000E+00")

' add single quote in front
0
 

Author Comment

by:jackjohnson44
ID: 16911337
I can't put a single quote in front of it.

Why does excel format the string that I build, but the string that comes out of the db does not get formatted?

If I assign the database value to a string, then write it to excel, the "+" gets dropped.

            tmpMeas = tmpRS("measure")
            xlsheet.Cells(counter, 12).value = tmpMeas
shows
   "3.21E-05"

while
            xlsheet.Cells(counter, 12).value = tmpRS("measure")
shows
   "+3.21E-05"

how do I get writing a variable to behave the same way using a recordset does?

The value is stored in a database as type string.
0
 

Author Comment

by:jackjohnson44
ID: 16911608
I was able to get it to work by assigning the value to the recordset, then printing the value from the recordset.
Is there a reason I can't do this by assigning it to a variable?

This works:

            If Len(tmpRS("calculatedValue")) Then
                tmpRS("calculatedValue") = " +" & Format(tmpRS("calculatedValue"), "#.0000E+00")
            Else
                tmpRS("calculatedValue") = ""
            End If
               
            xlsheet.Cells(counter, 13).value = tmpRS("calculatedValue")
0
 
LVL 26

Expert Comment

by:EDDYKT
ID: 16911638
xlsheet.Cells(counter, 12).value = tmpRS("measure")


when you do this what is the format cell tell you
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

721 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