Author Topic: Illegal string-number conversion  (Read 2539 times)

0 Members and 1 Guest are viewing this topic.

Offline QB64Curious

  • Newbie
  • Posts: 22
    • View Profile
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.  





Offline QB64Curious

  • Newbie
  • Posts: 22
    • View Profile
Re: Illegal string-number conversion
« Reply #1 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.