Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Sub not Reconizing Dim as String
#11
Excuse me for using BI and BM file names but there are TWO KINDS of include files and each needs to go in the right place in the main module.
So for communication convention we say the .BI file for the include file that goes at beginning of main module to hold all constants, UDT and Shared variables used in the 2nd type of include file the .BM that goes at the end of the main module and contains only Subs and Functions.

Tell me something, does a Dim Shared in Main Mod reach into an Included .BM file the one with the sub and function routines normally put at the end of Main mod and update Variable types as commanded in the main module?

I think not. 

I think in the include file, if you want a shared varaible to act as string, you have to have an Include .bi file with that instruction added and to include that .bi file in main module at the beginning of it.
  724  855  599  923  575  468  400  206  147  564  878  823  652  556 bxor cross forever
Reply
#12


(10-05-2025, 01:40 PM)pmackay Wrote:


This is the mess im making with the code.
Reply
#13
@pmackay do you understand what I just posted in reply #11?

You were posting your own thing so I think you missed it.

Do you understand there are two types of Include files now with QB64 unlike QB days of yore when there was only one .BI file to include?
  724  855  599  923  575  468  400  206  147  564  878  823  652  556 bxor cross forever
Reply
#14
OK here it is in 3 quickie code demos:

1 Normal stuff with out any includes.
Code: (Select All)
_Title "BI and BM demo 1" 'bplus 2025-10-05

' Demo 1 start with simple example of code that works fine with no BI or BM

Dim Shared MyString As String

MyString = "I am Marks current string."

MyStringStatus
MyString = "I am eager to help pmackay understand 2 types of include files.."
MyStringStatus
End

Sub MyStringStatus
    Print Mid$(MyString, 5)
End Sub

   



Demo 2 the red-line error because the included Sub has no idea MyString is supposed to be a string even though we say that first thing in main module.

Here is the new included MyStringStat.BM 'BMs go below all subs and functions of Main ususally
Code: (Select All)
Sub MyStringStatus
    Shared MyString As String
    Print Mid$(MyString, 5)
End Sub


Code: (Select All)
_Title "BI and BM demo 2" 'bplus 2025-10-05

' Demo 1 start with simple example of code that works fine with no BI or BM
' Demo 2 now put the sub MyStringStatus in a lib to include
'        we get red line error calling the sub because the sub doesn't know MyString is a String!!!!


' !!!!!!!!!!!!!   This replicates pmackay problem !!!!!!!!!!!!!!!!!!!!!!!!!!!

Dim Shared MyString As String

MyString = "I am Marks current string."
MyStringStatus
MyString = "I am eager to help pmackay understand 2 types of include files.."
MyStringStatus
End

$include: 'MyStringStat.BM'


Does that RED-LINE look familiar??? !!!
   


And here it is fixed by adding another Include file to cover Dim Shared FOR THE INCLUDED stuff in .BM file,  the one that only contains subs and functions.

MyStringStat.BI
Code: (Select All)
Dim Shared MyString As String

And now in Demo 3 we see everything working with include files as they did without include files in Demo 1
Code: (Select All)
_Title "BI and BM demo 3" 'bplus 2025-10-05

' Demo 1 start with simple example of code that works fine with no BI or BM
' Demo 2 now put the sub MyStringStatus in a lib to include
'        we get red line error calling the sub because the sub doesn't know MyString is a String!!!!

' Demo 3 NOW put the first line
'    Dim Shared MyString As String
' into and include file


' !!!!!!!!!!!!!!!!!!!! This Solves pmackay problem !!!!!!!!!!!!!!!!!!
'VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV

'$Include: 'MyStringStat.BI'

'MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM

MyString = "I am Marks current string."

MyStringStatus
MyString = "I am eager to help pmackay understand 2 types of include files.."
MyStringStatus
End

'$Include: 'MyStringStat.BM'

   


Oh and notice putting that Shared statement in an include file and including it first in main module eliminated the need to declare it again in the main module for main module variables of that name.
  724  855  599  923  575  468  400  206  147  564  878  823  652  556 bxor cross forever
Reply
#15
Just chiming in to say shared variables should be avoided as much as possible to prevent headaches.
The noticing will continue
Reply
#16
thank you b+  ..... now i get it....
Reply
#17
ah good, thanks for letting me know.
  724  855  599  923  575  468  400  206  147  564  878  823  652  556 bxor cross forever
Reply
#18
PHP Code:
https://www.facebook.com/share/p/1BBfjHfo1N/    this is a link to my code. I am in the process of cleaning it up. More code to add and change. 
Reply
#19
Code: (Select All)
' ===========================
' Permanent Variables
' ===========================

' --- Maze Constants ---
Const MAZE_W = 319
Const MAZE_H = 199
Const CELL_SIZE = 2
Const Hud0 = 10
Const Hud1 = 200
Const Hud2 = 360
Const Empty_Tile = 0
Const Wall_Tile = 1
Const Bug_Tile = 2
Const Pelletes_Tile = 3
Const Player_Tile = 4

' --- Random Seed ---
Randomize Timer + Rnd * Timer

' --- Score and Lives ---
Dim Shared Special As Integer
Dim Shared score As Long
Dim Shared lives As Integer
Dim Shared highscore As Long

Special = 3
score = 0
lives = 3
highscore = 0

' --- Maze Settings ---
Dim Shared maze(MAZE_W - 1, MAZE_H - 1) As Integer
Dim Shared startX As Integer
Dim Shared startY As Integer

' --- Player Settings ---
Dim Shared px As Integer
Dim Shared py As Integer
Dim Shared playerquit As Integer

' --- HUD / Fonts ---
Dim Shared defFont As Long
Dim Shared hudFont As Long

defFont = _Font(0)
hudFont = _LoadFont("Bangers-Regular.ttf", 32, "Bold")

' --- Game Mechanics ---
Dim Shared TotalBugs As Integer
Dim Shared x As Integer
Dim Shared y As Integer
Dim Shared attempts As Integer
Dim Shared rx As Integer
Dim Shared ry As Integer
Dim Shared paths As Integer
Dim Shared dir As Integer
Dim Shared length As Integer
Dim Shared lx As Integer
Dim Shared ly As Integer
top file set this way. much nicer. thanks b+
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Question Experimenting with a "StringList" type for simpler handling of string arrays/lists Heimdall 18 1,183 12-19-2025, 12:51 PM
Last Post: Heimdall
  Illegal string-number conversion Herve 7 748 07-07-2025, 09:53 AM
Last Post: a740g
  need help printing a scaled string in a custom font to a 32-bit image madscijr 9 1,135 07-03-2025, 04:48 PM
Last Post: SMcNeill
  DIM - AS - VARIABLE TYPE likely bug bartok 25 5,424 05-06-2024, 08:21 PM
Last Post: SMcNeill
  How to reorder string variable x factorial different ways? Circlotron 13 2,617 04-27-2024, 02:43 AM
Last Post: PhilOfPerth

Forum Jump:


Users browsing this thread: 1 Guest(s)