Need help with converting! (1 Viewer)

FreshCoder

Registered User.
Local time
Today, 11:05
Joined
Sep 22, 2018
Messages
33
Hi!

I need help regards to converting some measurements. From centimeter to meter and so on. I tried a bit myself, but i havent been able to break the code!:confused:




Code:
Option Compare Database
Option Explicit

Private Sub comCalculate_Click()
    Dim stdset As dao.Recordset
    Dim strsql As String
    Dim factor As Double, divisor As Double
    Dim AsMeter As Double, Answer As Double

    
    strsql = "SELECT * from Converting WHERE from = '" & cmbFrom & "'"
    Set stdset = CurrentDb.OpenRecordset(strsql)
    With stdset
        factor = 0
        Do While Not .EOF
            factor = !factorToMeter
            .MoveNext
        Loop
        .Close
    End With
    txtAnswer = factor * txtValue
End Sub
 

Attachments

  • ConvertingValues.accdb
    688 KB · Views: 31
  • Calculation-Measurements.PNG
    Calculation-Measurements.PNG
    21.2 KB · Views: 49

FreshCoder

Registered User.
Local time
Today, 11:05
Joined
Sep 22, 2018
Messages
33
Translated the access file.
 

Attachments

  • ConvertingValues.accdb
    688 KB · Views: 33

isladogs

MVP / VIP
Local time
Today, 19:05
Joined
Jan 14, 2017
Messages
18,258
Not sure what you mean by 'break the code'

What I do know is several of your conversion factors are wrong.
For example
1 yard = 0.9144 metres and not 0.9 m
1 mile = 1609.344 metres and not 1652 m.... Etc

If you're going to convert then you need to do it accurately otherwise it's a total waste of time and effort
 

FreshCoder

Registered User.
Local time
Today, 11:05
Joined
Sep 22, 2018
Messages
33
I meant solve the problem by break the code! Sorry.

Yeah, but lets just say these are the values i got to work with.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 02:05
Joined
May 7, 2009
Messages
19,246
values are based in Excel Convert() function
 

Attachments

  • ConvertingValues.zip
    27.3 KB · Views: 32

isladogs

MVP / VIP
Local time
Today, 19:05
Joined
Jan 14, 2017
Messages
18,258
I'm no wiser.
The code seems to work ok on the quick tests I did (so why do you want to break it?)
However, the answers will be wrong where the conversion factor is incorrect.

BTW nobody is paid for answering questions at this forum.
All of us have other things to do so you can't expect instant responses
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 13:05
Joined
Feb 28, 2001
Messages
27,323
When you say "break the code" are you speaking as a code-breaker trying to figure out what something does and how it does it?

And remember that you are asking an international gathering from New Orleans to the UK to ArnelGP who is somewhere out there. So if we don't give you fast response, maybe some of us are in the restroom or eating or sleeping. Today IS Saturday, which is not a work day for most of us. We have potential answers from probably 19 of the world's main time zones (the other 5 being mostly aquatic). Chillax, dude.

The table you showed us in your picture appears to list multiplication factors that one might use to convert something else to meters. (Though as noted, some of the factors are wrong.)

The reason your code segment fails is because the loop is wrongly structured. You don't need a loop at all. ALSO, NEVER EVER name a field or variable to match a keyword, such as WHERE from = '" & cmbFrom & "'"

You might get away with a DLookup, in which case you would look up the conversion factor based on a DLookup as

Code:
Factor = DLookup( "[FactorToMeter]", "Converting", "[From]='"  & Me.cmbFrom & "'")

You would have to check whether this returned anything at all because it assumes you are correctly spelling the units to be looked up. If your input was "veeblefetzers" for example, you would get back a null from the lookup.

Watch out for the two apostrophes in the quoted strings. They are needed to manage the string substitution you are doing in the criteria portion of the DLookup.

But you will have nine kinds of Hell from Access if you use a reserved word as a field name, e.g. From, so change that. And if you say you can't, then your problem is partly of your own making and we can't help you with that aspect of this problem.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 02:05
Joined
May 7, 2009
Messages
19,246
you might want to consider this. downliad a conversion table chart and fill your table.
 

Attachments

  • ConvertingValues2.zip
    28.6 KB · Views: 36

FreshCoder

Registered User.
Local time
Today, 11:05
Joined
Sep 22, 2018
Messages
33
Sorry for being stressed. Ill be more patient next time i wonder of something. Thanks for help people and special thanks to arnelgp for making that program. I can use that in my project :) Solved :)
 

Gasman

Enthusiastic Amateur
Local time
Today, 19:05
Joined
Sep 21, 2011
Messages
14,463
The problem with that is arnelgp is doing all your work for you and you are not really learning anything.?
 

Users who are viewing this thread

Top Bottom