C
C#16mo ago
newreal119

❔ I need help urgent

I have a very annoying error yes I'm not so good at c# but I'm doing challenges for myself so it's giving me an error I want you to help me I'm breaking my head since yesterday I went to chat gpt bard but none of them solved my problem. this is the error: https://pastebin.com/jdUK1BWp
Pastebin
Error - Pastebin.com
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
73 Replies
SinFluxx
SinFluxx16mo ago
Where's the code that the error's referencing?
newreal119
newreal119OP16mo ago
SinFluxx
SinFluxx16mo ago
so something on that line 46 noway.textorealdarich.... you have not instantiated, what is noway?
newreal119
newreal119OP16mo ago
is variable public she it is located in another form
newreal119
newreal119OP16mo ago
bro.
newreal119
newreal119OP16mo ago
@sinfluxx sorry but the mistakes it is portuguese you can translate?
SinFluxx
SinFluxx16mo ago
I can roughly translate, I'm a bit confused though as you have NameOfDiv, which is a Form? Then you're creating a new Form2 within NameOfDiv, and calling that noway, but then you're also creating the variable noway again as a string on line 26
newreal119
newreal119OP16mo ago
Then you're creating a new Form2 within NameOfDiv, and calling that noway, but then you're also creating the variable noway again as a string on line 26 No
newreal119
newreal119OP16mo ago
this is another form already existing in it is the public variable I already instantiated it to get its variable But I don't know what's giving an error, it says it's giving an error on line 46 too
SinFluxx
SinFluxx16mo ago
Omnissiah
Omnissiah16mo ago
some simple debugging could give the solution instead of guessing put a breakpoint there please
newreal119
newreal119OP16mo ago
no way it must have been my headache because I was breaking my head it's very confusing
SinFluxx
SinFluxx16mo ago
do what @chaos_solo said and put a breakpoint there, so you can see what the variables are set to
newreal119
newreal119OP16mo ago
how do you do this thing I already found it
newreal119
newreal119OP16mo ago
newreal119
newreal119OP16mo ago
translated start debugging
SinFluxx
SinFluxx16mo ago
click on the left of the line, so that a red circle appears, like below then run your program and it will stop (break) when it gets to that point in the code
newreal119
newreal119OP16mo ago
Ok in which variable?
SinFluxx
SinFluxx16mo ago
on the line you're getting the exception
newreal119
newreal119OP16mo ago
Ok bro I just remembered that I left the program as administrator because of file creation @sinfluxx
SinFluxx
SinFluxx16mo ago
I don't think that will be relevant to the error you're getting
newreal119
newreal119OP16mo ago
newreal119
newreal119OP16mo ago
i know I'm going to deactivate the business so I can see what the error is
newreal119
newreal119OP16mo ago
newreal119
newreal119OP16mo ago
what is? @sinfluxx
SinFluxx
SinFluxx16mo ago
you see at the bottom, noway.textorealdarich is null?
newreal119
newreal119OP16mo ago
yes
SinFluxx
SinFluxx16mo ago
so because you're trying to find .IndexOf("<body>") within it, but it's null, it won't work
newreal119
newreal119OP16mo ago
bro I will explain my program it is a program to make websites so easy by button
newreal119
newreal119OP16mo ago
newreal119
newreal119OP16mo ago
newreal119
newreal119OP16mo ago
newreal119
newreal119OP16mo ago
]
newreal119
newreal119OP16mo ago
newreal119
newreal119OP16mo ago
newreal119
newreal119OP16mo ago
newreal119
newreal119OP16mo ago
SinFluxx
SinFluxx16mo ago
I'm struggling to follow everything completely, but it sounds to me like you're trying to access one Form from a different Form, and running into problems with that, also because you're declaring the Form again
newreal119
newreal119OP16mo ago
SinFluxx
SinFluxx16mo ago
I would have thought you should return what you need from the NameOfDiv form back to Form2 and let Form2 update itself but I've never really used winforms
newreal119
newreal119OP16mo ago
I'm not declaring Ok I just instantiated it to find the <body> </body> bro
SinFluxx
SinFluxx16mo ago
that won't work the way you think it works that's creating a whole new/unrelated instance of Form2
newreal119
newreal119OP16mo ago
that's not why I need help either too not but i need help I need help with this and with mistakes we learn but is this add div a will add a division in the body and its name that will remain as a comment but it's giving error
SinFluxx
SinFluxx16mo ago
right, because noway.textorealdarich is not set to anything, as we saw above
newreal119
newreal119OP16mo ago
how not?
SinFluxx
SinFluxx16mo ago
you've obviously not declared it properly somewhere, it's hard to say because we're just seeing little bits and pieces of your code
newreal119
newreal119OP16mo ago
I'll show you all the code ok?
newreal119
newreal119OP16mo ago
Pastebin
using System;using System.Collections.Generic;using System.Componen...
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
newreal119
newreal119OP16mo ago
this form 2 @sinfluxx which you wants
SinFluxx
SinFluxx16mo ago
then where do you launch NameOfDiv from?
newreal119
newreal119OP16mo ago
Pastebin
using System;using System.Collections.Generic;using System.Componen...
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
newreal119
newreal119OP16mo ago
this is codeblock cs line 95
SinFluxx
SinFluxx16mo ago
and then your full NameOfDiv.cs?
Omnissiah
Omnissiah16mo ago
why do this
string[] linhas = File.ReadAllLines(Form1.nomedorarquivo);
string conteudo2 = string.Join(Environment.NewLine, linhas);
richTextBox1.Text = conteudo2;
string[] linhas = File.ReadAllLines(Form1.nomedorarquivo);
string conteudo2 = string.Join(Environment.NewLine, linhas);
richTextBox1.Text = conteudo2;
when you could simply use ReadAllText
newreal119
newreal119OP16mo ago
Yes
SinFluxx
SinFluxx16mo ago
I mean let us see it
newreal119
newreal119OP16mo ago
to read the content inside the html file to richtextbox1
Omnissiah
Omnissiah16mo ago
you can use ReadAllText avoiding ReadAllLines->string.join that's what im saying
newreal119
newreal119OP16mo ago
Ok https://pastebin.com/b5zjSeWf this is nameofdiv
Pastebin
using System;using System.Collections.Generic;using System.Componen...
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
newreal119
newreal119OP16mo ago
bro I got confused calm down there where this is? which line?
Omnissiah
Omnissiah16mo ago
i closed it i don't know
SinFluxx
SinFluxx16mo ago
line 40 in Form2
newreal119
newreal119OP16mo ago
if (File.Exists(Form1.nomedorarquivo)) { codigo = richTextBox1.Text; string[] linhas = File.ReadAllLines(Form1.nomedorarquivo); string conteudo2 = string.Join(Environment.NewLine, linhas); richTextBox1.Text = conteudo2; textorealdarich = richTextBox1.Text; } this
SinFluxx
SinFluxx16mo ago
yes
SinFluxx
SinFluxx16mo ago
the original problem is still because of this as far as I can tell:
newreal119
newreal119OP16mo ago
so it's for reading the file even explaining I didn't change the form of menu 1 I just put a panel and public variables etc then I put it like this and it's functional so what can i do?
Omnissiah
Omnissiah16mo ago
i was thinking of extracting data (settings) from the forms classes, but i'm not following that much also, there is no full code to review
newreal119
newreal119OP16mo ago
what you need?
Omnissiah
Omnissiah16mo ago
more time, and probably the whole project anyway yes i confirm i think you need a separate part of your project that deals with reading and saving data (also called isolation) so that it can be used by forms
SinFluxx
SinFluxx16mo ago
like I said I've never really dealt with winforms so I'm probably not best to advise on how things are done there but it does sound like you need to look into how to pass / return data between different forms
newreal119
newreal119OP16mo ago
no problem but thank you for the help 🤝
Omnissiah
Omnissiah16mo ago
winforms are very basic, instance just holds the data so the raw method to do it is creating properties that the form fills and then the parent read those properties when it gets the control back a modern way to do it would be using events
Accord
Accord16mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server