Solved

# format function in VB6

Posted on 2003-03-17
Medium Priority
404 Views
Hi
I am trying to format a a string as follows:
The idea here is to offset the string and then scale it.

Example:

assume we have -5.

I want to add +5 to this (offsetting) and then multiply the result by 2 (scaling).

Thus the result for -5 after "formatting" must be 0.
Similarly if value is -4...we must get -4(+5) = 1...1*2 = 2 after "formatting"

I am not able to figure out how to do this in VB6 using format function.

Any help is greatly appreciated

Thanks
Raghu
0
Question by:raghu_vs
[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

LVL 2

Expert Comment

ID: 8153411
raghu,

You aren't being very clear.

You have a math formula and when you obtain the results you want to format it?

If so then:

Text1.Text = Format\$(result, "#,###,###.#0") would format the result with comma separators, 2 decimal places and if the result value is equal to 0 (zero) then a 0 (zero) will show.

If this isn't what you need, post another comment.

Sweat

0

Author Comment

ID: 8153460
Hi
Sorry for not being clear!

This is what I am doing:
I have voltage value..(like -5v, -4v etc).
Now I have to represent these voltage values in
newton (Force) (like 0N, 2N, etc)

This means -5v corresponds to 0N
-4v corresponds to 2N

and so on............

For this I need to offset the voltage value (ex: -5v)
by 5 volts and then multply it by 2 to get 0N (in case of
-5V)

thus  -5v ->   -5+5 = 0 *2 = 0N
-4v ->   -4+5 = 1 *2 = 2N

and so on..

Hope u got the idea

Thanks
Raghu

0

LVL 1

Expert Comment

ID: 8153461
Dim myStr
Dim myoffset
Dim myScale

myStr = "-4"
myoffset = 5
myscale = 2

msgbox (val(mystr) + myoffset) * myscale
0

LVL 1

Accepted Solution

JH0401 earned 75 total points
ID: 8153541
Here just place a command button and a text box on a form and paste this code.  Put the voltage in the text box & press the command button -- it will msgbox the newton value & then change the text box to the newton value.

Option Explicit

Private Sub Command1_Click()

Dim myStr\$
Dim myoffset%
Dim myScale%
Dim myNew as double
myStr = val(text1)
myoffset = 5
myscale = 2

myNew = (val(mystr) + myoffset) * myscale
msgbox myNew
text1 = mynew & "N"

end sub
0

Author Comment

ID: 8153689
Thanks for the help.
Also Could this be done using only the format function?

Thanks
Raghu
0

LVL 1

Expert Comment

ID: 8153734
If you have a text box - call it TextVoltage & you have another text box - call it TextNewton you could use the following conversion.

TextNewton = (val(TextVoltage) + 5) * 2
0

LVL 1

Expert Comment

ID: 8153739
or if you want to show N you could use

TextNewton = (val(TextVoltage) + 5) * 2 & "N"
0

LVL 1

Expert Comment

ID: 8153756
is this what you wanted??? let me know -- thanks
0

LVL 11

Expert Comment

ID: 8156771
ForceVal = Format((val(Voltage) + 5) * 2, "0.0 N")
0

## Featured Post

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
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
Course of the Month14 days, left to enroll