Newsgroup: it.comp.lang.visual-basic
Titolo: Ratio Calculator

Hey Group :o)
Hope you all can help me out with this little bother I've got....
I've come to a point in my project where I need to find a ratio (X:Y)
from it's divided number.
For example:
Going from 4:3 = 0.25 = 4:3, see what I mean?
I've made a routine (which I don't have on me) similar to this:
__________________________________________________
Dim X As Integer
Dim intTemp As Integer
Dim intTemp2 As Integer
intTemp = 0.5625 '16:9 ratio
intTemp2 = intTemp
Do While InStr(1, intTemp, ".", vbTextCompare) > 0
     X = X + 1
     intTemp = intTemp2 * X
Loop
Text1.Text = intTemp2 & ":" & X
__________________________________________________
Right, see how this works?  It works fine, although I'd love to work
out a routine which can work it out a few milliseconds faster...
Anyway, I've put the same routine in to my project (this was just to
test) and it doesn't work and it's got me quite puzzled!  I've checked
what the variables are equal to but what happens is that it completely
skips the looped part leaving a ratio of 1:0.  The InStr = 2 as it
should, the variable in the InStr was correct at the test of 0.67... if
it equals 2, then why does the InStr return a false answer?
FYI: It's working out the first variable (intTemp) by dividing the
lowest dimension of the image to the largest, but this should not make
a difference.... right?
Anyone shed some light?
- Jester.

 
First: intTemp cannot have 0.5625 value, because intTemp is integer. The 
vb compiler round 0.5625 to 1
Second Text1.Text = intTemp2 & ":" & X shows intTemp2 that is 0.5625(but 
the compiler shows intTemp2 that is rounded). You must shows intTemp value
Third: in the If test you must write InStr(intTemp, ",") because in 
english math convention the point on decimal numbers is the comma.
have a good job
Bye
Ste
-- 
'gnurant come una cucuzza

>__________________________________________________
You could be 'gnurant, but your english is not so bad!

 english math convention the point on decimal numbers is the comma.
Quarth: this is an ITalian NG, please post in Italian. ;)
Ciao
--
Reporting tool: 
http://www.neodatatype.net

 
Quint: you have ragion, but se chist scriv in english, commaarrispond? 
ahahah...ciauz


 english math convention the point on decimal numbers is the comma.
What caz are you writing?
The CStr uses local decimal separator, so this code works differently 
on different OS, regardless of math conventions...
Anyway, intTemp is Integer...
Albert
-- 
Autore di
"Petting for Dummies"


http://snipurl.com/gomz
-- 
----------------------------
Mauro Gamberini

 on different OS, regardless of math conventions...
You have now discovered the hot water!


 
http://snipurl.com/gomz
Fantastico... "Company -> The Organisation"
Ciao

 You have now discovered the hot water!
Allora tu avevi scoperto l'acqua fredda, visto che hai scritto il 
contrario.
Ciao
Alberto


Hahaha, what argument have I started?
Anyway...
1) Sorry for posting it not in Italian on an Italian NG.
2) You are right about the integer, it worked at home, I probably used
a double, I can't remember.
3) In the test where it's not working, I should use a "," (comma) for
the InStr?
I'll give it a try and I really appreciate you all replying so quickly.
 I don't understand though that even though I might have to use a
comma, the InStr is still returning a value of two and I told the loop
to keep going while it was greater than 0.  And I don't know why when
the code was the same works on one project and not other.
Anyway, I'll try CStr, or the comma in InStr - ta for the help!
- Jester.

 - Jester.
-- 



ora capisco perchč tanti programmi  tanto bene non vanno....
Il codice corretto č
Dim X  as long
Dim intTemp as double
Dim intTemp2  as double
intTemp = 0.5625 
intTemp2 = intTemp
Do While clng(intTemp) <> inttemp
     X = X + 1
     intTemp = intTemp2 * X
Loop
msgbox intTemp & ":" & X
 
by
Giovanni