We would like to build a community for Small Basic programmers of any age who like to code. Everyone from total beginner to guru is welcome. Click here to register and share your programming journey!


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Small Basic Program Conversion to C#
#1
What can a person do when they have a small basic program that they want to convert to c# and the conversion comes up with a bunch of error messages that you don't understand that originates from visual studio. The program runs fine in small basic. The problems occur after conversion. This is an issue with visual studio. It generally gives potential fixes that never work and the explanation of what is wrong is way beyond my comprehension.

Most of the time I end up just leaving the running program in small basic and give up on converting to c#. I know that is not the ideal way of doing it, but what else can a person do?

JR
Reply
#2
I guess they can share a SB program here that fails to convert, and ask for help.

Or they can google the error messages in VS and see what they can learn.

It's a process of learning we all take, the key is to gradually increase understanding, not just get the fix, so writing small programs directly in C# is a good idea.  Those converted from SB are not optimal C#.

I'm currently learning Kotlin and Filament for 3D android development and node.js with Typescript for browser development, and it's tricky with mixed quality web resources.
[-] The following 1 user Likes litdev's post:
  • jrmrhrb00
Reply
#3
LitDev,

I'm trying to do 1 sb program. If I use ILSpy I get 1 set of errors from visual studio. If I use DnSpy I get a different set of errors from visual studio. None of the possible fixes from visual studio work. What visual studio says is wrong doesn't make sense to me for either way it was decompiled. At least in small basic you normally understand what the problem is. Not so in visual studio!

JR
Reply
#4
Hi litdev
I was also learning new skills I can't get vs so I got vscode in which I could try amazing languages.
After knowing that c# would only work on pc with .net I started looking for cross platform.net framework.
Came across mono(current dead),.net maui which could be used on my .net 8 but it's work load is huge size,same problem of huge workload for other than .net like Flutter(Dart),React(JS).
Now I will try to learn a new good cross platform language like c,cpp,rust.
Any good advice please
ZS
Reply
#5
@JR, 

If you publish the SB program code I will have a look, or even zip up the VS project you have, but without these any advice will be very generic.  Error messages can be confusing, but once you understand them they usually make sense - googling is your friend here.  I suggest trying the Advanced->Decompile option in SB-Prime as well, it does a couple other bits to the project setup.

@ZS,

Anything you learn will be useful, but probably the most generic cross-platform would be C++ (toughest) or maybe Python (easier and loads of libraries, especially for data science type stuff), but it really depends what you want it to do, which existing libraries you want to use etc.  If you want Windows Desktop then I would go SharpDevelop C#.  Maui .Net 8 is very heavy and not so easy as C#, its C++ and the GUI designer is poor, but it is cross platform, probably only for larger proffesional type projects that want to run on Windows and Linux.  Android or IOS have their own languages, web frontend (javascript), backend (php) are different again.
Reply
#6
LitDev,

Here's the program: WBVB625.000

Here's the error I get with visual studio:

Cannot implicitly convert type 'Microsoft.SmallBasic.Library.Primitive' to 'Microsoft.SmallBasic.Library.SmallBasicCallback'

This means nothing to me! other than it's trying to convert a primitive into something else. Gives me no clue as to what to do. The fix suggestions don't work.

JR
Reply
#7
Hi JR, 

Tricky, you are right.  We can see that it occurs on 5 lines where events are set.  SmallBasicCallback is a delegate to a function (basically a variable that is actually a function).  m_onmenu is a variable (Primitive) and onmenu is the function we actually want.  Why it has called it m_onmenu is odd, but you can see in your original SB code you have used the same name OnMenu for the event subroutine AND a variable.

Code:
'Events Enabled
LDControls.MenuClicked = OnMenu
LDShapes.ShapeEvent=OnShapeEvent
GraphicsWindow.KeyDown=OnKeyDown
Controls.ButtonClicked=OnButtonClicked
LDShapes.SetShapeEvent(tb[0])
Controls.Texttyped=OnTextTyped
While "True"
  If OnMenu = "True" Then
...
Sub OnMenu 'Setup Menu
  OnMenu="True"
EndSub

The fix is probably use separate variable for variable and subroutine name in SB, or in the C# change to use the delegate function name (without the m_).
Code:
        LDControls.MenuClicked += _SmallBasicProgram.onmenu;
        LDShapes.ShapeEvent += _SmallBasicProgram.onshapeevent;
        GraphicsWindow.KeyDown += _SmallBasicProgram.onkeydown;
        Controls.ButtonClicked += _SmallBasicProgram.onbuttonclicked;
        LDShapes.SetShapeEvent(Primitive.GetArrayValue(tb, 0.0));
        Controls.TextTyped += _SmallBasicProgram.ontexttyped;

So, it does make sense!

If I didn't spot this, my next step would be to test a very simple SB event program and see what it looked like decompiled:

Code:
GraphicsWindow.MouseDown = OnMouseDown

Sub OnMouseDown
EndSub
[-] The following 1 user Likes litdev's post:
  • jrmrhrb00
Reply
#8
LitDev,

Got it!

Thanks for the help! I still think Visual Studio's verbiage is lacking clarity.

JR
Reply
#9
So, what is the big deal about converting a program to c# or for that matter visual basic. It will probably run faster and for the joy of learning another programming language. If you think about it though, you have a programming language that is easy to use and has wonderful extensions. What else do you need?

LitDev has created the LitDev extension and Prime. These features have actually propelled Small Basic into being a featured programming language. And even with all of that it is still easy to use. Thanks to LitDev for all of his wonderful work and for supporting his web site.

JR
[-] The following 1 user Likes jrmrhrb00's post:
  • AbsoluteBeginner
Reply
#10
(12-11-2024, 01:07 PM)jrmrhrb00 Wrote: ... If you think about it though, you have a programming language that is easy to use and has wonderful extensions. What else do you need?

LitDev has created the LitDev extension and Prime. These features have actually propelled Small Basic into being a featured programming language. And even with all of that it is still easy to use. Thanks to LitDev for all of his wonderful work and for supporting his web site.

JR
(translated by Google translator)

That's exactly it !  Smile
People who want to create cool programs have cool programming languages. What did people have who needed a simple tool for entertainment and solving everyday problems?

After all, there are many more such people. But they didn’t have their own simple and powerful enough programming language.
Now they have such a programming language. LitDev is the Prometheus who brought light to the world of computers for such people.  Rolleyes
[-] The following 1 user Likes AbsoluteBeginner's post:
  • jrmrhrb00
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)