Posts: 4,143
Threads: 187
Joined: Apr 2022
Reputation:
253
01-19-2025, 05:18 PM
(This post was last modified: 01-19-2025, 05:25 PM by bplus.)
Two!
Code: (Select All)
Input "Enter a Number to convert , (comma) 1 to convert to mm from inches or ,(comma) any other for inches "; num, op%
Print _IIf(op% = 1, num * 25.4, num / 25.4) ' 25.4 mm per inch
This takes advantage of being able to assign multiple input values to variables.
"I'm lazy. I like to program in a manner that supports me being as lazy as possible. Big Grin"
I am that way with typing, unfortunately NOT with Editing!
Yeah 2 liner to show both conversions good too! Saves on variables +1
b = b + ...
Posts: 2,943
Threads: 344
Joined: Apr 2022
Reputation:
272
(01-19-2025, 05:18 PM)bplus Wrote: Two!
Code: (Select All)
Input "Enter a Number to convert , (comma) 1 to convert to mm from inches or ,(comma) any other for inches "; num, op%
Print _IIf(op% = 1, num * 25.4, num / 25.4) ' 25.4 mm per inch
This takes advantage of being able to assign multiple input values to variables.
You're going in the wrong direction here. The usage is getting more obtuse and harder to decipher; not easier. Keep it simple and easy to understand and use. Lines of code don't matter for squat if you can't use the end product easily.
Posts: 4,143
Threads: 187
Joined: Apr 2022
Reputation:
253
01-19-2025, 05:30 PM
(This post was last modified: 01-19-2025, 05:33 PM by bplus.)
Yeah better!
Code: (Select All)
Input "Enter a Number to convert inches to mm and vice versa"; num
Print num * 25.4; "mm", num / 25.4; "inches"
Why choose get 'em BOTH! Be generous
b = b + ...
Posts: 2,943
Threads: 344
Joined: Apr 2022
Reputation:
272
(01-19-2025, 05:30 PM)bplus Wrote: Yeah better!
Code: (Select All)
Input "Enter a Number to convert inches to mm and vice versa"; num
Print num * 25.4; "mm", num / 25.4; "inches"
That's basically what I did on the other page, except I used to PRINT USING to make certain that I didn't end up with some crazy scientific notation values for my numbers. 1 mm = 6.12345678981264827556tF+3 or such. LOL!
Posts: 4,143
Threads: 187
Joined: Apr 2022
Reputation:
253
Is two lines small enough? No?
Code: (Select All)
Print Val(_InputBox$("Convert number from inches to mm.", "Enter a number")) * 25.4
b = b + ...
Posts: 2,943
Threads: 344
Joined: Apr 2022
Reputation:
272
(01-19-2025, 06:13 PM)bplus Wrote: Is two lines small enough? No?
Code: (Select All)
Print Val(_InputBox$("Convert number from inches to mm.", "Enter a number")) * 25.4
Half the number of lines, with less than half the functionality. You're moving in the wrong direction again here.
What is with the obsession to try and produce the fewest possible number of lines of code for a program? Whatever happened to readability and functionality? Particularly when offering demos for a new user?
Posts: 2,943
Threads: 344
Joined: Apr 2022
Reputation:
272
Here -- one line, 29 characters:
Code: (Select All)
Input n:?n*25.4"mm"n/25.4"in"
Posts: 404
Threads: 58
Joined: Apr 2022
Reputation:
14
What a great question that turned out to be Protocog . Like dueling banjos, the music was awesome. There are some awfully clever codes on this site.
Posts: 4,143
Threads: 187
Joined: Apr 2022
Reputation:
253
01-19-2025, 08:12 PM
(This post was last modified: 01-19-2025, 10:32 PM by bplus.)
the dueting continues
"Wrong direction" ??? me with a true one-liner single statement showing another feature of QB64pe that can not be found in that other vesion of QB64.
Low bytes is good too, for sure!, but that is another direction ("colonscopey" let's call it) which I don't dare call "wrong", just a little misguided maybe.
let me quote some guy I know and love:
"Particularly when offering demos for a new user?"
yeah Mark try to have the last word with that guy!
@Dimster what do you mean WAS awesome?
b = b + ...
Posts: 2,943
Threads: 344
Joined: Apr 2022
Reputation:
272
01-20-2025, 12:56 AM
(This post was last modified: 01-20-2025, 01:09 AM by SMcNeill.)
@bplus I wracked my poor brain to death, and I finally came up with a single line of code that does everything -- both inch to mmm AND mm to inch conversion.
Code: (Select All)
Print _IIf(Shell("@echo off & set /P input=Please enter a value with positive for inch and negative for millimeter: & echo|set /p=%input%|clip") <> 0 Or Val(_Clipboard$)<0, str$(Val(_Clipboard$) / -25.4)+" inches", str$(Val(_Clipboard$) * 25.4) + " millimeters")
And that is one loooong line of code, fit only for the brain exercise, and not one that anyone should ever really study up on and try to learn from. LOL!
Give it a positive number to go from inch to mm. Give it a negative number to go from mm to inch. One command, tweaked completely insanely, to do everything within a single line of code and not colon cheating involved.
|