Author Topic: Illegal string-number conversion on line 37  (Read 2982 times)

0 Members and 1 Guest are viewing this topic.

Offline QB64Curious

  • Newbie
  • Posts: 22
    • View Profile
Illegal string-number conversion on line 37
« on: January 30, 2022, 07:12:05 pm »
Hi,

I'm in the process of converting a sort of grid text-mode menu system, to one with a single row that will scroll & display more items than the width of the screen will fit.

The menu array is working fine.  This is MenuItem().

But the array for the messages associated with each menu item, is a problem.  This array is called MenuMessage(), and is defined the same way as MenuItem().

I'm running this in the QB64 ide right now, but will also test it in the 4.5 ide later.

The error is

     Illegal string-number conversion on line 37

The line 37 in question is

Code: QB64: [Select]
  1. MenuMessage(1) = "Message for Choice 1"

Is it possible that I'm running up against the limit of the name of an array?  'MenuMessage' is 11 characters.

The full code is here


Code: QB64: [Select]
  1. 'horzmenu.bas, originally menucol.bas by Ray Thomas      January 2002
  2.  
  3. Const BLUE = 1
  4. Const WHITE = 7
  5. Const MENUROW = 1
  6. Const MAXIMUMITEMLENGTH = 10
  7.  
  8. Dim MenuItem(12) As String * 25 'Define the menu item array
  9. Dim MenuMessages(12) As String * 50 'Define the menu message array
  10. Dim ChooseItem As Integer 'Currently chosen menu item
  11. Dim XMenuPosn As Integer 'Controls the menu item X positions
  12. Dim YMenuPosn As Integer 'Controls the menu item Y positions
  13. Dim CurrentYMenuPosition As Integer
  14. Dim CurrentXMenuPosition As Integer
  15.  
  16. Dim Count As Integer 'Array counter
  17. Dim NumberOfColumns As Integer 'Number of menu items per line
  18. Dim Temp As String 'Used to centre text in the space
  19. Dim FullItemNameRow As Integer 'Row where the full name of the item is displayed
  20. Dim MessageRow 'Row where a message corresponding to the Menu Item is displayed
  21.  
  22. MenuItem(1) = "Choice 1"
  23. MenuItem(2) = "Choice 2"
  24. MenuItem(3) = "Choice 3"
  25. MenuItem(4) = "Choice 4"
  26. MenuItem(5) = "Longer Choice 5"
  27. MenuItem(6) = "Choice 6"
  28. MenuItem(7) = "Choice 7"
  29. MenuItem(8) = "Choice 8"
  30. MenuItem(9) = "Choice 9"
  31. MenuItem(10) = "Another Longer Choice 10"
  32. MenuItem(11) = "Choice 11"
  33. MenuItem(12) = "Choice 12"
  34.  
  35. MenuMessage(1) = "Message for Choice 1"
  36. MenuMessage(2) = "Message for Choice 2"
  37. MenuMessage(3) = "Message for Choice 3"
  38. MenuMessage(4) = "Message for Choice 4"
  39. MenuMessage(5) = "Message for Longer Choice 5"
  40. MenuMessage(6) = "Message for Choice 6"
  41. MenuMessage(7) = "Message for Choice 7"
  42. MenuMessage(8) = "Message for Choice 8"
  43. MenuMessage(9) = "Message for Choice 9"
  44. MenuMessage(10) = "Message for Another Longer Choice 10"
  45. MenuMessage(11) = "Message for Choice 11"
  46. MenuMessage(12) = "Message for Choice 12"
  47.  
  48. ChooseItem = 1 'Starting point of highlighted menu item
  49. XMenuPosn = 1 'X starting point of menu
  50. YMenuPosn = 1 'Y starting point of menu
  51. NumberOfColumns = 12 'Number of columns in the menu
  52. FullItemNameRow = 4
  53. MessageRow = 5
  54.  
  55.  
  56.  
  57. Color WHITE, BLUE
  58. GoSub DrawMenu
  59.  
  60. '*** get cursor key movements and redraw menu ***
  61.     Cmmnd$ = InKey$
  62.  
  63.     'Check for Esc key
  64.     If Cmmnd$ = Chr$(27) Then
  65.         End
  66.     End If
  67.     If Len(Cmmnd$) = 2 Then Cmmnd$ = Right$(Cmmnd$, 1)
  68.  
  69.     If Cmmnd$ = "8" Or Cmmnd$ = Chr$(72) Then GoSub MoveUp
  70.     If Cmmnd$ = "2" Or Cmmnd$ = Chr$(80) Then GoSub MoveDown
  71.     If Cmmnd$ = "4" Or Cmmnd$ = Chr$(75) Then GoSub Moveleft
  72.     If Cmmnd$ = "6" Or Cmmnd$ = Chr$(77) Then GoSub MoveRight
  73.     If Cmmnd$ = "9" Or Cmmnd$ = Chr$(73) Then GoSub TopCol
  74.     If Cmmnd$ = "3" Or Cmmnd$ = Chr$(81) Then GoSub BottomCol
  75.     If Cmmnd$ = "7" Or Cmmnd$ = Chr$(71) Then ChooseItem = 1
  76.     If Cmmnd$ = "1" Or Cmmnd$ = Chr$(79) Then ChooseItem = UBound(MenuItem$)
  77.  
  78.  
  79.     GoSub DrawMenu
  80.  
  81. Loop Until Cmmnd$ = Chr$(13)
  82.  
  83. Color 7, 1
  84. Print "Item chosen = "; RTrim$(MenuItem(ChooseItem))
  85.  
  86.  
  87. DrawMenu:
  88. 'Draw the menu
  89. Locate YMenuPosn, XMenuPosn
  90. For Count = 1 To UBound(MenuItem$)
  91.     If Count = ChooseItem Then Color BLUE, WHITE Else Color WHITE, BLUE
  92.     Print RTrim$(Mid$(MenuItem$(Count), 1, MAXIMUMITEMLENGTH)) + " ";
  93.  
  94.  
  95.  
  96.  
  97.  
  98.     If Count = ChooseItem Then
  99.         CurrentYMenuPosition = CsrLin
  100.         CurrentXMenuPosition = Pos(0)
  101.  
  102.         Locate MessageRow, 1
  103.         Print Space$(50)
  104.         Locate MessageRow, 1
  105.         Print RTrim$(MenuMessages(Count));
  106.         Locate FullItemNameRow, 1
  107.         Print Space$(25)
  108.         Locate FullItemNameRow, 1
  109.         Print RTrim$(MenuItem$(Count))
  110.         Locate CurrentYMenuPosition, CurrentXMenuPosition
  111.     End If
  112.  
  113.     '/*
  114.     ' Locate FullItemNameRow, 1
  115.     ' Print Space$(50)
  116.     ' Locate FullItemNameRow, 1
  117.     ' Print MenuItem$(Count)
  118.     ' Locate CurrentYMenuPosition, CurrentXMenuPosition
  119.     '*/
  120.  
  121.     If Count Mod NumberOfColumns = 0 Then
  122.         Print
  123.         Locate CsrLin, XMenuPosn
  124.     End If
  125. Next Count
  126.  
  127.  
  128.  
  129.  
  130. MoveUp:
  131. If ChooseItem <= NumberOfColumns Then
  132.     ChooseItem = UBound(MenuItem$) - (MenuItem Mod NumberOfColumns)
  133.     ChooseItem = ChooseItem - NumberOfColumns
  134.  
  135. MoveDown:
  136. If ChooseItem > UBound(MenuItem$) - MenuLine Then
  137.     ChooseItem = ChooseItem Mod MenuLine
  138.     ChooseItem = ChooseItem + MenuLine
  139. If ChooseItem = 0 Then ChooseItem = MenuLine
  140.  
  141. Moveleft:
  142. ChooseItem = ChooseItem - 1
  143. If ChooseItem = 0 Then ChooseItem = UBound(MenuItem$)
  144.  
  145. MoveRight:
  146. ChooseItem = ChooseItem + 1
  147. If ChooseItem = UBound(MenuItem$) + 1 Then ChooseItem = 1
  148.  
  149. TopCol:
  150. ChooseItem = ChooseItem Mod MenuLine
  151. If ChooseItem = 0 Then ChooseItem = MenuLine
  152.  
  153. BottomCol:
  154. ChooseItem = UBound(MenuItem$) - (MenuLine - (ChooseItem Mod MenuLine))
  155. If MenuLine - (ChooseItem Mod MenuLine) = MenuLine Then ChooseItem = UBound(MenuItem$)
  156.  

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Illegal string-number conversion on line 37
« Reply #1 on: January 30, 2022, 07:25:00 pm »
Variable name mismatch.

DIM MenuMessages...

MenuMessage(... = ....

Notice the missing S at the end of your variable name?
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline QB64Curious

  • Newbie
  • Posts: 22
    • View Profile
Re: Illegal string-number conversion on line 37
« Reply #2 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?

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Illegal string-number conversion on line 37
« Reply #3 on: January 30, 2022, 07:34:29 pm »
Looks like a job for Option _Explicit, that way if you have a typo it will show up as not dimensioned yet.

Offline QB64Curious

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