08-23-2025, 08:04 PM
Forgive me if I overstep here, but this code was just begging to be simplified down into a nice set of repeatable subs and simplified logic. See if this isn't the *exact* same code as what you wrote, but in a much more modular and expandable way?
Instead of copy/pasting all those routines repeatedly and just changing a few parts in them, make them a simple function and just pass them the parts as needed. Like this, you can easily add any new functionality you'd like into your program as long as it has a simple converted_amount = original_amout * multiplier formula associated to it. Anything more complex (such as the F2C and C2F formulas), you'd have to calculate separately as I've done here, but for everything else, just let that one simple SUB do all the work for you.
It's dropped several hundred lines out of this code, simplified it, and made it much easier to understand and maintain, in my opinion.
What do you think? It's still everything you had before; it's just structured to make use of SUBs and FUNCTIONs instead of being so copy/paste orientated.
Code: (Select All)
'Converter by SierraKen
'Made on August 23, 2025
Screen _NewImage(800, 600, 32)
_PrintString (368, 30), "Converter"
_Title "Converter - by SierraKen"
For x = 1 To 30
For y = 1 To 30
c = c + .5
Line (100 + x, 100 + y)-(300 - x, 150 - y), _RGB32(100 + c, 100 + c, 200 + c), B 'c2f
Line (100 + x, 175 + y)-(300 - x, 225 - y), _RGB32(100 + c, 100 + c, 200 + c), B 'f2c
Line (100 + x, 250 + y)-(300 - x, 300 - y), _RGB32(100 + c, 100 + c, 200 + c), B 'g2o
Line (100 + x, 325 + y)-(300 - x, 375 - y), _RGB32(100 + c, 100 + c, 200 + c), B 'o2g
Line (100 + x, 400 + y)-(300 - x, 450 - y), _RGB32(100 + c, 100 + c, 200 + c), B 'k2p
Line (100 + x, 475 + y)-(300 - x, 525 - y), _RGB32(100 + c, 100 + c, 200 + c), B 'p2k
Line (500 + x, 100 + y)-(700 - x, 150 - y), _RGB32(100 + c, 100 + c, 200 + c), B 'km2m
Line (500 + x, 175 + y)-(700 - x, 225 - y), _RGB32(100 + c, 100 + c, 200 + c), B 'm2km
Line (500 + x, 250 + y)-(700 - x, 300 - y), _RGB32(100 + c, 100 + c, 200 + c), B 'l2g
Line (500 + x, 325 + y)-(700 - x, 375 - y), _RGB32(100 + c, 100 + c, 200 + c), B 'g2l
Line (500 + x, 400 + y)-(700 - x, 450 - y), _RGB32(100 + c, 100 + c, 200 + c), B 'kmph2mph
Line (500 + x, 475 + y)-(700 - x, 525 - y), _RGB32(100 + c, 100 + c, 200 + c), B 'mph2kmph
Next y
Next x
Color _RGB32(0, 0, 0), _RGB32(255, 255, 255)
_PrintString (120, 120), "Celsius To Fahrenheit": _PrintString (520, 120), "Kilometers To Miles"
_PrintString (120, 195), "Fahrenheit To Celsius": _PrintString (520, 195), "Miles To Kilometers"
_PrintString (140, 270), "Grams To Ounces": _PrintString (540, 270), "Liters To Gallons"
_PrintString (140, 345), "Ounces To Grams": _PrintString (540, 345), "Gallons To Liters"
_PrintString (120, 420), "Kilograms To Pounds": _PrintString (520, 420), "KM/Hour To Miles/Hour"
_PrintString (120, 495), "Pounds To Kilograms": _PrintString (520, 495), "Miles/Hour To KM/Hour"
mouseWasDown = 0
Do
Do While _MouseInput: Loop
xx = _MouseX: yy = _MouseY
mouseIsDown = -_MouseButton(1)
If mouseIsDown = 1 And mouseWasDown = 0 Then 'move this outside all those IF conditions
'Just check if the mouse was properly clicked once. If it wasn't, nothing else matters.
Select Case xx 'I prefer select case for ease of organization, as shown here
Case 100 To 300 'left side of the button list
Select Case yy
Case 100 To 150
celsius$ = _InputBox$("Celsius To Fahrenheit", "Enter Celsius Degrees")
If Val(celsius$) = 0 And celsius$ <> "0" Then Exit Select
ce = Val(celsius$)
F = (ce * 1.8) + 32
_MessageBox "Fahrenheit", Str$(F), ""
RestoreFocus
Case 175 To 225
Fahrenheit$ = _InputBox$("Fahrenheit To Celsus", "Enter Fahrenheit Degrees")
If Val(Fahrenheit$) = 0 And Fahrenheit$ <> "0" Then Exit Select
f2 = Val(Fahrenheit$)
ce2 = (f2 - 32) / 1.8
_MessageBox "Celsius", Str$(ce2), ""
RestoreFocus
Case 250 To 300: Convert "Grams", "Ounces", 0.35274, "Ounces"
Case 325 To 375: Convert "Ounces", "Grams", 28.3495, "Grams"
Case 400 To 450: Convert "Kilograms", "Pounds", 2.20462, "Pounds"
Case 475 To 525: Convert "Pounds", "Kilograms", 1 / 2.20462, "Kilograms"
End Select
Case 500 To 700 'right side of the button list
Select Case yy
Case 100 To 150: Convert "Kilometers", "Miles", 0.621371, "Miles"
Case 175 To 225: Convert "Miles", "Kilometers", 1.60934, "Kilometers"
Case 250 To 300: Convert "Liters", "Gallons", 0.264172, "Gallons"
Case 325 To 375: Convert "Gallons", "Liters", 3.78541, "Liters"
Case 400 To 450: Convert "KPH", "MPH", 0.621371, "Miles Per Hour"
Case 275 To 525: Convert "MPH", "KPH", 1.60934, "Kilometers Per Hour"
End Select
End Select
End If
mouseWasDown = mouseIsDown
Loop Until InKey$ = Chr$(27)
System
Sub Convert (from$, to$, multiplier##, long_desc$)
box_title$ = from$ + " to " + to$
prompt$ = "Enter " + from$
user_input$ = _InputBox$(box_title$, prompt$)
v## = Val(user_input$)
If v## = 0 And user_input$ <> "0" Then Exit Sub
_MessageBox long_desc$, Str$(v## * multiplier##), ""
RestoreFocus
End Sub
Sub RestoreFocus
_Delay .25
positionX& = _ScreenX
positionY& = _ScreenY
_ScreenClick positionX& + 30, positionY& + 100
End Sub
Instead of copy/pasting all those routines repeatedly and just changing a few parts in them, make them a simple function and just pass them the parts as needed. Like this, you can easily add any new functionality you'd like into your program as long as it has a simple converted_amount = original_amout * multiplier formula associated to it. Anything more complex (such as the F2C and C2F formulas), you'd have to calculate separately as I've done here, but for everything else, just let that one simple SUB do all the work for you.
It's dropped several hundred lines out of this code, simplified it, and made it much easier to understand and maintain, in my opinion.

What do you think? It's still everything you had before; it's just structured to make use of SUBs and FUNCTIONs instead of being so copy/paste orientated.

