format function in VB6

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
raghu_vsAsked:
Who is Participating?
 
JH0401Connect With a Mentor Commented:
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
 
SweatCommented:
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
 
raghu_vsAuthor Commented:
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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
JH0401Commented:
Dim myStr
Dim myoffset
Dim myScale

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

msgbox (val(mystr) + myoffset) * myscale
0
 
raghu_vsAuthor Commented:
Thanks for the help.
Also Could this be done using only the format function?


Thanks
Raghu
0
 
JH0401Commented:
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
 
JH0401Commented:
or if you want to show N you could use

TextNewton = (val(TextVoltage) + 5) * 2 & "N"
0
 
JH0401Commented:
is this what you wanted??? let me know -- thanks
0
 
supunrCommented:
ForceVal = Format((val(Voltage) + 5) * 2, "0.0 N")
0
All Courses

From novice to tech pro — start learning today.