I would like to use a script to provide calculations from kg to lbs and viceversa

I would like a script that a user can simply double click.
It should prompt them if they want to convert from lbs to kg or kg to lbs.
Depending on what is selected they enter an amount, and then the calculated amount will then be provided for them.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Joe KlimisCommented:
Hi Try the following

A user friendly form :-)

#region Script Settings
#<ScriptSettings xmlns="http://tempuri.org/ScriptSettings.xsd">
#  <ScriptPackager>
#    <process>powershell.exe</process>
#    <arguments />
#    <extractdir>%TEMP%</extractdir>
#    <files />
#    <usedefaulticon>true</usedefaulticon>
#    <showinsystray>false</showinsystray>
#    <altcreds>false</altcreds>
#    <efs>true</efs>
#    <ntfs>true</ntfs>
#    <local>false</local>
#    <abortonfail>true</abortonfail>
#    <product />
#    <version></version>
#    <versionstring />
#    <comments />
#    <company />
#    <includeinterpreter>false</includeinterpreter>
#    <forcecomregistration>false</forcecomregistration>
#    <consolemode>false</consolemode>
#    <EnableChangelog>false</EnableChangelog>
#    <AutoBackup>false</AutoBackup>
#    <snapinforce>false</snapinforce>
#    <snapinshowprogress>false</snapinshowprogress>
#    <snapinautoadd>2</snapinautoadd>
#    <snapinpermanentpath />
#    <cpumode>1</cpumode>
#    <hidepsconsole>false</hidepsconsole>
#  </ScriptPackager>

#region ScriptForm Designer

#region Constructor



#region Post-Constructor Custom Code


#region Form Creation
#Warning: It is recommended that changes inside this region be handled using the ScriptForm Designer.
#When working with the ScriptForm designer this region and any changes within may be overwritten.
#~~< Form1 >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
$Form1 = New-Object System.Windows.Forms.Form
$Form1.ClientSize = New-Object System.Drawing.Size(287, 172)
$Form1.Text = "Weight Convert V1.0"
$Form1.BackColor = [System.Drawing.SystemColors]::InactiveCaption
#~~< RadioButtonLb >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
$RadioButtonLb = New-Object System.Windows.Forms.RadioButton
$RadioButtonLb.Location = New-Object System.Drawing.Point(177, 63)
$RadioButtonLb.Size = New-Object System.Drawing.Size(104, 24)
$RadioButtonLb.TabIndex = 7
$RadioButtonLb.TabStop = $true
$RadioButtonLb.Text = "Pounds to KG"
$RadioButtonLb.UseVisualStyleBackColor = $true
#~~< RadioButtonkg >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
$RadioButtonkg = New-Object System.Windows.Forms.RadioButton
$RadioButtonkg.Location = New-Object System.Drawing.Point(177, 41)
$RadioButtonkg.Size = New-Object System.Drawing.Size(95, 24)
$RadioButtonkg.TabIndex = 6
$RadioButtonkg.TabStop = $true
$RadioButtonkg.Text = "kg to Pounds"
$RadioButtonkg.UseVisualStyleBackColor = $true
#~~< TextBox2 >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
$TextBox2 = New-Object System.Windows.Forms.TextBox
$TextBox2.Location = New-Object System.Drawing.Point(12, 109)
$TextBox2.ReadOnly = $true
$TextBox2.Size = New-Object System.Drawing.Size(131, 20)
$TextBox2.TabIndex = 4
$TextBox2.Text = ""
#~~< TextBox1 >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
$TextBox1 = New-Object System.Windows.Forms.TextBox
$TextBox1.Location = New-Object System.Drawing.Point(7, 67)
$TextBox1.Size = New-Object System.Drawing.Size(136, 20)
$TextBox1.TabIndex = 3
$TextBox1.Text = ""
#~~< Label1 >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
$Label1 = New-Object System.Windows.Forms.Label
$Label1.Location = New-Object System.Drawing.Point(33, 8)
$Label1.Size = New-Object System.Drawing.Size(150, 30)
$Label1.TabIndex = 2
$Label1.Text = "Powershell Converter"
#~~< btn_convert >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
$btn_convert = New-Object System.Windows.Forms.Button
$btn_convert.Location = New-Object System.Drawing.Point(177, 93)
$btn_convert.Size = New-Object System.Drawing.Size(104, 36)
$btn_convert.TabIndex = 1
$btn_convert.Text = "Convert"
$btn_convert.UseVisualStyleBackColor = $true
#~~< btn_quit >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
$btn_quit = New-Object System.Windows.Forms.Button
$btn_quit.Location = New-Object System.Drawing.Point(177, 145)
$btn_quit.Size = New-Object System.Drawing.Size(75, 23)
$btn_quit.TabIndex = 0
$btn_quit.Text = "Quit"
$btn_quit.UseVisualStyleBackColor = $true


#region Custom Code


#region Event Loop

function Main{



#region Event Handlers

function RadioButtonLbClick( $object ){

function RadioButtonkgClick( $object ){
	$RadioButtonkg.checked = $true
	$RadioButtonLb.checked = $false

function Btn_convertClick($object)
	if ($RadioButtonkg.checked )
	{ $TextBox2.Text = [single]($TextBox1.Text) * 2.2046226218 }
	{ $TextBox2.Text = [single]($TextBox1.Text) / 2.2046226218  }


function Btn_quitClick( $object ){

function TextBox1TextChanged( $object ){


Main # This call must remain below all other event functions


Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Here is a vbs:
Sub Demo()
    Dim dblAmount
    Dim intMeasurment
    Dim dblResult
    intMeasurment = InputBox("Which measurment would you like to convert from?" & vbCrLf & vbCrLf & "For ''lbs to kg'' type 1" & vbCrLf & "For ''kg to lbs'' type 2", "Measurment Conversion")
    dblAmount = InputBox("Please enter the weight to convert.", "Measurment Conversion")
    dblResult = (IIf(intMeasurment = 1, dblAmount / 0.4535922921969, dblAmount * 2.204623))
    MsgBox dblResult
End Sub

Open in new window

100questionsAuthor Commented:
@joeklimis - Is your script a batch script, Powershell or VBScript?
Making Bulk Changes to Active Directory

Watch this video to see how easy it is to make mass changes to Active Directory from an external text file without using complicated scripts.

Joe KlimisCommented:
this is a Powershell script , wich uses .net forms

just save it into a file and run it in the normal way  

100questionsAuthor Commented:
@MacroShadow - when trying to run the script nothing happens.
Joe KlimisCommented:
try adding   Demo()  as the last line to invoke the subroutine, you may not need the ()
100questionsAuthor Commented:
Joe are you referring to the script from MacroShadow?
100questionsAuthor Commented:
@MacroShadow - I added the Demo(), however after I enter the weight to convert, it does not calculate anything..
100questionsAuthor Commented:
@MacroShadow - if I try to run the script by doubleclicking the vbs file, I get an error:
Type mismatch: 'IIf'
Code:  800A000D
Joe KlimisCommented:
@100questions  - Yes I was , I am guessing this needed to be VB, its a  sham as the Powershell rocked  :-)

did you try the powershell ?
Sorry, this works.
Dim dblAmount
Dim intMeasurment
Dim dblResult
intMeasurment = InputBox("Which measurment would you like to convert from?" & vbCrLf & vbCrLf & "For ''lbs to kg'' type 1" & vbCrLf & "For ''kg to lbs'' type 2", "Measurment Conversion")
dblAmount = InputBox("Please enter the weight to convert.", "Measurment Conversion")
If intMeasurment = 1 Then
    dblResult = dblAmount / 0.4535922921969
    dblResult = dblAmount * 2.204623
End If
MsgBox dblResult

Open in new window

100questionsAuthor Commented:
Thanks everyone, both work well.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.