Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - QB64Curious

Pages: [1] 2
1
Hi Steve,

Yes, something like.  But it doesn't have room for function names not on the list.

FreeBasic appears to have Procedure Pointers, in both the Dos and Windows and Linux versions.  Maybe QB64 can extend to something like this, but we're still stuck with QB 4.5 being what it is.

Thanks everyone for the clarifications, and the C examples.

Isn't this more or less something like what you're wanting? 

Code: QB64: [Select]
  1.     Input "Enter the function name to call =>"; func$
  2.     Print Eval(func$)
  3. Loop Until func$ = ""
  4.  
  5.  
  6. Function Eval (what$)
  7.     Select Case LCase$(what$)
  8.         Case "foo": Eval = Foo
  9.         Case "foo2": Eval = Foo2
  10.         Case "foo3": Eval = Foo3
  11.         Case "foo4": Eval = Foo4
  12.         Case Else: Print "Invalid function name.  You can only call FOO, FOO2, FOO3, or FOO4."
  13.     End Select
  14.  
  15.     Foo = 1
  16.  
  17.     Foo2 = 2
  18.  
  19.     Foo3 = 3
  20.  
  21.     Foo4 = 4
  22.  

A variable is storing the name of the function, and then we're calling the proper function when that variable is set.  Or am I missing something here and the original poster is asking for more than what I'm interpreting from this question?

2
Huh.  That's a disappointment.

Ok, thanks Luke.

No.

Edit: no, unless someone writes some extremely hacky C++.

3
QB64 Discussion / Re: Recomendation of some basic libraries for QB
« on: February 03, 2022, 10:33:32 pm »
Although it isn't packaged as a library, this site has some useful general functions:

https://www.pcjs.org/documents/books/mspl13/basic/qblang/

(This may already be mentioned in the QB64 wiki)

, and specifically, a function for printing at a specific Row and Column, while retaining the original position.  It's pretty much what was suggested elsewhere, but is a complete routine.

Code: QB64: [Select]
  1.     ' Print message at the designated row and column.
  2.     SUB PrntMsg(Row%,Col%,Message$) STATIC
  3.         ' Save current cursor position.
  4.         CurRow%=CSRLIN
  5.         CurCol%=POS(0)
  6.         ' Print the message at the location.
  7.         LOCATE Row%,Col% : PRINT Message$;
  8.         ' Restore cursor location.
  9.         LOCATE CurRow%,CurCol%
  10.     END SUB
  11.  

It doesn't include a COLOR attribute parameter, but it's a good start.

4
Hi,

One more question, for at least a few days.

Does 64 or 4.5 have some kind of AddressOf( FunctionName$ ), or Eval( FunctionName$ ) that allows us to call a subroutine or function from a variable containing that function name?

So if we have two functions

Code: QB64: [Select]
  1. Function FirstFunction
  2. '...
  3. '...
  4.  
  5. Function SecondFunction
  6. '...
  7. '...
  8.  

, and we put

Code: QB64: [Select]
  1. FunctionName$ = "FirstFunction"

, is there a way of using the variable FunctionName$, to call the function that it references?



5
QB64 Discussion / Re: Recomendation of some basic libraries for QB
« on: February 03, 2022, 04:04:02 pm »
Thanks, bplus.


Everything is passed by reference, QB64 is unusual in that. If you change a variable value inside a procedure (Sub or function) that value will be preserved when return from procedure IFF you use the same Type in variable pass as Type defined in Procedure. You can overcome this by setting varaibles as copies of arguments inside the procedure and then change those all you want inside procedure.

6
QB64 Discussion / Re: Recomendation of some basic libraries for QB
« on: February 03, 2022, 03:19:31 pm »
Thanks, LM.  That's the general way I would approach it, but I wanted to see if there were some existing libraries that dealt with these, as well as any side effects and parameter validation.


For Screen 0: You can get the current row and column using CSRLIN and POS(0).  Read/store those in variables first and use LOCATE to get back to that position later.

7
QB64 Discussion / Re: Recomendation of some basic libraries for QB
« on: February 03, 2022, 03:17:33 pm »
I understand, thanks.

Sorry I put () around arguments when calling a sub, wrong unless you use outdated CALL keyword first.

Sort myArray()

is what the "call" to a Sort sub looks like these days.

8
QB64 Discussion / Re: Recomendation of some basic libraries for QB
« on: February 03, 2022, 03:07:42 pm »
So the arrays are always passed by reference, correct?  So if you pass one to a Sub or Function, and that module modifieds the array, then when you return from that module, the array remains modified.  Is that right?

Thanks,


What? Explain in English... BTW Functions can not return arrays ie nope() = FunctionName() (x, y, z)
but you can rewrite an array in a Sub (or Function) like

Sort (myArray() as something)

sub Sort(MyArr() as say Integer)
' some sort routine
end sub

9
QB64 Discussion / Re: Recomendation of some basic libraries for QB
« on: February 03, 2022, 02:57:48 pm »
Hi bplus,

Coupla quesitons

1)  Does _PrintString(xpix, ypix), text$ return the cursor back to the original location, before calling it?  I didn't mention this in the original post, but edited it afterwards.

2)  Do these routines work in 4.5?  I like to go back & forth between 64 and 4.5, testing in each environment.  At least for now.

This is a really nice comprehensive page, thanks. - https://www.qb64sourcecode.com/Task7.html



10
QB64 Discussion / Recomendation of some basic libraries for QB
« on: February 03, 2022, 02:03:35 pm »
Hi,

There are a lot of legacy libraries around, but it's difficult to search through each one, and find out the kinds of functions I'm looking for.

I'm looking for simple functions like

GetCurrentLocation()  - returns an array with Current Column and Current Row position

PrintAt_RowY_ColumnX_WithColor(  Y, X, Color ) - Self-explanatory, but also saves the current cursor location and LOCATES it back after the call.

GetCurrentBackGroundColor()


, stuff like that, just for Text Mode Screen 0.

I know how to code all these things in principle, but was looking for a basic library that already covers this functionality robustly.


Also, I'd like to write up some Functional modules for QB.  I'm nearly certain it's not available yet, but would like to do

QBArray_Map( fn, SourceArray ) -> TargetArray
QBArray_Reduce( fn, SourceArray ) -> FinalResult

, at the least.  If there's already something like that, can you let me know, so as to avoid reinventing the wheel?


11
QB64 Discussion / Re: Illegal string-number conversion
« on: February 03, 2022, 10:57:52 am »
Got it.

Code: QB64: [Select]
  1. ' Modified from a routine by Steve Trace
  2. Function Mybarmenu$ (y, x, spacing, tc, bc, prompts$())
  3.  
  4.     Dim ChoiceSelected$
  5.  
  6.  
  7.     top = LBound(prompts$, 1)
  8.     bottom = UBound(prompts$, 1)
  9.     prompt = LBound(prompts$, 2)
  10.     description = UBound(prompts$, 2)
  11.     ReDim position(bottom)
  12.     okprompt$ = ""
  13.     Locate y, x, 0
  14.     Color tc, bc
  15.     For i = top To bottom
  16.         position(i) = Pos(y)
  17.         Print prompts$(i, prompt); Spc(spacing);
  18.         okprompt$ = okprompt$ + Chr$(Asc(prompts$(i, prompt)))
  19.     Next i
  20.     current = top
  21.     moveto = current
  22.     ChoiceSelected$ = ""
  23.     While ChoiceSelected$ = ""
  24.         Color bc, tc
  25.         Locate y, position(current)
  26.         Print prompts$(current, prompt);
  27.         Locate y + 1, x
  28.         Color tc, bc
  29.         Print prompts$(current, description);
  30.         While ch$ = ""
  31.             ch$ = InKey$
  32.         Wend
  33.         If Asc(ch$) = 0 Then
  34.             Call specialkey(ch$, moveto, top, bottom)
  35.         ElseIf ch$ = Chr$(13) Then
  36.             ChoiceSelected$ = Chr$(Asc(prompts$(current, prompt)))
  37.             ' ELSEIF INSTR(okprompt$, UCASE$(ch$)) > 0 THEN
  38.         ElseIf InStr(okprompt$, UCase$(ch$)) > 0 Then
  39.             ChoiceSelected$ = UCase$(ch$)
  40.         Else
  41.             Beep
  42.         End If
  43.         If moveto <> current Then
  44.             Locate y, position(current)
  45.             Print prompts$(current, prompt);
  46.             Locate y + 1, x
  47.             Print Space$(80 - x);
  48.             current = moveto
  49.         End If
  50.         ch$ = ""
  51.     Wend
  52.     Erase position
  53.     Mybarmenu = ChoiceSelected$
  54.  

12
QB64 Discussion / Re: The QB64 Bible (Work In Progress)
« on: February 03, 2022, 10:44:48 am »
Steve,

Will you leave a copy of this on your github, as it updates?


As you guys might know (if you don't, what the heck have you been doing -- hiding your head under a rock somewhere??), I've transitioned into a writer/novelist now that I've more or less officially retired here at the farm.  October to January still keeps me busy with farm life, but otherwise I've got the rest of the year free to indulge my hobbies however I want.

For ages, I've been promising, "Some day, I'm going to sit down and end up writing up some sort of overly complex and wordy manual for QB64 that everyone can laugh at and nobody will probably ever use!"

Well, I just so happen to be snowed in -- and have been snowed in for the last few weeks -- and my boredom and restlessness has now gotten to the point where I finally decided to sit down and start on this little project:  The QB64 Bible.

For now, all I've got is basically a write up about SCREEN 0 -- (and it's only about 14 pages long) -- but I hope it shows the style and format I'm shooting for here, and the information which I want to try and gather up into one easy to find and reference area.

Feel free to download it.  Study it.  Point out anything that seems unclear or imprecise, or that you just don't like, and offer any ideas of what you guys think should go into this little project.  I'm just starting on this, but if all works out, I can probably churn out a few hundred pages of nonsense by the end of the month (provided I stick with this project exclusively during that time), so at that point it might actually have enough information in it to become something that somebody, somewhere, might want to make use of sometime in the future.

Just remember:  This is a work in progress and is subject to any and all revisions, edits, changes, additions, and deletions -- at my whim and whimsey -- for the foreseeable future.

13
QB64 Discussion / Illegal string-number conversion
« on: February 03, 2022, 10:39:46 am »
Hi,

I'm modifying a barmenu routine, originally coded by Steve Trace.  Steve had written his barmenu as a sub, but I'm trying to convert it to a function.  The function will return the choice selected.

The problem is that the return statement

Code: QB64: [Select]
  1. MyBarMenu = ChoiceSelected

is generating an illegal string-number conversion error.


I don't know how to specify the return value of a function.  I tried 'As String' after the function name & parameters ; but that also generates an error.


This is the module.


Code: QB64: [Select]
  1. ' Modified from a routine by Steve Trace
  2. Function Mybarmenu (y, x, spacing, tc, bc, prompts$())
  3.  
  4.     Dim ChoiceSelected As String
  5.  
  6.  
  7.     top = LBound(prompts$, 1)
  8.     bottom = UBound(prompts$, 1)
  9.     prompt = LBound(prompts$, 2)
  10.     description = UBound(prompts$, 2)
  11.     ReDim position(bottom)
  12.     okprompt$ = ""
  13.     Locate y, x, 0
  14.     Color tc, bc
  15.     For i = top To bottom
  16.         position(i) = Pos(y)
  17.         Print prompts$(i, prompt); Spc(spacing);
  18.         okprompt$ = okprompt$ + Chr$(Asc(prompts$(i, prompt)))
  19.     Next i
  20.     current = top
  21.     moveto = current
  22.     ChoiceSelected = ""
  23.     While ChoiceSelected = ""
  24.         Color bc, tc
  25.         Locate y, position(current)
  26.         Print prompts$(current, prompt);
  27.         Locate y + 1, x
  28.         Color tc, bc
  29.         Print prompts$(current, description);
  30.         While ch$ = ""
  31.             ch$ = InKey$
  32.         Wend
  33.         If Asc(ch$) = 0 Then
  34.             Call specialkey(ch$, moveto, top, bottom)
  35.         ElseIf ch$ = Chr$(13) Then
  36.             ChoiceSelected = Chr$(Asc(prompts$(current, prompt)))
  37.             ' ELSEIF INSTR(okprompt$, UCASE$(ch$)) > 0 THEN
  38.         ElseIf InStr(okprompt$, UCase$(ch$)) > 0 Then
  39.             ChoiceSelected = UCase$(ch$)
  40.         Else
  41.             Beep
  42.         End If
  43.         If moveto <> current Then
  44.             Locate y, position(current)
  45.             Print prompts$(current, prompt);
  46.             Locate y + 1, x
  47.             Print Space$(80 - x);
  48.             current = moveto
  49.         End If
  50.         ch$ = ""
  51.     Wend
  52.     Erase position
  53.     MyBarMenu = ChoiceSelected
  54.  





14
QB64 Discussion / Re: Illegal string-number conversion on line 37
« on: January 31, 2022, 02:59:30 am »
Yes, absolutely.  I use it in VBScript all the time.  It didn't occur to me that QB had it as well.

15
QB64 Discussion / Re: Illegal string-number conversion on line 37
« on: January 30, 2022, 07:34:02 pm »
Yep I see it, thanks McNeil.

Variable name mismatch.

DIM MenuMessages...

MenuMessage(... = ....

Notice the missing S at the end of your variable name?

Pages: [1] 2