|
Post by johnnyrockets on Nov 4, 2023 17:07:32 GMT -5
Hi all, I have created my first program in LB now. It takes a string and reverses it, then it asks the user if they want to enter another string. Simple and fun to write! Now my question is, the "running program output window" seems to be of an arbitrary size and I'd like to control its size somewhat and maybe remove some of the controls like the horizontal scroll bar, etc. What command(s) would I look at or use to do this? Thanks! Johnny
|
|
|
Post by tsh73 on Nov 5, 2023 1:01:22 GMT -5
Hello Johnny You really better post some code then asking about code Becuase now we can only guess. But my guess is: if your code uses INPUT and PRINT, then your program works in MAINWIN mode (similar to DOS console in older BASICs) You can change mainwin size, in characters. That's all. Be warned that this change will stay and next program will start with same mainwin size, though. www.libertybasicuniversity.com/lb4help/JPOYX2.htmIf you want more, you should explore GUI programs, see Help/GUI Programming (onlain part is here www.libertybasicuniversity.com/lb4help/1MSUAK6.htmbut help installed with LB is likely newer. Do you have latest 4.5.1 LB?)
|
|
bplus
Full Member
Posts: 127
|
Post by bplus on Nov 5, 2023 9:26:06 GMT -5
It is fun! and so many ways to do it! do do k$ = input$(1) 'go ahead and try Enter loop until len(k$) if asc(k$)=13 then Print b$, "End of Program" end else f$ = f$ + k$ b$ = k$ + b$ print f$, b$ end if loop while 1
|
|
|
Post by johnnyrockets on Nov 5, 2023 16:08:33 GMT -5
Thanks guys!
Crazy thing is there a lot of ways to do the same thing!
Sorry for not posting, I'm a bit of a hack, so this probably is not the "best" way to do it...
Here is my code:
'*************************************************** '* '* Date/Author: 11/2023 '* '* Purpose: '* 1) Input a word '* 2) Store it in an array '* 3) Read it back out into a string '* 4) Print the string print it out in reverse '* '*************************************************** mainwin 40 12
do cls dim bigWord$(15)
'Resets newWord$ to an empty string newWord$ = ""
'Input a word input "Enter a word: "; myWord$
'Variable to hold the length of the word entered wordLength = len(myWord$)
'Loop through 5 times, grab each character individually, add together for x = wordLength to 1 step -1 midGrab$ = mid$(myWord$, x, 1) newWord$ = newWord$ + midGrab$ next x
'Print the word reversed print:print "That word in reversed is: "; newWord$
'Ask to reverse another word print input "Enter another word (type 'y') ? "; answer$
'Check what was entered loop until answer$ <> "y" stop
---------------------------------------
Thanks!
Johnny
|
|
bplus
Full Member
Posts: 127
|
Post by bplus on Nov 6, 2023 12:56:42 GMT -5
That's probably the first way I'd try! step 2 in comments not needed or done I think...
Do you know about recursive methods? A little challenge if you do ;-))
|
|
|
Post by johnnyrockets on Nov 6, 2023 17:54:29 GMT -5
Thanks bplus! I like your version!
J
|
|
bplus
Full Member
Posts: 127
|
Post by bplus on Nov 6, 2023 18:26:33 GMT -5
Here is my favorite version:
r$ = "Here is a cool one!" Print revs$(r$) Function revs$ (s$) If Len(s$) = 1 Then revs$ = s$ Else revs$ = revs$(Mid$(s$, 2)) + Left$(s$, 1) ': Print s End Function
|
|
bplus
Full Member
Posts: 127
|
Post by bplus on Nov 6, 2023 20:43:15 GMT -5
OK another one, reverse by swap$
input "Enter word to reverse ";word$ 'reverse by swap$ bplus 2023-11-06 rev$ = word$ for i = 1 to int(len(word$)/2) rev$ = swap$(rev$, i, len(word$)-i +1) next print word$;" reversed is ";rev$
function swap$(s$, p1, p2) for i = 1 to len(s$) if i <> p1 and i <> p2 then b$ = b$ + mid$(s$, i, 1) else if i = p1 then b$ = b$ + mid$(s$, p2, 1) else b$ = b$ + mid$(s$, p1, 1) end if next swap$ = b$ end function
|
|