08-23-2025, 09:08 PM
Steve, I found something I forgot to add LOL. I forgot to go to Focus (or your RestoreFocus) when a person clicks the Cancel button in the InputBox$. Sorry about that!
Here is your fixed version (I hope). Look at the code and make sure it's correct. I tested it and it seems to work good. I'll post my fixed version after yours.
Steve's version (fixed):
Here is my original version (fixed):
Here is your fixed version (I hope). Look at the code and make sure it's correct. I tested it and it seems to work good. I'll post my fixed version after yours.
Steve's version (fixed):
Code: (Select All)
'Converter by SierraKen - mod by Steve
'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
RestoreFocus
Exit Select
End If
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
RestoreFocus
Exit Select
End If
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
RestoreFocus
Exit Sub
End If
_MessageBox long_desc$, Str$(v## * multiplier##), ""
RestoreFocus
End Sub
Sub RestoreFocus
_Delay .25
positionX& = _ScreenX
positionY& = _ScreenY
_ScreenClick positionX& + 30, positionY& + 100
End Sub
Here is my original version (fixed):
Code: (Select All)
'Converter by SierraKen
'Made on August 23, 2025
Screen _NewImage(800, 600, 32)
_PrintString (368, 30), "Converter"
_Title "Converter - by SierraKen"
'c2f
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
Next y
Next x
Color _RGB32(0, 0, 0), _RGB32(255, 255, 255)
_PrintString (120, 120), "Celsius To Fahrenheit"
c = 0
'f2c
For x = 1 To 30
For y = 1 To 30
c = c + .5
Line (100 + x, 175 + y)-(300 - x, 225 - y), _RGB32(100 + c, 100 + c, 200 + c), B
Next y
Next x
Color _RGB32(0, 0, 0), _RGB32(255, 255, 255)
_PrintString (120, 195), "Fahrenheit To Celsius"
c = 0
'g2o
For x = 1 To 30
For y = 1 To 30
c = c + .5
Line (100 + x, 250 + y)-(300 - x, 300 - y), _RGB32(100 + c, 100 + c, 200 + c), B
Next y
Next x
Color _RGB32(0, 0, 0), _RGB32(255, 255, 255)
_PrintString (140, 270), "Grams To Ounces"
c = 0
'o2g
For x = 1 To 30
For y = 1 To 30
c = c + .5
Line (100 + x, 325 + y)-(300 - x, 375 - y), _RGB32(100 + c, 100 + c, 200 + c), B
Next y
Next x
Color _RGB32(0, 0, 0), _RGB32(255, 255, 255)
_PrintString (140, 345), "Ounces To Grams"
c = 0
'k2p
For x = 1 To 30
For y = 1 To 30
c = c + .5
Line (100 + x, 400 + y)-(300 - x, 450 - y), _RGB32(100 + c, 100 + c, 200 + c), B
Next y
Next x
Color _RGB32(0, 0, 0), _RGB32(255, 255, 255)
_PrintString (120, 420), "Kilograms To Pounds"
c = 0
'p2k
For x = 1 To 30
For y = 1 To 30
c = c + .5
Line (100 + x, 475 + y)-(300 - x, 525 - y), _RGB32(100 + c, 100 + c, 200 + c), B
Next y
Next x
Color _RGB32(0, 0, 0), _RGB32(255, 255, 255)
_PrintString (120, 495), "Pounds To Kilograms"
c = 0
'km2m
For x = 1 To 30
For y = 1 To 30
c = c + .5
Line (500 + x, 100 + y)-(700 - x, 150 - y), _RGB32(100 + c, 100 + c, 200 + c), B
Next y
Next x
Color _RGB32(0, 0, 0), _RGB32(255, 255, 255)
_PrintString (520, 120), "Kilometers To Miles"
c = 0
'm2km
For x = 1 To 30
For y = 1 To 30
c = c + .5
Line (500 + x, 175 + y)-(700 - x, 225 - y), _RGB32(100 + c, 100 + c, 200 + c), B
Next y
Next x
Color _RGB32(0, 0, 0), _RGB32(255, 255, 255)
_PrintString (520, 195), "Miles To Kilometers"
c = 0
'l2g
For x = 1 To 30
For y = 1 To 30
c = c + .5
Line (500 + x, 250 + y)-(700 - x, 300 - y), _RGB32(100 + c, 100 + c, 200 + c), B
Next y
Next x
Color _RGB32(0, 0, 0), _RGB32(255, 255, 255)
_PrintString (540, 270), "Liters To Gallons"
c = 0
'g2l
For x = 1 To 30
For y = 1 To 30
c = c + .5
Line (500 + x, 325 + y)-(700 - x, 375 - y), _RGB32(100 + c, 100 + c, 200 + c), B
Next y
Next x
Color _RGB32(0, 0, 0), _RGB32(255, 255, 255)
_PrintString (540, 345), "Gallons To Liters"
c = 0
'km/h to m/h
For x = 1 To 30
For y = 1 To 30
c = c + .5
Line (500 + x, 400 + y)-(700 - x, 450 - y), _RGB32(100 + c, 100 + c, 200 + c), B
Next y
Next x
Color _RGB32(0, 0, 0), _RGB32(255, 255, 255)
_PrintString (520, 420), "KM/Hour To Miles/Hour"
c = 0
'm/h to km/h
For x = 1 To 30
For y = 1 To 30
c = c + .5
Line (500 + x, 475 + y)-(700 - x, 525 - y), _RGB32(100 + c, 100 + c, 200 + c), B
Next y
Next x
Color _RGB32(0, 0, 0), _RGB32(255, 255, 255)
_PrintString (520, 495), "Miles/Hour To KM/Hour"
c = 0
mouseWasDown = 0
Do
Do While _MouseInput
xx = _MouseX
yy = _MouseY
If _MouseButton(1) Then
mouseIsDown = 1
Exit Do
Else
mouseIsDown = 0
End If
Loop
If xx > 100 And xx < 300 And yy > 100 And yy < 150 Then
If mouseIsDown = 1 And mouseWasDown = 0 Then
celsius$ = _InputBox$("Celsius To Fahrenheit", "Enter Celsius Degrees")
If Val(celsius$) = 0 And celsius$ <> "0" Then
GoSub focus
GoTo skip
End If
ct$ = LTrim$(celsius$)
ct2$ = RTrim$(celsius$)
If ct$ + ct2$ = "" Then
GoSub focus
GoTo skip
End If
ce = Val(celsius$)
F = (ce * 1.8) + 32
_MessageBox "Fahrenheit", Str$(F), ""
GoSub focus
End If
End If
If xx > 100 And xx < 300 And yy > 175 And yy < 225 Then
If mouseIsDown = 1 And mouseWasDown = 0 Then
Fahrenheit$ = _InputBox$("Fahrenheit To Celsus", "Enter Fahrenheit Degrees")
If Val(Fahrenheit$) = 0 And Fahrenheit$ <> "0" Then
GoSub focus
GoTo skip
End If
ct$ = LTrim$(Fahrenheit$)
ct2$ = RTrim$(Fahrenheit$)
If ct$ + ct2$ = "" Then
GoSub focus
GoTo skip
End If
f2 = Val(Fahrenheit$)
ce2 = (f2 - 32) / 1.8
_MessageBox "Celsius", Str$(ce2), ""
GoSub focus
End If
End If
If xx > 100 And xx < 300 And yy > 250 And yy < 300 Then
If mouseIsDown = 1 And mouseWasDown = 0 Then
grams$ = _InputBox$("Grams To Ounces", "Enter Grams")
If Val(grams$) = 0 And grams$ <> "0" Then
GoSub focus
GoTo skip
End If
ct$ = LTrim$(grams$)
ct2$ = RTrim$(grams$)
If ct$ + ct2$ = "" Then
GoSub focus
GoTo skip
End If
g = Val(grams$)
o = 0.035274 * g
_MessageBox "Ounces", Str$(o), ""
GoSub focus
End If
End If
If xx > 100 And xx < 300 And yy > 325 And yy < 375 Then
If mouseIsDown = 1 And mouseWasDown = 0 Then
ounces$ = _InputBox$("Ounces To Grams", "Enter Ounces")
If Val(ounces$) = 0 And ounces$ <> "0" Then
GoSub focus
GoTo skip
End If
ct$ = LTrim$(ounces$)
ct2$ = RTrim$(ounces$)
If ct$ + ct2$ = "" Then
GoSub focus
GoTo skip
End If
o2 = Val(ounces$)
g2 = 28.3495 * o2
_MessageBox "Grams", Str$(g2), ""
GoSub focus
End If
End If
If xx > 100 And xx < 300 And yy > 400 And yy < 450 Then
If mouseIsDown = 1 And mouseWasDown = 0 Then
kg$ = _InputBox$("Kilograms To Pounds", "Enter Kilograms")
If Val(kg$) = 0 And kg$ <> "0" Then
GoSub focus
GoTo skip
End If
ct$ = LTrim$(kg$)
ct2$ = RTrim$(kg$)
If ct$ + ct2$ = "" Then
GoSub focus
GoTo skip
End If
kg = Val(kg$)
p = kg * 2.20462
_MessageBox "Pounds", Str$(p), ""
GoSub focus
End If
End If
If xx > 100 And xx < 300 And yy > 475 And yy < 525 Then
If mouseIsDown = 1 And mouseWasDown = 0 Then
pounds$ = _InputBox$("Pounds To Kilograms", "Enter Pounds")
If Val(pounds$) = 0 And pounds$ <> "0" Then
GoSub focus
GoTo skip
End If
ct$ = LTrim$(pounds$)
ct2$ = RTrim$(pounds$)
If ct$ + ct2$ = "" Then
GoSub focus
GoTo skip
End If
p2 = Val(pounds$)
kg2 = p2 / 2.20462
_MessageBox "Kilograms", Str$(kg2), ""
GoSub focus
End If
End If
If xx > 500 And xx < 700 And yy > 100 And yy < 150 Then
If mouseIsDown = 1 And mouseWasDown = 0 Then
km$ = _InputBox$("Kilometers To Miles", "Enter Kilometers")
If Val(km$) = 0 And km$ <> "0" Then
GoSub focus
GoTo skip
End If
ct$ = LTrim$(km$)
ct2$ = RTrim$(km$)
If ct$ + ct2$ = "" Then
GoSub focus
GoTo skip
End If
km = Val(km$)
mi = km * 0.621371
_MessageBox "Miles", Str$(mi), ""
GoSub focus
End If
End If
If xx > 500 And xx < 700 And yy > 175 And yy < 225 Then
If mouseIsDown = 1 And mouseWasDown = 0 Then
miles$ = _InputBox$("Miles To Kilometers", "Enter Miles")
If Val(miles$) = 0 And miles$ <> "0" Then
GoSub focus
GoTo skip
End If
ct$ = LTrim$(miles$)
ct2$ = RTrim$(miles$)
If ct$ + ct2$ = "" Then
GoSub focus
GoTo skip
End If
mi = Val(miles$)
km = mi * 1.60934
_MessageBox "Kilometers", Str$(km), ""
GoSub focus
End If
End If
If xx > 500 And xx < 700 And yy > 250 And yy < 300 Then
If mouseIsDown = 1 And mouseWasDown = 0 Then
liters$ = _InputBox$("Liters To Gallons", "Enter Liters")
If Val(liters$) = 0 And liters$ <> "0" Then
GoSub focus
GoTo skip
End If
ct$ = LTrim$(liters$)
ct2$ = RTrim$(liters$)
If ct$ + ct2$ = "" Then
GoSub focus
GoTo skip
End If
l = Val(liters$)
Ga = 0.264172 * l
_MessageBox "Gallons", Str$(Ga), ""
GoSub focus
End If
End If
If xx > 500 And xx < 700 And yy > 325 And yy < 375 Then
If mouseIsDown = 1 And mouseWasDown = 0 Then
gallons$ = _InputBox$("Gallons To Liters", "Enter Gallons")
If Val(gallons$) = 0 And gallons$ <> "0" Then
GoSub focus
GoTo skip
End If
ct$ = LTrim$(gallons$)
ct2$ = RTrim$(gallons$)
If ct$ + ct2$ = "" Then
GoSub focus
GoTo skip
End If
g = Val(gallons$)
l2 = g * 3.78541
_MessageBox "Liters", Str$(l2), ""
GoSub focus
End If
End If
If xx > 500 And xx < 700 And yy > 400 And yy < 450 Then
If mouseIsDown = 1 And mouseWasDown = 0 Then
kmh$ = _InputBox$("KPH To MPH", "Enter KPH")
If Val(kmh$) = 0 And kmh$ <> "0" Then
GoSub focus
GoTo skip
End If
ct$ = LTrim$(kmh$)
ct2$ = RTrim$(kmh$)
If ct$ + ct2$ = "" Then
GoSub focus
GoTo skip
End If
kmh = Val(kmh$)
mph = 0.621371 * kmh
_MessageBox "Miles per Hour", Str$(mph), ""
GoSub focus
End If
End If
If xx > 500 And xx < 700 And yy > 475 And yy < 525 Then
If mouseIsDown = 1 And mouseWasDown = 0 Then
mph$ = _InputBox$("MPH to KPH", "Enter MPH")
If Val(mph$) = 0 And mph$ <> "0" Then
GoSub focus
GoTo skip
End If
ct$ = LTrim$(mph$)
ct2$ = RTrim$(mph$)
If ct$ + ct2$ = "" Then
GoSub focus
GoTo skip
End If
mph = Val(mph$)
kmh = 1.60934 * mph
_MessageBox "Kilometers per Hour", Str$(kmh), ""
GoSub focus
End If
End If
skip:
mouseWasDown = mouseIsDown
Loop Until InKey$ = Chr$(27)
Color _RGB32(255, 255, 255), _RGB32(0, 0, 0)
End
focus:
_Delay .25
positionX& = _ScreenX
positionY& = _ScreenY
_ScreenClick positionX& + 30, positionY& + 100
Return

