Trying to use the Hardware library

Dave5910715

Member
Licensed User
Hi
My attempt using the Hardware library failed so I've taken the example out of the help manual, added Form1 and the DLL's (Hardware.dll for device and HardwareDesktop.dll for PC) but trying to run I still get the same error:

An error occured on sub main.app_start.

Line number:10

Hardware1.New1

Error description:
Object reference not set to an instance of an object.

I'm using the Desktop Version 6.9 with .Net 2.0.50727.3603:sign0085:
 

sitajony

Active Member
Licensed User
Weird...
Can we get all your code?
Did you try to close and run again Basic4PPC?
When you type Hardware1. there're function names who are show?
 

corwin42

Expert
Licensed User
Longtime User
An error occured on sub main.app_start.

Line number:10

Hardware1.New1

Error description:
Object reference not set to an instance of an object.

Did you create the Hardware1 object first? You have to create the object first in the IDE with the Tools->Add object menu.

If you can't solve it please post your whole sbp file here.
 

Dave5910715

Member
Licensed User
You may have guessed I'm new to Basic4pp, the help manual used Hardware1.New1 but the syntax did not change so I've tried Hardware.New1 as below. I'm now getting the colour change and options following the '.' but noticed the Objects (hardware) are not showing up in the right hand side box.

Have closed down & restarted and cut code down to below and still getting same error ?

and yes added the Hardware.dll & HardwareDesktop.dll in tools Components

'Add a Hardware object named Hardware1
Sub Globals

End Sub


Sub App_Start
Form1.show
Hardware.New1
Msgbox("Device ID: " & Hardware.GetDeviceID)
End Sub


Sub Timer1_Tick
Hardware.KeepAlive 'Resets the system idle timers
End Sub
 
Last edited:

mjcoon

Well-Known Member
Licensed User
... but noticed the Objects (hardware) are not showing up in the right hand side box.

As corwin42 pointed out just minutes before you posted, you have to name the object in the IDE as well as doing the Hardware1.New1. The former is a compile-time operation and will cause the object name to appear in the right-hand pane. You could think of it as a declaration that associates the name with the object type in the library. The Hardware1.New1 is a run-time process and could happen zero or more times in any run of the program (depending upon the design).

HTH, Mike.
 

Dave5910715

Member
Licensed User
Many thanks - penny slowly dropping, I'd assumed once you add the component it created an instance

Just a note for any other beginners after adding the components you also need to create the object via Tools > Add Object and select Hardware (or what ever component your using) and give it a name ie Hardware1
 
Last edited:

sitajony

Active Member
Licensed User
In programing for any languages it's the same thing C C++ VB .NET and on B4PPC... Else we can't use a library function if we don't know with what we use... (Sorry if you don't understand lol)
 

Frogger

Member
Licensed User
Longtime User

Don't worry, the exact same thing confused me too. Basic programming was much easier on my 8-bit Amstrad CPC back in the 80s
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…