Click to See Complete Forum and Search --> : VB Left of a character in a number


Danbabe
05-14-2007, 12:38 PM
Hi guys,

yet again, I need your help. A user will enter the room measurements in Metres into a text box. I am trying to convert the Metres in Feet and Inches so the result will show both.

I have the following script already set-up:

'Bring in the text box
Dim fRoom
fRoom = Request.Form("room")

Dim Result, workFeet
workFeet = left(fRoom * 3.2808399, 5)
Result = fRoom & "m (" & workFeet & "')

If the user enters a low figure in Metres such as '1', then Result=
1m (3.280 ')

If the user enters a higher figure such as 10 then the Result=
10m (32.28')

What I need to do is write the feet and inches correctly. Is there anyway I can ask the code to show me all numbers to the left of the '.' in workFeet? Then show me all numbers to right of '.' of workFeet? So what I need from a number od 32.28 =
32
28

Any ideas chaps?

Cheers

Dan

lmf232s
05-14-2007, 03:57 PM
well based on your question you could use the split function

Dim aTemp : aTemp = Split(Value, ".")

Response.write aTemp(0) & "<BR>"
Response.write aTemp(1) & "<BR>"

Danbabe
05-14-2007, 03:59 PM
Thank you very much. That worked perfect.

Dan

russell
05-15-2007, 08:38 AM
while that certainly works, why not use a mathematical calculation, converting metres to inches...

Const inchesPerMetre = 39.37

Dim metres
Dim feet
Dim inches

metres = 10

inches = int(metres * inchesPerMetre)
feet = int(inches / 12)
inches = inches mod 12

'msgbox feet & "' " & inches & """"


this could all be done on one line too...or even better, converted to a function