BlueTooth - Error (Undeclared variable 'Main')

sweddle

Member
Licensed User
Hello,

I am some what still new to B4A so to make my BlueTooth app I am taking a good bit from the BlueTooth chat Tutorial/file.

--- ERROR ---
Undeclared variable 'main' is used before it was assigned any value.
Line: 58
AStream.InitializePrefix(Main.serial1.InputStream, True, Main.serial1.OutputStream, "AStream")
--- End Error ---

I have looked/searched the app Tutorial for the word "Main" to see if it is being set or well something is being done with it and I do not find it anywhere else.

The Tutorials has 2 files/code Tabs "Main" and "ChatActivity"
I'm not sure if the tab name has something to do with the use of Main in the code line or not but no matter my app (with only one tab) has the same name "Main" so i'd think that to be fine.

Any ideas of where this "Main" is or how to set it? or???

Thanks for any help! :sign0104:
Shane
 

JonPM

Well-Known Member
Licensed User
Main is the name of the activity that holds the code. Perhaps you can upload your project here so someone can take a look (File> Export as zip)
 
Upvote 0

sweddle

Member
Licensed User
Thanks JonPM...

I striped down my app to the bear BlueTooth needs and have attached it...
I still get the error

----ERROR---
Error description: Undeclared variable 'main' is used before it was assigned any value.
Occurred on line: 106
----END-----

--- Code line 106 ---
AStream.InitializePrefix(Main.serial1.InputStream, True, Main.serial1.OutputStream, "AStream")
---END---

One thing that making me wonder is this... I notice now that the BlueTooth example/Tutorial has the code line in question in a separate Module that is only called/loaded once there is a BlueTooth connection... as to my same line of code (that errors) is in a "If-then-else" that is testing for a connection only and then attempts to load the line. No matter it errors on compile.

Anywho hope that helps but I have no idea as I'm not sure what that "Main" is as I cant find it in a search.

Thanks for the help!
Shane
 

Attachments

  • BlueTest.zip
    8.3 KB · Views: 108
Upvote 0

klaus

Expert
Licensed User
Simply remove the Main prefix.
Main is the name of the Main module.
I notice now that the BlueTooth example/Tutorial has the code line in question in a separate Module ...
That's the reason of the Main prefix.
When you call an object, a routine or a variable in another module you must add the module name, where these were defined, as a prefix.
In your case the object is defined and called in the same module so no prefix.

Best regards.
 
Upvote 0

sweddle

Member
Licensed User
Thanks Klaus, That did the job...

Here is what happened and what I did so others may learn if they have the problem:

I did give removing the "Main" a shot the other day before posting but I had left the line of code:
AStream.InitializePrefix(serial1.InputStream, True, serial1.OutputStream, "AStream")
To be executed upon the program starting, and it had a diffident error be it that there was no BlueTooth connection yet.

Once I placed the line of code in an "If-then-else" that tested for a BT connection = true then it worked fine (with Main removed as well)

--The working fix--
Sub Serial1_Connected (Success As Boolean)
ProgressDialogHide
Log("connected: " & Success)
If Success = False Then
Log(LastException.Message)
ToastMessageShow("Error connecting: " & LastException.Message, True)
Else
If AStream.IsInitialized = False Then
AStream.InitializePrefix(serial1.InputStream, True, serial1.OutputStream, "AStream")
End If
End If
End Sub
-- End working fix---

Thanks for all the help!!!
Shane
 
Upvote 0
Top