I was trying to make a program that compiles a piece of code written in a BASIC variation i'm making.
I tried to figure out the problem but I couldn't. I changed the "String.StartsWith()" to String == "something" and it worked, but I need to use StartsWith in this part.
private String ComprobarCmd(String txt)
{
String texto = txt;
if (texto.StartsWith("CLS")) return "1";
if (texto.StartsWith("SETCURSOR")) return "2";
if (texto.StartsWith("PRINT")) return "3";
if (texto.StartsWith("END")) return "1000";
return "F";
}
I expected it to return a string, but it just gave me this error (it's in Spanish):
************** Texto de la excepción **************
System.NullReferenceException: Referencia a objeto no establecida como instancia de un objeto.
en JBasic_Compiler.Form1.ComprobarCmd(String txt) en D:\Programas\Proyectos VB\JBasic Compiler\JBasic Compiler\JBasic Compiler\Form1.cs:línea 67
en JBasic_Compiler.Form1.Compilar(String path) en D:\Programas\Proyectos VB\JBasic Compiler\JBasic Compiler\JBasic Compiler\Form1.cs:línea 54
en JBasic_Compiler.Form1.Form1_Load(Object sender, EventArgs e) en D:\Programas\Proyectos VB\JBasic Compiler\JBasic Compiler\JBasic Compiler\Form1.cs:línea 28
en System.Windows.Forms.Form.OnLoad(EventArgs e)
en System.Windows.Forms.Form.OnCreateControl()
en System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
en System.Windows.Forms.Control.CreateControl()
en System.Windows.Forms.Control.WmShowWindow(Message& m)
en System.Windows.Forms.Control.WndProc(Message& m)
en System.Windows.Forms.ScrollableControl.WndProc(Message& m)
en System.Windows.Forms.Form.WmShowWindow(Message& m)
en System.Windows.Forms.Form.WndProc(Message& m)
en System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
en System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
en System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)